mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-28 09:51:06 -06:00
SDA-2694: add logic to delete app cache before app initialization (#1126)
This commit is contained in:
parent
128bb9c0e3
commit
eb80e42463
@ -123,7 +123,7 @@
|
|||||||
"browserify": "16.5.1",
|
"browserify": "16.5.1",
|
||||||
"cross-env": "5.2.0",
|
"cross-env": "5.2.0",
|
||||||
"del": "3.0.0",
|
"del": "3.0.0",
|
||||||
"electron": "9.3.2",
|
"electron": "9.3.5",
|
||||||
"electron-builder": "22.7.0",
|
"electron-builder": "22.7.0",
|
||||||
"electron-builder-squirrel-windows": "20.38.3",
|
"electron-builder-squirrel-windows": "20.38.3",
|
||||||
"electron-icon-maker": "0.0.4",
|
"electron-icon-maker": "0.0.4",
|
||||||
|
@ -39,6 +39,7 @@ export interface IConfig {
|
|||||||
mainWinPos?: ICustomRectangle;
|
mainWinPos?: ICustomRectangle;
|
||||||
locale?: string;
|
locale?: string;
|
||||||
installVariant?: string;
|
installVariant?: string;
|
||||||
|
bootCount?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IGlobalConfig {
|
export interface IGlobalConfig {
|
||||||
@ -117,6 +118,7 @@ class Config {
|
|||||||
public filteredCloudConfig: ICloudConfig | {};
|
public filteredCloudConfig: ICloudConfig | {};
|
||||||
private isFirstTime: boolean = true;
|
private isFirstTime: boolean = true;
|
||||||
private installVariant: string | undefined;
|
private installVariant: string | undefined;
|
||||||
|
private bootCount: number | undefined;
|
||||||
private readonly configFileName: string;
|
private readonly configFileName: string;
|
||||||
private readonly installVariantFilename: string;
|
private readonly installVariantFilename: string;
|
||||||
private readonly installVariantPath: string;
|
private readonly installVariantPath: string;
|
||||||
@ -278,10 +280,19 @@ class Config {
|
|||||||
// update to the new build number
|
// update to the new build number
|
||||||
filteredFields.buildNumber = buildNumber;
|
filteredFields.buildNumber = buildNumber;
|
||||||
filteredFields.installVariant = this.installVariant;
|
filteredFields.installVariant = this.installVariant;
|
||||||
|
filteredFields.bootCount = 0;
|
||||||
logger.info(`config-handler: setting first time launch for build`, buildNumber);
|
logger.info(`config-handler: setting first time launch for build`, buildNumber);
|
||||||
return await this.updateUserConfig(filteredFields);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -406,16 +417,25 @@ class Config {
|
|||||||
if (!installVariant) {
|
if (!installVariant) {
|
||||||
logger.info(`config-handler: there's no install variant found, this is a first time launch`);
|
logger.info(`config-handler: there's no install variant found, this is a first time launch`);
|
||||||
this.isFirstTime = true;
|
this.isFirstTime = true;
|
||||||
|
this.bootCount = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (installVariant && typeof installVariant === 'string' && installVariant !== this.installVariant) {
|
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`);
|
logger.info(`config-handler: install variant found is of a different instance, this is a first time launch`);
|
||||||
this.isFirstTime = true;
|
this.isFirstTime = true;
|
||||||
|
this.bootCount = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.info(`config-handler: install variant is the same as the existing one, not a first time launch`);
|
logger.info(`config-handler: install variant is the same as the existing one, not a first time launch`);
|
||||||
this.isFirstTime = false;
|
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 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
let oneStart = false;
|
||||||
const startApplication = async () => {
|
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()) {
|
if (config.isFirstTimeLaunch()) {
|
||||||
logger.info(`main: This is a first time launch! will update config and handle auto launch`);
|
logger.info(`main: This is a first time launch! will update config and handle auto launch`);
|
||||||
cleanAppCacheOnInstall();
|
cleanAppCacheOnInstall();
|
||||||
@ -87,11 +92,19 @@ const startApplication = async () => {
|
|||||||
await autoLaunchInstance.handleAutoLaunch();
|
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
|
// Picks global config values and updates them in the user config
|
||||||
await config.updateUserConfigOnStart();
|
await config.updateUserConfigOnStart();
|
||||||
// Setup session properties only after app ready
|
|
||||||
setSessionProperties();
|
setSessionProperties();
|
||||||
await windowHandler.createApplication();
|
await windowHandler.createApplication();
|
||||||
|
restartOnFirstInstall();
|
||||||
logger.info(`main: created application`);
|
logger.info(`main: created application`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ class VersionHandler {
|
|||||||
|
|
||||||
if (!this.mainUrl) {
|
if (!this.mainUrl) {
|
||||||
logger.error(`version-handler: Unable to get pod url for getting version data from server! Setting defaults!`);
|
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);
|
resolve(this.versionInfo);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -386,6 +386,7 @@ export class WindowHandler {
|
|||||||
|
|
||||||
cleanAppCacheOnCrash(this.mainWindow);
|
cleanAppCacheOnCrash(this.mainWindow);
|
||||||
// loads the main window with url from config/cmd line
|
// loads the main window with url from config/cmd line
|
||||||
|
logger.info(`Loading main window with url ${this.url}`);
|
||||||
this.mainWindow.loadURL(this.url);
|
this.mainWindow.loadURL(this.url);
|
||||||
// check for build expiry in case of test builds
|
// check for build expiry in case of test builds
|
||||||
this.checkExpiry(this.mainWindow);
|
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 () => {
|
this.mainWindow.webContents.on('did-finish-load', async () => {
|
||||||
// reset to false when the client reloads
|
// reset to false when the client reloads
|
||||||
this.isMana = false;
|
this.isMana = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user