SDA-2694: add logic to delete app cache before app initialization (#1126)

This commit is contained in:
Vishwas Shashidhar 2020-11-30 16:02:53 +05:30 committed by GitHub
parent 128bb9c0e3
commit eb80e42463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 15 deletions

View File

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

View File

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

View File

@ -67,18 +67,23 @@ if (!isDevEnv) {
}
/**
* Main function that init the application
* Restarts the app in case of network issues
*/
const restartOnFirstInstall = async (): Promise<void> => {
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`);
};

View File

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

View File

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