Skip to content

Commit

Permalink
SDA-4489 - Use init instead of constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranNiranjan committed May 3, 2024
1 parent 9e0bd41 commit 9fda23a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 61 deletions.
120 changes: 60 additions & 60 deletions src/app/auto-update-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
};
Expand Down

0 comments on commit 9fda23a

Please sign in to comment.