diff --git a/src/app/memory-monitor.ts b/src/app/memory-monitor.ts index b579abf0..5a83619b 100644 --- a/src/app/memory-monitor.ts +++ b/src/app/memory-monitor.ts @@ -66,59 +66,58 @@ class MemoryMonitor { return; } - (electron.powerMonitor as any).querySystemIdleTime((time) => { - const idleTime = time * 1000; - // for MacOS use private else use residentSet - const memoryConsumption = isMac ? (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`); + const time = electron.powerMonitor.getSystemIdleTime(); + const idleTime = time * 1000; + // for MacOS use private else use residentSet + const memoryConsumption = isMac ? (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`); - 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: `, this.isInMeeting); - return; - } + if (this.isInMeeting) { + logger.info(`memory-monitor: NOT RELOADING -> User is currently in a meeting. Meeting status from client: `, this.isInMeeting); + return; + } - if (!windowHandler.isOnline) { - logger.info(`memory-monitor: NOT RELOADING -> Not connected to network. Network status: `, windowHandler.isOnline); - return; - } + if (!windowHandler.isOnline) { + logger.info(`memory-monitor: NOT RELOADING -> Not connected to network. Network status: `, windowHandler.isOnline); + return; + } - if (!(memoryConsumption && memoryConsumption > this.memoryThreshold)) { - logger.info(`memory-monitor: NOT RELOADING -> Memory consumption ${memoryConsumption} is lesser than the threshold ${this.memoryThreshold}`); - return; - } + if (!(memoryConsumption && memoryConsumption > this.memoryThreshold)) { + logger.info(`memory-monitor: NOT RELOADING -> Memory consumption ${memoryConsumption} is lesser than the threshold ${this.memoryThreshold}`); + return; + } - if (!(idleTime > this.maxIdleTime)) { - logger.info(`memory-monitor: NOT RELOADING -> User is not idle for: `, idleTime); - return; - } + if (!(idleTime > this.maxIdleTime)) { + logger.info(`memory-monitor: NOT RELOADING -> User is not idle for: `, idleTime); + return; + } - if (!this.canReload) { - logger.info(`memory-monitor: NOT RELOADING -> Already refreshed at: `, this.lastReloadTime); - return; - } + if (!this.canReload) { + logger.info(`memory-monitor: NOT RELOADING -> Already refreshed at: `, this.lastReloadTime); + return; + } - const mainWindow = windowHandler.getMainWindow(); - if (!(mainWindow && windowExists(mainWindow))) { - logger.info(`memory-monitor: NOT RELOADING -> Main window doesn't exist!`); - return; - } + const mainWindow = windowHandler.getMainWindow(); + if (!(mainWindow && windowExists(mainWindow))) { + logger.info(`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`); + logger.info(`memory-monitor: RELOADING -> auto reloading the app as all the conditions are satisfied`); - 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 - }); + 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 } }