Improve persistence after Discord updates

Credit to doggybootsy

Co-Authored-By: Robert Delaney <71196819+doggybootsy@users.noreply.github.com>
This commit is contained in:
Vendicated 2026-09-05 20:38:21 +02:00
parent 0850f37fbb
commit c3b8254c2b
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18

View file

@ -17,6 +17,7 @@
*/
import { app } from "electron";
import EventEmitter from "events";
import { copyFileSync, existsSync, readdirSync, renameSync } from "original-fs";
import { basename, dirname, join } from "path";
@ -65,6 +66,18 @@ function patchLatest() {
}
}
// Try to patch latest on before-quit
// Discord's Win32 updater will call app.quit() on restart and open new version on will-quit
app.on("before-quit", patchLatest);
if (process.platform === "win32" || process.platform === "linux") {
EventEmitter.prototype.emit = new Proxy(EventEmitter.prototype.emit, {
apply(target, thisArg, argArray) {
if (argArray[0] === "host-updated") {
patchLatest();
}
return Reflect.apply(target, thisArg, argArray);
},
});
// Try to patch latest on before-quit
// Discord's Win32 updater will call app.quit() on restart and open new version on will-quit
app.on("before-quit", patchLatest);
}