Skip to content

Commit 3b794c2

Browse files
Arcitecsamfundev
authored andcommitted
uninstall.js: Complete rewrite of the uninstall code, adds Flatpak/Snap
- Now uses clearer variable names and improved code formatting. - Improved the GUI's logging messages, with better explanations such as "restarting" instead of "killing", since non-technical users are the primary audience of BetterDiscord-Installer. - Added detailed comments for future maintainers/contributors.
1 parent 42705cd commit 3b794c2

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/renderer/actions/uninstall.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import {promises as fs} from "fs";
2-
import originalFs from "original-fs";
3-
import rimraf from "rimraf";
42
import path from "path";
53

64
import {progress} from "../stores/installation";
@@ -23,14 +21,14 @@ async function deleteShims(paths) {
2321
const progressPerLoop = (DELETE_SHIM_PROGRESS - progress.value) / paths.length;
2422
for (const discordPath of paths) {
2523
const indexFile = path.join(discordPath, "index.js");
26-
log("Removing " + indexFile);
24+
log(`Removing injection scripts from: ${discordPath}.`);
2725
try {
2826
if (await exists(indexFile)) await fs.writeFile(indexFile, `module.exports = require("./core.asar");`);
29-
log("✅ Deletion successful");
27+
log("✅ Uninstalled successfully.");
3028
progress.set(progress.value + progressPerLoop);
3129
}
3230
catch (err) {
33-
log(`❌ Could not delete file ${indexFile}`);
31+
log(`❌ Could not uninstall BetterDiscord from ${discordPath}.`);
3432
log(`❌ ${err.message}`);
3533
return err;
3634
}
@@ -44,22 +42,26 @@ export default async function(config) {
4442
if (!sane) return fail();
4543

4644

45+
// Installation channels (such as "stable", "canary") and their latest version's paths.
4746
const channels = Object.keys(config);
4847
const paths = Object.values(config);
4948

5049

51-
lognewline("Deleting shims...");
50+
// Remove BetterDiscord from each Discord version's loader-script.
51+
lognewline("Deleting BetterDiscord's loader scripts...");
5252
const deleteErr = await deleteShims(paths);
5353
if (deleteErr) return fail();
54-
log("✅ Shims deleted");
54+
log("✅ Loader scripts deleted.");
5555
progress.set(DELETE_SHIM_PROGRESS);
5656

5757

58-
lognewline("Killing Discord...");
58+
// Automatically restart Discord clients if they are running.
59+
lognewline("Restarting Discord...");
5960
const killErr = await kill(channels, (RESTART_DISCORD_PROGRESS - progress.value) / channels.length);
60-
if (killErr) showRestartNotice(); // No need to bail out
61-
else log("✅ Discord restarted");
61+
if (killErr) showRestartNotice(); // No need to bail out if we failed, just tell user to restart manually.
62+
else log("✅ Discord restarted.");
6263
progress.set(RESTART_DISCORD_PROGRESS);
6364

65+
6466
succeed();
6567
};

0 commit comments

Comments
 (0)