Skip to content

Commit a551bdf

Browse files
committed
improve messages; Kill Discord on Windows before patching
1 parent a5d7953 commit a551bdf

6 files changed

+25
-7
lines changed

find_discord_darwin.go

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func FindDiscords() []any {
5656
return discords
5757
}
5858

59+
func PreparePatch(di *DiscordInstall) {}
60+
5961
func FixOwnership(_ string) error {
6062
return nil
6163
}

find_discord_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func FindDiscords() []any {
129129
return discords
130130
}
131131

132-
// Not actually find_discord but no need to have this in the binary on Windows/Mac
132+
func PreparePatch(di *DiscordInstall) {}
133133

134134
// FixOwnership fixes file ownership on Linux
135135
func FixOwnership(p string) error {

find_discord_windows.go

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"errors"
1111
"fmt"
1212
"os"
13+
"os/exec"
1314
path "path/filepath"
1415
"strings"
1516
)
@@ -83,6 +84,13 @@ func FindDiscords() []any {
8384
return discords
8485
}
8586

87+
func PreparePatch(di *DiscordInstall) {
88+
name := windowsNames[di.branch]
89+
fmt.Println("Killing " + name + "...")
90+
91+
_ = exec.Command("powershell", "Stop-Process -Name "+name).Run()
92+
}
93+
8694
func FixOwnership(_ string) error {
8795
return nil
8896
}

gui.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func handleOpenAsarConfirmed() {
164164

165165
func handleErr(err error, action string) {
166166
if errors.Is(err, os.ErrPermission) {
167-
switch os := runtime.GOOS; os {
167+
switch runtime.GOOS {
168168
case "windows":
169169
err = errors.New("Permission denied. Make sure your Discord is fully closed (from the tray)!")
170170
case "darwin":
@@ -483,9 +483,9 @@ func renderInstaller() g.Widget {
483483
),
484484

485485
InfoModal("#downloaded", "Successfully Downloaded", "The Vencord files were successfully downloaded!"),
486-
InfoModal("#patched", "Successfully Patched", "You must now fully close Discord (from the tray).\n"+
487-
"Then, verify Vencord installed successfully by looking for its category in Discord Settings"),
488-
InfoModal("#unpatched", "Successfully Unpatched", "You must now fully close Discord (from the tray)"),
486+
InfoModal("#patched", "Successfully Patched", "If Discord is still open, fully close it first.\n"+
487+
"Then, start it and verify Vencord installed successfully by looking for its category in Discord Settings"),
488+
InfoModal("#unpatched", "Successfully Unpatched", "If Discord is still open, fully close it first. Then start it again, it should be back to stock!"),
489489
InfoModal("#scuffed-install", "Hold On!", "You have a broken Discord Install.\n"+
490490
"Sometimes Discord decides to install to the wrong location for some reason!\n"+
491491
"You need to fix this before patching, otherwise Vencord will likely not work.\n\n"+
@@ -497,8 +497,8 @@ func renderInstaller() g.Widget {
497497
"You're installing OpenAsar at your own risk. If you run into issues with OpenAsar,\n"+
498498
"no support will be provided, join the OpenAsar Server instead!\n\n"+
499499
"To install OpenAsar, press Accept and click 'Install OpenAsar' again.", true),
500-
InfoModal("#openasar-patched", "Successfully Installed OpenAsar", "You must now fully close Discord (from the tray)"),
501-
InfoModal("#openasar-unpatched", "Successfully Uninstalled OpenAsar", "You must now fully close Discord (from the tray)"),
500+
InfoModal("#openasar-patched", "Successfully Installed OpenAsar", "If Discord is still open, fully close it first. Then start it again and verify OpenAsar installed successfully!"),
501+
InfoModal("#openasar-unpatched", "Successfully Uninstalled OpenAsar", "If Discord is still open, fully close it first. Then start it again and it should be back to stock!"),
502502
InfoModal("#modal"+strconv.Itoa(modalId), modalTitle, modalMessage),
503503
}
504504

openasar.go

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ func (di *DiscordInstall) IsOpenAsar() (retBool bool) {
6565
}
6666

6767
func (di *DiscordInstall) InstallOpenAsar() error {
68+
PreparePatch(di)
69+
6870
dir := path.Join(di.appPath, "..")
6971
asarFile, err := FindAsarFile(dir)
7072
if err != nil {
@@ -97,6 +99,8 @@ func (di *DiscordInstall) InstallOpenAsar() error {
9799
}
98100

99101
func (di *DiscordInstall) UninstallOpenAsar() error {
102+
PreparePatch(di)
103+
100104
dir := path.Join(di.appPath, "..")
101105
originalAsar := path.Join(dir, "app.asar.original")
102106
if !ExistsFile(originalAsar) {

patcher.go

+4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ func (di *DiscordInstall) patch() error {
149149
}
150150
}
151151

152+
PreparePatch(di)
153+
152154
if di.isPatched {
153155
fmt.Println(di.path, "is already patched. Unpatching first...")
154156
if err := di.unpatch(); err != nil {
@@ -269,6 +271,8 @@ func unpatchRenames(dir string, isSystemElectron bool) (errOut error) {
269271
func (di *DiscordInstall) unpatch() error {
270272
fmt.Println("Unpatching " + di.path + "...")
271273

274+
PreparePatch(di)
275+
272276
if di.isSystemElectron {
273277
fmt.Println("Detected as System Electron Install")
274278
// See comment in Patch

0 commit comments

Comments
 (0)