improve persistence

This commit is contained in:
Vendicated 2026-09-05 20:38:21 +02:00
parent f5671d73cd
commit 0c004e677e
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);
}