Skip to content

Commit

Permalink
fix: remove handlers and listeners before creating auto update manager
Browse files Browse the repository at this point in the history
  • Loading branch information
nicole-obrien committed Sep 4, 2023
1 parent 850e929 commit 1a7c051
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/desktop/lib/electron/managers/auto-update.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,25 @@ interface VersionDetails {

export default class AutoUpdateManager {
private downloadCancellation?: CancellationToken
private ipcHandlersRegistered = false

constructor() {
this.init()
}

private init(): void {
if (!this.ipcHandlersRegistered) {
ipcMain.handle('update-download', this.updateDownload.bind(this))
ipcMain.handle('update-cancel', this.updateCancel.bind(this))
ipcMain.handle('update-install', this.updateInstall.bind(this))
ipcMain.handle('update-check', this.updateCheck.bind(this))
this.ipcHandlersRegistered = true
}
this.removeHandlers()
ipcMain.handle('update-download', this.updateDownload.bind(this))
ipcMain.handle('update-cancel', this.updateCancel.bind(this))
ipcMain.handle('update-install', this.updateInstall.bind(this))
ipcMain.handle('update-check', this.updateCheck.bind(this))

autoUpdater.logger = electronLog
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
autoUpdater.logger.transports.file.level = 'info'
autoUpdater.autoDownload = false

autoUpdater.removeAllListeners()
autoUpdater.on('update-available', this.handleUpdateAvailable.bind(this))
autoUpdater.on('download-progress', this.handleDownloadProgress.bind(this))
autoUpdater.on('update-downloaded', this.handleUpdateDownloaded.bind(this))
Expand Down Expand Up @@ -92,4 +90,11 @@ export default class AutoUpdateManager {
console.error(error)
}
}

private removeHandlers(): void {
ipcMain.removeHandler('update-download')
ipcMain.removeHandler('update-cancel')
ipcMain.removeHandler('update-install')
ipcMain.removeHandler('update-check')
}
}

0 comments on commit 1a7c051

Please sign in to comment.