mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-11-21 16:38:41 -06:00
SDA-4247 (Update user config once on before-quit) (#1918)
* SDA-4347 - Add Semaphore for updating user config file Signed-off-by: Kiran Niranjan <kiran.niranjan@symphony.com> * SDA-4347 - Update user config once on before-quit Signed-off-by: Kiran Niranjan <kiran.niranjan@symphony.com> * SDA-4347 - Handle application exit Signed-off-by: Kiran Niranjan <kiran.niranjan@symphony.com> * SDA-4347 - Fix uts Signed-off-by: Kiran Niranjan <kiran.niranjan@symphony.com> --------- Signed-off-by: Kiran Niranjan <kiran.niranjan@symphony.com>
This commit is contained in:
parent
090c8e52b1
commit
b41e07db88
@ -42,6 +42,16 @@ jest.mock('../src/common/logger', () => {
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('../src/app/window-handler', () => {
|
||||
return {
|
||||
windowHandler: {
|
||||
createMoreInfoWindow: jest.fn(),
|
||||
getMainWindow: jest.fn(),
|
||||
isMana: true,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('app cache handler', () => {
|
||||
describe('check app cache file', () => {
|
||||
const cachePathExpected = path.join(app.getPath('userData'), 'CacheCheck');
|
||||
|
@ -11,6 +11,7 @@ import * as rimraf from 'rimraf';
|
||||
import { i18n } from '../common/i18n';
|
||||
|
||||
import { logger } from '../common/logger';
|
||||
import { windowHandler } from './window-handler';
|
||||
|
||||
// Cache check file path
|
||||
const userDataPath: string = app.getPath('userData');
|
||||
@ -123,8 +124,7 @@ export const cleanAppCacheOnCrash = (window: BrowserWindow): void => {
|
||||
|
||||
if (response === 0) {
|
||||
cleanOldCache();
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
await windowHandler.exitApplication(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { app, powerSaveBlocker } from 'electron';
|
||||
import { powerSaveBlocker } from 'electron';
|
||||
import { logger } from '../common/logger';
|
||||
import { windowHandler } from './window-handler';
|
||||
class AppStateHandler {
|
||||
private id?: number;
|
||||
|
||||
@ -9,8 +10,7 @@ class AppStateHandler {
|
||||
*/
|
||||
public restart() {
|
||||
logger.info(`Restarting app as per instruction from SFE`);
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
windowHandler.exitApplication(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,6 +219,8 @@ class Config {
|
||||
this.readGlobalConfig();
|
||||
this.readInstallVariant();
|
||||
this.readCloudConfig();
|
||||
|
||||
app.on('before-quit', this.writeUserConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,6 +322,13 @@ class Config {
|
||||
JSON.stringify(data),
|
||||
);
|
||||
this.userConfig = { ...this.userConfig, ...data };
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the config data into the user config file
|
||||
*/
|
||||
public writeUserConfig = async (): Promise<void> => {
|
||||
logger.info(`config-handler: Updating user config file`);
|
||||
try {
|
||||
await writeFile(
|
||||
this.userConfigPath,
|
||||
@ -328,13 +337,13 @@ class Config {
|
||||
);
|
||||
logger.info(
|
||||
`config-handler: updated user config values with the data ${JSON.stringify(
|
||||
data,
|
||||
this.userConfig,
|
||||
)}`,
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`config-handler: failed to update user config file with ${JSON.stringify(
|
||||
data,
|
||||
this.userConfig,
|
||||
)}`,
|
||||
error,
|
||||
);
|
||||
@ -343,7 +352,7 @@ class Config {
|
||||
`Failed to update user config due to error: ${error}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* updates new data to the cloud config
|
||||
|
@ -194,8 +194,7 @@ export const titleBarChangeDialog = async (
|
||||
if (response === 0) {
|
||||
logger.error(`test`, isNativeStyle);
|
||||
await config.updateUserConfig({ isCustomTitleBar: isNativeStyle });
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
await windowHandler.exitApplication(true);
|
||||
}
|
||||
};
|
||||
|
||||
@ -220,7 +219,6 @@ export const restartDialog = async (configFields: any) => {
|
||||
const { response } = await dialog.showMessageBox(focusedWindow, options);
|
||||
await config.updateUserConfig(configFields);
|
||||
if (response === 0) {
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
await windowHandler.exitApplication(true);
|
||||
}
|
||||
};
|
||||
|
@ -1188,8 +1188,7 @@ export class WindowHandler {
|
||||
logger.info('window-handler: user updated pod url', hostname);
|
||||
const url = new URL(`https://${hostname}`).toString();
|
||||
await config.updateUserConfig({ url });
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
await windowHandler.exitApplication(true);
|
||||
};
|
||||
|
||||
await versionHandler.getClientVersion(true, this.url);
|
||||
@ -2289,6 +2288,14 @@ export class WindowHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public exitApplication = async (shouldRelaunch: boolean = true) => {
|
||||
await config.writeUserConfig();
|
||||
if (shouldRelaunch) {
|
||||
app.relaunch();
|
||||
}
|
||||
app.exit();
|
||||
};
|
||||
|
||||
/**
|
||||
* Listens for app load timeouts and reloads if required
|
||||
*/
|
||||
@ -2374,7 +2381,7 @@ export class WindowHandler {
|
||||
|
||||
const { response } = await dialog.showMessageBox(browserWindow, options);
|
||||
if (response === 0) {
|
||||
app.exit();
|
||||
await this.exitApplication(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user