diff --git a/src/app/memory-monitor.ts b/src/app/memory-monitor.ts index faaf3ab4..deaa12c0 100644 --- a/src/app/memory-monitor.ts +++ b/src/app/memory-monitor.ts @@ -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.', + ); + } } } diff --git a/src/app/window-actions.ts b/src/app/window-actions.ts index 3356d0cf..af8e0236 100644 --- a/src/app/window-actions.ts +++ b/src/app/window-actions.ts @@ -404,7 +404,7 @@ const handleMediaPermissions = async ( callback: (permission: boolean) => void, details: PermissionRequestHandlerHandlerDetails, ): Promise => { - logger.info(`window-action: permission is ->`, { type: message, permission }); + logger.info('window-action: permission is ->', permission); let systemAudioPermission; let systemVideoPermission; if (isMac) { diff --git a/src/app/window-handler.ts b/src/app/window-handler.ts index ab6d6a0c..400b8272 100644 --- a/src/app/window-handler.ts +++ b/src/app/window-handler.ts @@ -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; diff --git a/src/app/window-utils.ts b/src/app/window-utils.ts index eae4f96a..492982c2 100644 --- a/src/app/window-utils.ts +++ b/src/app/window-utils.ts @@ -950,7 +950,7 @@ export const updateFeaturesForCloudConfig = async (): Promise => { : autoLaunchInstance.disableAutoLaunch(); if (mainWebContents && !mainWebContents.isDestroyed()) { - if (memoryRefresh) { + if (memoryRefresh && memoryRefresh === CloudConfigDataTypes.ENABLED) { logger.info( `window-utils: updating the memory threshold`, memoryThreshold,