From e21cb6e34aab0aacd3faf7efcfb4ffd2903297f8 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:47:25 +0200 Subject: [PATCH] Unsubscribe autoUpdater event handlers --- ts/updater/macos.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ts/updater/macos.ts b/ts/updater/macos.ts index 105b533966..f8118e471e 100644 --- a/ts/updater/macos.ts +++ b/ts/updater/macos.ts @@ -49,16 +49,27 @@ export class MacOSUpdater extends Updater { const { logger } = this; const { promise, resolve, reject } = explodePromise(); - autoUpdater.on('error', (...args) => { + const onError = (...args: Array) => { logger.error('autoUpdater: error', ...args.map(Errors.toLogFormat)); const [error] = args; + cleanup(); reject(error); - }); - autoUpdater.on('update-downloaded', () => { + }; + + const onDownloaded = () => { logger.info('autoUpdater: update-downloaded event fired'); + cleanup(); resolve(); - }); + }; + + function cleanup() { + autoUpdater.removeListener('error', onError); + autoUpdater.removeListener('update-downloaded', onDownloaded); + } + + autoUpdater.on('error', onError); + autoUpdater.on('update-downloaded', onDownloaded); // See: https://github.com/electron/electron/issues/5020#issuecomment-477636990 const updateUrl = pathToFileURL(filePath).href;