mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-28 09:51:06 -06:00
SDA-3442 App refresh when memory threshold reached (#1290)
* SDA-3442 App refresh when memory threshold reached * Small improvements
This commit is contained in:
parent
bc9b6cf8ce
commit
e50c6fe379
@ -61,11 +61,11 @@ class MemoryMonitor {
|
||||
* Validates the predefined conditions and refreshes the client
|
||||
*/
|
||||
private validateMemory(): void {
|
||||
logger.info(`memory-monitor: validating memory refresh conditions`);
|
||||
logger.info('memory-monitor: validating memory refresh conditions');
|
||||
const { memoryRefresh } = config.getConfigFields(['memoryRefresh']);
|
||||
if (memoryRefresh !== CloudConfigDataTypes.ENABLED) {
|
||||
logger.info(
|
||||
`memory-monitor: memory reload is disabled in the config, not going to refresh!`,
|
||||
'memory-monitor: memory reload is disabled in the config, not going to refresh!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -77,18 +77,17 @@ class MemoryMonitor {
|
||||
? this.memoryInfo && this.memoryInfo.private
|
||||
: this.memoryInfo && this.memoryInfo.residentSet;
|
||||
logger.info(
|
||||
`memory-monitor: Checking different conditions to see if we should auto reload the app`,
|
||||
'memory-monitor: Checking different conditions to see if we should auto reload the app',
|
||||
);
|
||||
|
||||
logger.info(`memory-monitor: Is in meeting: `, this.isInMeeting);
|
||||
logger.info(`memory-monitor: Is Network online: `, windowHandler.isOnline);
|
||||
logger.info(`memory-monitor: Memory consumption: `, memoryConsumption);
|
||||
logger.info(`memory-monitor: Idle Time: `, idleTime);
|
||||
logger.info(`memory-monitor: Last Reload time: `, this.lastReloadTime);
|
||||
|
||||
logger.info('memory-monitor: Is in meeting: ', this.isInMeeting);
|
||||
logger.info('memory-monitor: Is Network online: ', windowHandler.isOnline);
|
||||
logger.info('memory-monitor: Memory consumption: ', memoryConsumption);
|
||||
logger.info('memory-monitor: Idle Time: ', idleTime);
|
||||
logger.info('memory-monitor: Last Reload time: ', this.lastReloadTime);
|
||||
if (this.isInMeeting) {
|
||||
logger.info(
|
||||
`memory-monitor: NOT RELOADING -> User is currently in a meeting. Meeting status from client: `,
|
||||
'memory-monitor: NOT RELOADING -> User is currently in a meeting. Meeting status from client: ',
|
||||
this.isInMeeting,
|
||||
);
|
||||
return;
|
||||
@ -96,7 +95,7 @@ class MemoryMonitor {
|
||||
|
||||
if (!windowHandler.isOnline) {
|
||||
logger.info(
|
||||
`memory-monitor: NOT RELOADING -> Not connected to network. Network status: `,
|
||||
'memory-monitor: NOT RELOADING -> Not connected to network. Network status: ',
|
||||
windowHandler.isOnline,
|
||||
);
|
||||
return;
|
||||
@ -111,15 +110,14 @@ class MemoryMonitor {
|
||||
|
||||
if (!(idleTime > this.maxIdleTime)) {
|
||||
logger.info(
|
||||
`memory-monitor: NOT RELOADING -> User is not idle for: `,
|
||||
'memory-monitor: NOT RELOADING -> User is not idle for: ',
|
||||
idleTime,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.canReload) {
|
||||
logger.info(
|
||||
`memory-monitor: NOT RELOADING -> Already refreshed at: `,
|
||||
'memory-monitor: NOT RELOADING -> Already refreshed at: ',
|
||||
this.lastReloadTime,
|
||||
);
|
||||
return;
|
||||
@ -128,22 +126,36 @@ class MemoryMonitor {
|
||||
const mainWindow = windowHandler.getMainWindow();
|
||||
if (!(mainWindow && windowExists(mainWindow))) {
|
||||
logger.info(
|
||||
`memory-monitor: NOT RELOADING -> Main window doesn't exist!`,
|
||||
"memory-monitor: NOT RELOADING -> Main window doesn't exist!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(
|
||||
`memory-monitor: RELOADING -> auto reloading the app as all the conditions are satisfied`,
|
||||
'memory-monitor: RELOADING -> auto reloading the app as all the conditions are satisfied',
|
||||
);
|
||||
this.reloadMainWindow();
|
||||
}
|
||||
|
||||
windowHandler.setIsAutoReload(true);
|
||||
mainWindow.reload();
|
||||
this.canReload = false;
|
||||
this.lastReloadTime = new Date().getTime();
|
||||
setTimeout(() => {
|
||||
this.canReload = true;
|
||||
}, this.memoryRefreshThreshold); // prevents multiple reloading of the client within 24hrs
|
||||
/***
|
||||
* Reloads main window
|
||||
*/
|
||||
private reloadMainWindow(): void {
|
||||
const mainWebContents = windowHandler.getMainWebContents();
|
||||
if (mainWebContents && !mainWebContents.isDestroyed()) {
|
||||
windowHandler.setIsAutoReload(true);
|
||||
this.canReload = false;
|
||||
this.lastReloadTime = new Date().getTime();
|
||||
setTimeout(() => {
|
||||
this.canReload = true;
|
||||
}, this.memoryRefreshThreshold); // prevents multiple reloading of the client within 24hrs
|
||||
logger.info('memory-monitor: auto-reload start');
|
||||
mainWebContents.reloadIgnoringCache();
|
||||
} else {
|
||||
logger.error(
|
||||
'memory-monitor: Unable to reload, no main window webContents found.',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,7 +404,7 @@ const handleMediaPermissions = async (
|
||||
callback: (permission: boolean) => void,
|
||||
details: PermissionRequestHandlerHandlerDetails,
|
||||
): Promise<void> => {
|
||||
logger.info(`window-action: permission is ->`, { type: message, permission });
|
||||
logger.info('window-action: permission is ->', permission);
|
||||
let systemAudioPermission;
|
||||
let systemVideoPermission;
|
||||
if (isMac) {
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
crashReporter,
|
||||
DesktopCapturerSource,
|
||||
dialog,
|
||||
Event,
|
||||
globalShortcut,
|
||||
ipcMain,
|
||||
RenderProcessGoneDetails,
|
||||
@ -432,10 +433,19 @@ export class WindowHandler {
|
||||
});
|
||||
});
|
||||
|
||||
this.mainWindow.once('ready-to-show', (event: Electron.Event) => {
|
||||
this.mainWindow.once('ready-to-show', (event: Event) => {
|
||||
logger.info(`window-handler: Main Window ready to show: ${event}`);
|
||||
});
|
||||
|
||||
this.mainWebContents.on(
|
||||
'did-fail-load',
|
||||
(_, errorCode: number, errorDescription: string) => {
|
||||
logger.error(
|
||||
`window-handler: Fail loading - Error code: ${errorCode}. Error desscription: ${errorDescription}`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
this.mainWebContents.on('did-finish-load', async () => {
|
||||
// reset to false when the client reloads
|
||||
this.isMana = false;
|
||||
|
@ -950,7 +950,7 @@ export const updateFeaturesForCloudConfig = async (): Promise<void> => {
|
||||
: autoLaunchInstance.disableAutoLaunch();
|
||||
|
||||
if (mainWebContents && !mainWebContents.isDestroyed()) {
|
||||
if (memoryRefresh) {
|
||||
if (memoryRefresh && memoryRefresh === CloudConfigDataTypes.ENABLED) {
|
||||
logger.info(
|
||||
`window-utils: updating the memory threshold`,
|
||||
memoryThreshold,
|
||||
|
Loading…
Reference in New Issue
Block a user