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;