diff --git a/src/main/persistAfterDiscordUpdates.ts b/src/main/persistAfterDiscordUpdates.ts index a0a34bf53..d66e6621a 100644 --- a/src/main/persistAfterDiscordUpdates.ts +++ b/src/main/persistAfterDiscordUpdates.ts @@ -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); +}