From 9fda23ab43b998bc8105218ed8dbb9425789b55b Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Tue, 30 Apr 2024 14:52:56 +0530 Subject: [PATCH] SDA-4489 - Use init instead of constructor --- src/app/auto-update-handler.ts | 120 ++++++++++++++++----------------- src/app/main.ts | 2 +- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/app/auto-update-handler.ts b/src/app/auto-update-handler.ts index 0c078510f..714abb17a 100644 --- a/src/app/auto-update-handler.ts +++ b/src/app/auto-update-handler.ts @@ -51,70 +51,70 @@ export class AutoUpdate { private downloadProgressDelayTimer: NodeJS.Timeout | null = null; private isForceUpdate: boolean = false; - constructor() { - this.getGenericServerOptions().then((opts) => { - if (isMac) { - this.autoUpdater = new MacUpdater(opts); - } else if (isWindowsOS) { - this.autoUpdater = new NsisUpdater(opts); - } + public init = async () => { + const opts = await this.getGenericServerOptions(); + if (isMac) { + this.autoUpdater = new MacUpdater(opts); + } else if (isWindowsOS) { + this.autoUpdater = new NsisUpdater(opts); + } - if (this.autoUpdater) { - this.autoUpdater.logger = electronLog; - this.autoUpdater.autoDownload = false; - this.autoUpdater.autoInstallOnAppQuit = true; - this.autoUpdater.allowDowngrade = true; - - this.autoUpdater.on('update-not-available', () => { - if (this.autoUpdateTrigger === AutoUpdateTrigger.AUTOMATED) { - logger.info( - 'auto-update-handler: no update available found with automatic check', - ); - this.autoUpdateTrigger = undefined; - return; - } - const mainWebContents = windowHandler.mainWebContents; - // Display client banner - if (mainWebContents && !mainWebContents.isDestroyed()) { - mainWebContents.send('display-client-banner', { - reason: 'autoUpdate', - action: 'update-not-available', - }); - } - this.autoUpdateTrigger = undefined; - }); - this.autoUpdater.on('update-available', async (info) => { - await this.updateEventHandler(info, 'update-available'); - }); - this.autoUpdater.on('download-progress', async (info) => { - await this.updateEventHandler(info, 'download-progress'); - }); - this.autoUpdater.on('update-downloaded', async (info) => { - if (this.isForceUpdate) { - this.isForceUpdate = false; - logger.info( - 'auto-update-handler: update downloaded and isForceUpdate', - ); - // Handle update and restart for macOS - if (isMac) { - windowHandler.setIsAutoUpdating(true); - } - this.autoUpdater?.quitAndInstall(); - return; - } - await this.updateEventHandler(info, 'update-downloaded'); - }); + if (this.autoUpdater) { + this.autoUpdater.logger = electronLog; + this.autoUpdater.autoDownload = false; + this.autoUpdater.autoInstallOnAppQuit = true; + this.autoUpdater.allowDowngrade = true; - this.autoUpdater.on('error', (error) => { + this.autoUpdater.on('update-not-available', () => { + if (this.autoUpdateTrigger === AutoUpdateTrigger.AUTOMATED) { + logger.info( + 'auto-update-handler: no update available found with automatic check', + ); this.autoUpdateTrigger = undefined; - logger.error( - 'auto-update-handler: Error occurred while updating. ', - error, + return; + } + const mainWebContents = windowHandler.mainWebContents; + // Display client banner + if (mainWebContents && !mainWebContents.isDestroyed()) { + mainWebContents.send('display-client-banner', { + reason: 'autoUpdate', + action: 'update-not-available', + }); + } + this.autoUpdateTrigger = undefined; + }); + this.autoUpdater.on('update-available', async (info) => { + await this.updateEventHandler(info, 'update-available'); + }); + this.autoUpdater.on('download-progress', async (info) => { + await this.updateEventHandler(info, 'download-progress'); + }); + this.autoUpdater.on('update-downloaded', async (info) => { + if (this.isForceUpdate) { + this.isForceUpdate = false; + logger.info( + 'auto-update-handler: update downloaded and isForceUpdate', ); - }); - } - }); - } + // Handle update and restart for macOS + if (isMac) { + windowHandler.setIsAutoUpdating(true); + } + this.autoUpdater?.quitAndInstall(); + return; + } + await this.updateEventHandler(info, 'update-downloaded'); + }); + + this.autoUpdater.on('error', (error) => { + this.autoUpdateTrigger = undefined; + logger.error( + 'auto-update-handler: Error occurred while updating. ', + error, + ); + }); + await this.performForcedAutoUpdate(); + } + }; /** * Checks for updates and performs a forced installation if the latest version is already downloaded. diff --git a/src/app/main.ts b/src/app/main.ts index 80b554f57..614b0f15f 100644 --- a/src/app/main.ts +++ b/src/app/main.ts @@ -108,7 +108,7 @@ const startApplication = async () => { // Picks global config values and updates them in the user config await config.updateUserConfigOnStart(); setSessionProperties(); - await autoUpdate.performForcedAutoUpdate(); + await autoUpdate.init(); await windowHandler.createApplication(); logger.info(`main: created application`); };