diff --git a/src/electron/common/common.ts b/src/electron/common/common.ts index 2df0240b..078e7662 100644 --- a/src/electron/common/common.ts +++ b/src/electron/common/common.ts @@ -90,6 +90,7 @@ export interface AppStats { export enum UpdateStatus { Error, + NetworkError, CheckingForUpdate, UpdateNotAvailable, UpdateAvailable, diff --git a/src/electron/main/updater.ts b/src/electron/main/updater.ts index 6c4a20a3..23276257 100644 --- a/src/electron/main/updater.ts +++ b/src/electron/main/updater.ts @@ -20,11 +20,19 @@ export class BreachProtocolAutosolverUpdater { this.registerListeners(); } - checkForUpdates() { + async checkForUpdates() { this.autoUpdate = this.store.getState().settings.autoUpdate; autoUpdater.autoDownload = this.autoUpdate; - autoUpdater.checkForUpdates(); + try { + await autoUpdater.checkForUpdates(); + } catch (error) { + if (error instanceof Error) { + this.onError(error); + } else { + throw error; + } + } } dispose() { @@ -42,6 +50,14 @@ export class BreachProtocolAutosolverUpdater { autoUpdater.on('download-progress', this.onDownloadProgress.bind(this)); } + private onError(error: Error) { + if (error.message === 'net::ERR_INTERNET_DISCONNECTED') { + this.setUpdateStatus(UpdateStatus.NetworkError); + } else { + this.setUpdateStatus(UpdateStatus.Error); + } + } + private onCheckingForUpdates() { this.setUpdateStatus(UpdateStatus.CheckingForUpdate); } diff --git a/src/electron/renderer/components/StatusBar.tsx b/src/electron/renderer/components/StatusBar.tsx index eb8151e7..b4c442f1 100644 --- a/src/electron/renderer/components/StatusBar.tsx +++ b/src/electron/renderer/components/StatusBar.tsx @@ -118,6 +118,7 @@ function useShowUpdateStatus(status: UpdateStatus, delay = 3000) { const updateStatusMessage = { [UpdateStatus.Error]: 'Error occurred', + [UpdateStatus.NetworkError]: 'Offline', [UpdateStatus.CheckingForUpdate]: 'Checking for updates..', [UpdateStatus.UpdateNotAvailable]: 'Up to date', [UpdateStatus.UpdateAvailable]: 'Update available',