From eb80e42463731500958da7b62484d0872b87ca9f Mon Sep 17 00:00:00 2001 From: Vishwas Shashidhar Date: Mon, 30 Nov 2020 16:02:53 +0530 Subject: [PATCH 1/3] SDA-2694: add logic to delete app cache before app initialization (#1126) --- package.json | 2 +- src/app/config-handler.ts | 28 ++++++++++++++++++++++++---- src/app/main.ts | 33 +++++++++++++++++++++++---------- src/app/version-handler.ts | 1 + src/app/window-handler.ts | 17 +++++++++++++++++ 5 files changed, 66 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 37ff9504..b8d173a0 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "browserify": "16.5.1", "cross-env": "5.2.0", "del": "3.0.0", - "electron": "9.3.2", + "electron": "9.3.5", "electron-builder": "22.7.0", "electron-builder-squirrel-windows": "20.38.3", "electron-icon-maker": "0.0.4", diff --git a/src/app/config-handler.ts b/src/app/config-handler.ts index afc094d3..1b2f1635 100644 --- a/src/app/config-handler.ts +++ b/src/app/config-handler.ts @@ -39,6 +39,7 @@ export interface IConfig { mainWinPos?: ICustomRectangle; locale?: string; installVariant?: string; + bootCount?: number; } export interface IGlobalConfig { @@ -117,6 +118,7 @@ class Config { public filteredCloudConfig: ICloudConfig | {}; private isFirstTime: boolean = true; private installVariant: string | undefined; + private bootCount: number | undefined; private readonly configFileName: string; private readonly installVariantFilename: string; private readonly installVariantPath: string; @@ -278,10 +280,19 @@ class Config { // update to the new build number filteredFields.buildNumber = buildNumber; filteredFields.installVariant = this.installVariant; + filteredFields.bootCount = 0; logger.info(`config-handler: setting first time launch for build`, buildNumber); return await this.updateUserConfig(filteredFields); } - await this.updateUserConfig({ buildNumber, installVariant: this.installVariant }); + await this.updateUserConfig({ buildNumber, installVariant: this.installVariant, bootCount: this.bootCount }); + } + + /** + * Gets the boot count for an SDA installation + */ + public getBootCount(): number | undefined { + logger.info(`config-handler: Current boot count is ${this.bootCount}`); + return this.bootCount; } /** @@ -312,9 +323,9 @@ class Config { const { acpFeatureLevelEntitlements, podLevelEntitlements, pmpEntitlements } = this.cloudConfig as ICloudConfig; // Filter out some values - const filteredACP = filterOutSelectedValues(acpFeatureLevelEntitlements, [ true, 'NOT_SET', '', [] ]); - const filteredPod = filterOutSelectedValues(podLevelEntitlements, [ true, 'NOT_SET', '', [] ]); - const filteredPMP = filterOutSelectedValues(pmpEntitlements, [ true, 'NOT_SET', '', [] ]); + const filteredACP = filterOutSelectedValues(acpFeatureLevelEntitlements, [true, 'NOT_SET', '', []]); + const filteredPod = filterOutSelectedValues(podLevelEntitlements, [true, 'NOT_SET', '', []]); + const filteredPMP = filterOutSelectedValues(pmpEntitlements, [true, 'NOT_SET', '', []]); // priority is PMP > ACP > SDA this.filteredCloudConfig = { ...filteredACP, ...filteredPod, ...filteredPMP }; @@ -406,16 +417,25 @@ class Config { if (!installVariant) { logger.info(`config-handler: there's no install variant found, this is a first time launch`); this.isFirstTime = true; + this.bootCount = 0; return; } if (installVariant && typeof installVariant === 'string' && installVariant !== this.installVariant) { logger.info(`config-handler: install variant found is of a different instance, this is a first time launch`); this.isFirstTime = true; + this.bootCount = 0; return; } logger.info(`config-handler: install variant is the same as the existing one, not a first time launch`); this.isFirstTime = false; + this.bootCount = (this.getConfigFields(['bootCount']) as IConfig).bootCount; + if (this.bootCount !== undefined) { + this.bootCount++; + await this.updateUserConfig({ bootCount: this.bootCount }); + } else { + await this.updateUserConfig({ bootCount: 0 }); + } } } diff --git a/src/app/main.ts b/src/app/main.ts index 520a975e..35aa3c06 100644 --- a/src/app/main.ts +++ b/src/app/main.ts @@ -67,18 +67,23 @@ if (!isDevEnv) { } /** - * Main function that init the application + * Restarts the app in case of network issues + */ +const restartOnFirstInstall = async (): Promise => { + const bootCount = config.getBootCount(); + if (bootCount !== undefined && bootCount === 1) { + logger.warn(`Boot count fits the criteria of equal to 1, restarting the app`); + app.relaunch(); + app.quit(); + } + logger.warn(`Boot count does not fit the criteria of lesser than or equal to 1, not restarting the app`); +}; + +/** + * Main function that initialises the application */ let oneStart = false; const startApplication = async () => { - await app.whenReady(); - if (oneStart) { - return; - } - - logger.info('main: app is ready, performing initial checks oneStart: ' + oneStart); - oneStart = true; - createAppCacheFile(); if (config.isFirstTimeLaunch()) { logger.info(`main: This is a first time launch! will update config and handle auto launch`); cleanAppCacheOnInstall(); @@ -87,11 +92,19 @@ const startApplication = async () => { await autoLaunchInstance.handleAutoLaunch(); } } + await app.whenReady(); + if (oneStart) { + return; + } + + logger.info('main: app is ready, performing initial checks oneStart: ' + oneStart); + oneStart = true; + createAppCacheFile(); // Picks global config values and updates them in the user config await config.updateUserConfigOnStart(); - // Setup session properties only after app ready setSessionProperties(); await windowHandler.createApplication(); + restartOnFirstInstall(); logger.info(`main: created application`); }; diff --git a/src/app/version-handler.ts b/src/app/version-handler.ts index 55c0f4ad..26e5aa26 100644 --- a/src/app/version-handler.ts +++ b/src/app/version-handler.ts @@ -77,6 +77,7 @@ class VersionHandler { if (!this.mainUrl) { logger.error(`version-handler: Unable to get pod url for getting version data from server! Setting defaults!`); + logger.info(`version-handler: Setting defaults -> ${JSON.stringify(this.versionInfo)}`); resolve(this.versionInfo); return; } diff --git a/src/app/window-handler.ts b/src/app/window-handler.ts index 10a26958..f206940d 100644 --- a/src/app/window-handler.ts +++ b/src/app/window-handler.ts @@ -386,6 +386,7 @@ export class WindowHandler { cleanAppCacheOnCrash(this.mainWindow); // loads the main window with url from config/cmd line + logger.info(`Loading main window with url ${this.url}`); this.mainWindow.loadURL(this.url); // check for build expiry in case of test builds this.checkExpiry(this.mainWindow); @@ -412,6 +413,22 @@ export class WindowHandler { ); }); + const logEvents = [ + 'did-fail-provisional-load', 'did-frame-finish-load', + 'did-start-loading', 'did-stop-loading', 'will-redirect', + 'did-navigate', 'did-navigate-in-page', 'preload-error', + ]; + + logEvents.forEach((windowEvent: any) => { + this.mainWindow?.webContents.on(windowEvent, () => { + logger.info(`window-handler: Main Window Event Occurred: ${windowEvent}`); + }); + }); + + this.mainWindow.once('ready-to-show', (event: Electron.Event) => { + logger.info(`window-handler: Main Window ready to show: ${event}`); + }); + this.mainWindow.webContents.on('did-finish-load', async () => { // reset to false when the client reloads this.isMana = false; From fabb8fb860eb4ca917264173369c309e0648630d Mon Sep 17 00:00:00 2001 From: Johan Kwarnmark Date: Mon, 30 Nov 2020 12:14:09 +0100 Subject: [PATCH 2/3] sda-2700 show 1.5/SFE 2.0/SFE-lite --- package.json | 3 ++- spec/__snapshots__/aboutApp.spec.ts.snap | 3 ++- spec/aboutApp.spec.ts | 1 + spectron/about-app.spec.ts | 1 + src/app/version-handler.ts | 24 +++++++++++++++++++++--- src/renderer/components/about-app.tsx | 11 +++++++++-- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index b8d173a0..4d78517d 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "buildNumber": "0", "searchAPIVersion": "1.55.3", "sfeVersion": "0", + "sfeClientType": "1.5", "description": "Symphony desktop app (Foundation ODP)", "author": "Symphony OSS ", "main": "lib/src/app/init.js", @@ -182,4 +183,4 @@ "!lib/src/**/*.js" ] } -} +} \ No newline at end of file diff --git a/spec/__snapshots__/aboutApp.spec.ts.snap b/spec/__snapshots__/aboutApp.spec.ts.snap index cd69763d..6d3363d9 100644 --- a/spec/__snapshots__/aboutApp.spec.ts.snap +++ b/spec/__snapshots__/aboutApp.spec.ts.snap @@ -62,7 +62,8 @@ exports[`about app should render correctly 1`] = `
  • - SFE: + SFE-Lite + : N/A diff --git a/spec/aboutApp.spec.ts b/spec/aboutApp.spec.ts index 3fa79bd8..ef40a143 100644 --- a/spec/aboutApp.spec.ts +++ b/spec/aboutApp.spec.ts @@ -16,6 +16,7 @@ describe('about app', () => { buildNumber: '4.x.x', hostname: 'N/A', sfeVersion: 'N/A', + sfeClientType: '1.5', sdaVersion: '3.8.0', sdaBuildNumber: '0', electronVersion: '3.1.11', diff --git a/spectron/about-app.spec.ts b/spectron/about-app.spec.ts index 36deb3e0..b40458b9 100644 --- a/spectron/about-app.spec.ts +++ b/spectron/about-app.spec.ts @@ -41,6 +41,7 @@ test('about-app: verify copy button with few data validation', async (t) => { t.true(clipboard.hasOwnProperty('appName')); t.true(clipboard.hasOwnProperty('clientVersion')); t.true(clipboard.hasOwnProperty('sfeVersion')); + t.true(clipboard.hasOwnProperty('sfeClientType')); t.true(clipboard.hasOwnProperty('sdaVersion')); t.true(clipboard.hasOwnProperty('sdaBuildNumber')); robotActions.closeWindow(); diff --git a/src/app/version-handler.ts b/src/app/version-handler.ts index 26e5aa26..8aea35d8 100644 --- a/src/app/version-handler.ts +++ b/src/app/version-handler.ts @@ -1,6 +1,6 @@ import { net } from 'electron'; import * as nodeURL from 'url'; -import { buildNumber, clientVersion, optionalDependencies, searchAPIVersion, sfeVersion, version } from '../../package.json'; +import { buildNumber, clientVersion, optionalDependencies, searchAPIVersion, sfeClientType, sfeVersion, version } from '../../package.json'; import { logger } from '../common/logger'; import { config, IGlobalConfig } from './config-handler'; @@ -8,6 +8,7 @@ interface IVersionInfo { clientVersion: string; buildNumber: string; sfeVersion: string; + sfeClientType: string; sdaVersion: string; sdaBuildNumber: string; electronVersion: string; @@ -35,6 +36,7 @@ class VersionHandler { clientVersion, buildNumber, sfeVersion, + sfeClientType, sdaVersion: version, sdaBuildNumber: buildNumber, electronVersion: process.versions.electron, @@ -140,8 +142,22 @@ class VersionHandler { request.end(); + logger.info('version-handler: mainUrl: ' + mainUrl); + logger.info('version-handler: hostname: ' + hostname); + /* Get SFE version */ - const urlSfeVersion = `${protocol}//${hostname}/client/version.json`; + let urlSfeVersion; + if (mainUrl?.includes('/client-bff/')) { + if (mainUrl?.includes('/client-bff/daily/')) { + urlSfeVersion = `${protocol}//${hostname}/client-bff/daily/version.json`; + } else { + urlSfeVersion = `${protocol}//${hostname}/client-bff/version.json`; + } + this.versionInfo.sfeClientType = '2.0'; + } else { + urlSfeVersion = `${protocol}//${hostname}/client/version.json`; + this.versionInfo.sfeClientType = '1.5'; + } logger.info(`version-handler: Trying to get SFE version info for the URL: ${urlSfeVersion}`); const requestSfeVersion = net.request(urlSfeVersion); @@ -159,7 +175,9 @@ class VersionHandler { this.versionInfo.sfeVersion = this.sfeVersionInfo[key]; - logger.info(`version-handler: Updated SFE version info from server! ${JSON.stringify(this.versionInfo)}`); + logger.info('version-handler: SFE-version: ' + this.sfeVersionInfo[key]); + + logger.info(`version-handler: Updated SFE version info from server! ${JSON.stringify(this.versionInfo, null, 3)}`); resolve(this.versionInfo); } catch (error) { logger.error(`version-handler: Error getting SFE version data from the server! ${error}`); diff --git a/src/renderer/components/about-app.tsx b/src/renderer/components/about-app.tsx index 6bb2dd67..0df13d51 100644 --- a/src/renderer/components/about-app.tsx +++ b/src/renderer/components/about-app.tsx @@ -12,6 +12,7 @@ interface IState { buildNumber: string; hostname: string; sfeVersion: string; + sfeClientType: string; versionLocalised?: string; sdaVersion?: string; sdaBuildNumber?: string; @@ -53,6 +54,7 @@ export default class AboutApp extends React.Component<{}, IState> { buildNumber: 'N/A', hostname: 'N/A', sfeVersion: 'N/A', + sfeClientType: 'N/A', sdaVersion: 'N/A', sdaBuildNumber: 'N/A', electronVersion: 'N/A', @@ -75,13 +77,18 @@ export default class AboutApp extends React.Component<{}, IState> { */ public render(): JSX.Element { const { clientVersion, buildNumber, hostname, sfeVersion, - sdaVersion, sdaBuildNumber, client, + sfeClientType, sdaVersion, sdaBuildNumber, client, } = this.state; const appName = remote.app.getName() || 'Symphony'; const copyright = `\xA9 ${new Date().getFullYear()} ${appName}`; const podVersion = `${clientVersion} (${buildNumber})`; const sdaVersionBuild = `${sdaVersion} (${sdaBuildNumber})`; + let sfeClientTypeName = 'SFE'; + if (sfeClientType !== '1.5') { + sfeClientTypeName = 'SFE-Lite'; + } + return (
    @@ -103,7 +110,7 @@ export default class AboutApp extends React.Component<{}, IState> {
  • POD: {hostname || 'N/A'}
  • SBE: {podVersion}
  • SDA: {sdaVersionBuild}
  • -
  • SFE: {sfeVersion} {client}
  • +
  • {sfeClientTypeName}: {sfeVersion} {client}
  • From 4d155d13c9bbdcd6b149d2887fcafa6fea59a838 Mon Sep 17 00:00:00 2001 From: Vishwas Shashidhar Date: Tue, 1 Dec 2020 18:05:04 +0530 Subject: [PATCH 3/3] SDA-2731: remove logic of deleting app cache on first install (#1128) --- src/app/main.ts | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/app/main.ts b/src/app/main.ts index 35aa3c06..c9642e86 100644 --- a/src/app/main.ts +++ b/src/app/main.ts @@ -5,7 +5,7 @@ import * as shellPath from 'shell-path'; import { isDevEnv, isElectronQA, isLinux, isMac } from '../common/env'; import { logger } from '../common/logger'; import { getCommandLineArgs } from '../common/utils'; -import { cleanAppCacheOnInstall, cleanUpAppCache, createAppCacheFile } from './app-cache-handler'; +import { cleanUpAppCache, createAppCacheFile } from './app-cache-handler'; import { autoLaunchInstance } from './auto-launch-controller'; import { setChromeFlags, setSessionProperties } from './chrome-flags'; import { config } from './config-handler'; @@ -66,19 +66,6 @@ if (!isDevEnv) { app.setAsDefaultProtocolClient('symphony'); } -/** - * Restarts the app in case of network issues - */ -const restartOnFirstInstall = async (): Promise => { - const bootCount = config.getBootCount(); - if (bootCount !== undefined && bootCount === 1) { - logger.warn(`Boot count fits the criteria of equal to 1, restarting the app`); - app.relaunch(); - app.quit(); - } - logger.warn(`Boot count does not fit the criteria of lesser than or equal to 1, not restarting the app`); -}; - /** * Main function that initialises the application */ @@ -86,7 +73,6 @@ let oneStart = false; const startApplication = async () => { if (config.isFirstTimeLaunch()) { logger.info(`main: This is a first time launch! will update config and handle auto launch`); - cleanAppCacheOnInstall(); await config.setUpFirstTimeLaunch(); if (!isLinux) { await autoLaunchInstance.handleAutoLaunch(); @@ -104,7 +90,6 @@ const startApplication = async () => { await config.updateUserConfigOnStart(); setSessionProperties(); await windowHandler.createApplication(); - restartOnFirstInstall(); logger.info(`main: created application`); };