SDA-3941 Prevent displaying auto-update banner if triggered by recurring check and there is no update available

This commit is contained in:
sbenmoussati 2022-11-04 09:23:05 +01:00 committed by Salah Benmoussati
parent 04847c2361
commit abdea98dd4
6 changed files with 45 additions and 11 deletions

View File

@ -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,

View File

@ -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<void> => {
logger.info('auto-update-handler: Checking for updates');
public checkUpdates = async (
trigger: AutoUpdateTrigger = AutoUpdateTrigger.MANUAL,
): Promise<void> => {
this.autoUpdateTrigger = trigger;
logger.info('auto-update-handler: Checking for updates', trigger);
if (this.autoUpdater) {
const opts: GenericServerOptions = this.getGenericServerOptions();
this.autoUpdater.setFeedURL(opts);

View File

@ -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;

View File

@ -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));
}

View File

@ -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';

View File

@ -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,
});
}
}