fix: SDA-2330 - Update API from querySystemIdleTime to getSystemIdleTime (#1043)

This commit is contained in:
Kiran Niranjan 2020-08-04 15:30:11 +05:30 committed by GitHub
parent 913bfb8d5c
commit 0c82066018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,59 +66,58 @@ class MemoryMonitor {
return; return;
} }
(electron.powerMonitor as any).querySystemIdleTime((time) => { const time = electron.powerMonitor.getSystemIdleTime();
const idleTime = time * 1000; const idleTime = time * 1000;
// for MacOS use private else use residentSet // for MacOS use private else use residentSet
const memoryConsumption = isMac ? (this.memoryInfo && this.memoryInfo.private) : (this.memoryInfo && this.memoryInfo.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: 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 in meeting: `, this.isInMeeting);
logger.info(`memory-monitor: Is Network online: `, windowHandler.isOnline); logger.info(`memory-monitor: Is Network online: `, windowHandler.isOnline);
logger.info(`memory-monitor: Memory consumption: `, memoryConsumption); logger.info(`memory-monitor: Memory consumption: `, memoryConsumption);
logger.info(`memory-monitor: Idle Time: `, idleTime); logger.info(`memory-monitor: Idle Time: `, idleTime);
logger.info(`memory-monitor: Last Reload time: `, this.lastReloadTime); logger.info(`memory-monitor: Last Reload time: `, this.lastReloadTime);
if (this.isInMeeting) { if (this.isInMeeting) {
logger.info(`memory-monitor: NOT RELOADING -> User is currently in a meeting. Meeting status from client: `, this.isInMeeting); logger.info(`memory-monitor: NOT RELOADING -> User is currently in a meeting. Meeting status from client: `, this.isInMeeting);
return; return;
} }
if (!windowHandler.isOnline) { if (!windowHandler.isOnline) {
logger.info(`memory-monitor: NOT RELOADING -> Not connected to network. Network status: `, windowHandler.isOnline); logger.info(`memory-monitor: NOT RELOADING -> Not connected to network. Network status: `, windowHandler.isOnline);
return; return;
} }
if (!(memoryConsumption && memoryConsumption > this.memoryThreshold)) { if (!(memoryConsumption && memoryConsumption > this.memoryThreshold)) {
logger.info(`memory-monitor: NOT RELOADING -> Memory consumption ${memoryConsumption} is lesser than the threshold ${this.memoryThreshold}`); logger.info(`memory-monitor: NOT RELOADING -> Memory consumption ${memoryConsumption} is lesser than the threshold ${this.memoryThreshold}`);
return; return;
} }
if (!(idleTime > this.maxIdleTime)) { if (!(idleTime > this.maxIdleTime)) {
logger.info(`memory-monitor: NOT RELOADING -> User is not idle for: `, idleTime); logger.info(`memory-monitor: NOT RELOADING -> User is not idle for: `, idleTime);
return; return;
} }
if (!this.canReload) { if (!this.canReload) {
logger.info(`memory-monitor: NOT RELOADING -> Already refreshed at: `, this.lastReloadTime); logger.info(`memory-monitor: NOT RELOADING -> Already refreshed at: `, this.lastReloadTime);
return; return;
} }
const mainWindow = windowHandler.getMainWindow(); const mainWindow = windowHandler.getMainWindow();
if (!(mainWindow && windowExists(mainWindow))) { if (!(mainWindow && windowExists(mainWindow))) {
logger.info(`memory-monitor: NOT RELOADING -> Main window doesn't exist!`); logger.info(`memory-monitor: NOT RELOADING -> Main window doesn't exist!`);
return; 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); windowHandler.setIsAutoReload(true);
mainWindow.reload(); mainWindow.reload();
this.canReload = false; this.canReload = false;
this.lastReloadTime = new Date().getTime(); this.lastReloadTime = new Date().getTime();
setTimeout(() => { setTimeout(() => {
this.canReload = true; this.canReload = true;
}, this.memoryRefreshThreshold); // prevents multiple reloading of the client within 24hrs }, this.memoryRefreshThreshold); // prevents multiple reloading of the client within 24hrs
});
} }
} }