Skip to content

Commit

Permalink
uninstall.js: Complete rewrite of the uninstall code, adds Flatpak/Snap
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Arcitec authored and samfundev committed May 4, 2023
1 parent 4546c91 commit ddd5809
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/renderer/actions/uninstall.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {promises as fs} from "fs";
import originalFs from "original-fs";
import rimraf from "rimraf";
import path from "path";

import {progress} from "../stores/installation";
Expand All @@ -23,14 +21,14 @@ async function deleteShims(paths) {
const progressPerLoop = (DELETE_SHIM_PROGRESS - progress.value) / paths.length;
for (const discordPath of paths) {
const indexFile = path.join(discordPath, "index.js");
log("Removing " + indexFile);
log(`Removing injection scripts from: ${discordPath}.`);
try {
if (await exists(indexFile)) await fs.writeFile(indexFile, `module.exports = require("./core.asar");`);
log("✅ Deletion successful");
log("✅ Uninstalled successfully.");
progress.set(progress.value + progressPerLoop);
}
catch (err) {
log(`❌ Could not delete file ${indexFile}`);
log(`❌ Could not uninstall BetterDiscord from ${discordPath}.`);
log(`❌ ${err.message}`);
return err;
}
Expand All @@ -44,22 +42,26 @@ export default async function(config) {
if (!sane) return fail();


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


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


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


succeed();
};

0 comments on commit ddd5809

Please sign in to comment.