diff --git a/src/app/app-menu.ts b/src/app/app-menu.ts index f9be7c06..435f1ca2 100644 --- a/src/app/app-menu.ts +++ b/src/app/app-menu.ts @@ -38,7 +38,7 @@ import { } from './window-utils'; import { autoLaunchInstance as autoLaunch } from './auto-launch-controller'; -import { autoUpdate } from './auto-update-handler'; +import { autoUpdate, AutoUpdateTrigger } from './auto-update-handler'; export const menuSections = { about: 'about', @@ -299,7 +299,7 @@ export class AppMenu { }, { click: (_item) => { - autoUpdate.checkUpdates(); + autoUpdate.checkUpdates(AutoUpdateTrigger.MANUAL); }, visible: isMac && !!isAutoUpdateEnabled && !!windowHandler.isMana, label: i18n.t('Check for updates')(), @@ -689,7 +689,7 @@ export class AppMenu { }, { click: (_item) => { - autoUpdate.checkUpdates(); + autoUpdate.checkUpdates(AutoUpdateTrigger.MANUAL); }, visible: isWindowsOS && !!isAutoUpdateEnabled && !!windowHandler.isMana, diff --git a/src/app/auto-update-handler.ts b/src/app/auto-update-handler.ts index e0cd179b..ee1c5c5f 100644 --- a/src/app/auto-update-handler.ts +++ b/src/app/auto-update-handler.ts @@ -11,10 +11,16 @@ import { windowHandler } from './window-handler'; const DEFAULT_AUTO_UPDATE_CHANNEL = 'sda-update'; +export enum AutoUpdateTrigger { + MANUAL = 'MANUAL', + AUTOMATED = 'AUTOMATED', +} + export class AutoUpdate { public isUpdateAvailable: boolean = false; public didPublishDownloadProgress: boolean = false; public autoUpdater: MacUpdater | NsisUpdater | undefined = undefined; + private autoUpdateTrigger: AutoUpdateTrigger | undefined = undefined; constructor() { const opts = this.getGenericServerOptions(); @@ -31,6 +37,13 @@ export class AutoUpdate { 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()) { @@ -39,6 +52,7 @@ export class AutoUpdate { action: 'update-not-available', }); } + this.autoUpdateTrigger = undefined; }); this.autoUpdater.on('update-available', (info) => { @@ -82,6 +96,14 @@ export class AutoUpdate { }); } }); + + this.autoUpdater.on('error', (error) => { + this.autoUpdateTrigger = undefined; + logger.error( + 'auto-update-handler: Error occurred while updating. ', + error, + ); + }); } } @@ -111,8 +133,11 @@ export class AutoUpdate { * Checks for the latest updates * @return void */ - public checkUpdates = async (): Promise => { - logger.info('auto-update-handler: Checking for updates'); + public checkUpdates = async ( + trigger: AutoUpdateTrigger = AutoUpdateTrigger.MANUAL, + ): Promise => { + this.autoUpdateTrigger = trigger; + logger.info('auto-update-handler: Checking for updates', trigger); if (this.autoUpdater) { const opts: GenericServerOptions = this.getGenericServerOptions(); this.autoUpdater.setFeedURL(opts); diff --git a/src/app/main-api-handler.ts b/src/app/main-api-handler.ts index f5375aa9..7dd7a0f2 100644 --- a/src/app/main-api-handler.ts +++ b/src/app/main-api-handler.ts @@ -46,7 +46,7 @@ import { windowExists, } from './window-utils'; -import { autoUpdate } from './auto-update-handler'; +import { autoUpdate, AutoUpdateTrigger } from './auto-update-handler'; // Swift search API let swiftSearchInstance; @@ -385,7 +385,12 @@ ipcMain.on( autoUpdate.downloadUpdate(); break; case apiCmds.checkForUpdates: - autoUpdate.checkUpdates(); + const autoUpdateTrigger = arg.autoUpdateTrigger; + if (autoUpdateTrigger && autoUpdateTrigger in AutoUpdateTrigger) { + autoUpdate.checkUpdates(arg.autoUpdateTrigger); + } else { + autoUpdate.checkUpdates(); + } break; default: break; diff --git a/src/app/window-utils.ts b/src/app/window-utils.ts index 772e3d9b..d33d181d 100644 --- a/src/app/window-utils.ts +++ b/src/app/window-utils.ts @@ -48,7 +48,7 @@ import { import { notification } from '../renderer/notification'; import { autoLaunchInstance } from './auto-launch-controller'; -import { autoUpdate } from './auto-update-handler'; +import { autoUpdate, AutoUpdateTrigger } from './auto-update-handler'; import { mainEvents } from './main-event-handler'; interface IStyles { @@ -1107,7 +1107,7 @@ export const updateFeaturesForCloudConfig = async ( await config.updateUserConfig({ lastAutoUpdateCheckDate: new Date().toISOString(), }); - autoUpdate.checkUpdates(); + autoUpdate.checkUpdates(AutoUpdateTrigger.AUTOMATED); return; } logger.info( @@ -1124,7 +1124,7 @@ export const updateFeaturesForCloudConfig = async ( await config.updateUserConfig({ lastAutoUpdateCheckDate: new Date().toISOString(), }); - autoUpdate.checkUpdates(); + autoUpdate.checkUpdates(AutoUpdateTrigger.AUTOMATED); } }, getRandomTime(MIN_AUTO_UPDATE_CHECK_INTERVAL, MAX_AUTO_UPDATE_CHECK_INTERVAL)); } diff --git a/src/common/api-interface.ts b/src/common/api-interface.ts index c9216dbc..ad40f11a 100644 --- a/src/common/api-interface.ts +++ b/src/common/api-interface.ts @@ -1,4 +1,5 @@ import { Size } from 'electron'; +import { AutoUpdateTrigger } from '../app/auto-update-handler'; export enum apiCmds { isOnline = 'is-online', @@ -123,6 +124,7 @@ export interface IApiArgs { thumbnailSize: Size; pipe: string; data: Uint8Array; + autoUpdateTrigger: AutoUpdateTrigger; } export type Themes = 'light' | 'dark'; diff --git a/src/renderer/ssf-api.ts b/src/renderer/ssf-api.ts index 68a95006..7cfa4cd2 100644 --- a/src/renderer/ssf-api.ts +++ b/src/renderer/ssf-api.ts @@ -5,6 +5,7 @@ import { searchAPIVersion, version, } from '../../package.json'; +import { AutoUpdateTrigger } from '../app/auto-update-handler'; import { IShellStatus } from '../app/c9-shell-handler'; import { RedirectionStatus } from '../app/citrix-handler'; import { IDownloadItem } from '../app/download-handler'; @@ -818,9 +819,10 @@ export class SSFApi { /** * Allows JS to check for updates */ - public checkForUpdates(): void { + public checkForUpdates(autoUpdateTrigger?: AutoUpdateTrigger): void { ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.checkForUpdates, + autoUpdateTrigger, }); } }