Remove old installs when detected

This commit is contained in:
Zack Rauen 2022-12-12 18:50:51 -05:00
parent d2594463c0
commit 06bdfe301b
2 changed files with 43 additions and 23 deletions

View File

@ -1,4 +1,6 @@
import {app} from "electron"; import {app} from "electron";
import path from "path";
import fs from "fs";
import ipc from "./modules/ipc"; import ipc from "./modules/ipc";
import BrowserWindow from "./modules/browserwindow"; import BrowserWindow from "./modules/browserwindow";
@ -20,6 +22,7 @@ if (!process.argv.includes("--vanilla")) {
} }
// Enable DevTools on Stable. // Enable DevTools on Stable.
try {
let fakeAppSettings; let fakeAppSettings;
Object.defineProperty(global, "appSettings", { Object.defineProperty(global, "appSettings", {
get() { get() {
@ -31,6 +34,17 @@ Object.defineProperty(global, "appSettings", {
fakeAppSettings = value; fakeAppSettings = value;
}, },
}); });
}
catch (_) {
// Detect old install and delete it
const appPath = app.getAppPath(); // Should point to app or app.asar
const oldInstall = path.resolve(appPath, "..", "app");
if (fs.existsSync(oldInstall)) {
fs.rmdirSync(oldInstall, {recursive: true});
app.quit();
app.relaunch();
}
}
// Needs to run this after Discord but before ready() // Needs to run this after Discord but before ready()
if (!process.argv.includes("--vanilla")) { if (!process.argv.includes("--vanilla")) {

View File

@ -128,6 +128,7 @@ const registerPreload = (event, path) => {
export default class IPCMain { export default class IPCMain {
static registerEvents() { static registerEvents() {
try {
ipc.on(IPCEvents.GET_PATH, getPath); ipc.on(IPCEvents.GET_PATH, getPath);
ipc.on(IPCEvents.RELAUNCH, relaunch); ipc.on(IPCEvents.RELAUNCH, relaunch);
ipc.on(IPCEvents.OPEN_DEVTOOLS, openDevTools); ipc.on(IPCEvents.OPEN_DEVTOOLS, openDevTools);
@ -141,4 +142,9 @@ export default class IPCMain {
ipc.handle(IPCEvents.OPEN_DIALOG, openDialog); ipc.handle(IPCEvents.OPEN_DIALOG, openDialog);
ipc.handle(IPCEvents.OPEN_WINDOW, createBrowserWindow); ipc.handle(IPCEvents.OPEN_WINDOW, createBrowserWindow);
} }
catch (err) {
// eslint-disable-next-line no-console
console.error(err);
}
}
} }