ELECTRON-870 - Revert back to old memory refresh logic

This commit is contained in:
Kiran Niranjan 2018-10-25 14:43:22 +05:30 committed by José Alves Durand Neto
parent 4737a9135f
commit 2871cb5c90
3 changed files with 11 additions and 76 deletions

View File

@ -9,7 +9,6 @@ const shellPath = require('shell-path');
const urlParser = require('url');
const nodePath = require('path');
const compareSemVersions = require('./utils/compareSemVersions.js');
const eventEmitter = require('./eventEmitter');
// Local Dependencies
const {
@ -195,15 +194,6 @@ app.on('ready', () => {
});
function initiateApp() {
electron.powerMonitor.on('lock-screen', () => {
eventEmitter.emit('sys-locked');
});
electron.powerMonitor.on('unlock-screen', () => {
eventEmitter.emit('sys-unlocked');
});
checkFirstTimeLaunch()
.then(readConfigThenOpenMainWindow)
.catch(readConfigThenOpenMainWindow);

View File

@ -1,6 +1,6 @@
'use strict';
const eventEmitter = require('./eventEmitter');
const systemIdleTime = require('@paulcbetts/system-idle-time');
const log = require('./log.js');
const logLevels = require('./enums/logLevels.js');
@ -8,15 +8,13 @@ const { getMainWindow, setIsAutoReload, getIsOnline } = require('./windowMgr');
const { getConfigField } = require('./config');
const maxMemory = 800;
const defaultInterval = 30 * 1000;
const defaultIntervalSymLock = 10 * 1000;
const memoryRefreshThreshold = 60 * 60 * 1000;
const maxIdleTime = 4 * 60 * 60 * 1000;
const memoryRefreshInterval = 1000;
const cpuUsageThreshold = 5;
let isInMeeting = false;
let canReload = true;
let appMinimizedTimer;
let powerMonitorTimer;
let preloadMemory;
let preloadWindow;
@ -57,6 +55,7 @@ function optimizeMemory() {
&& !isInMeeting
&& getIsOnline()
&& canReload
&& systemIdleTime.getIdleTime() > maxIdleTime
&& activeNetworkRequest
) {
getConfigField('memoryRefresh')
@ -116,61 +115,6 @@ function setPreloadMemoryInfo(memoryInfo, activeRequests) {
optimizeMemory();
}
/**
* Called whenever the application is minimized
* and waits for 30s to optimize memory
*/
eventEmitter.on('appMinimized', () => {
log.send(logLevels.INFO, 'Application was minimised');
appMinimizedTimer = setTimeout(() => {
const mainWindow = getMainWindow();
if (mainWindow && !mainWindow.isDestroyed() && mainWindow.isMinimized()) {
log.send(logLevels.INFO, 'Application is minimised for more than 30s so calling requestMemoryInfo');
requestMemoryInfo();
}
}, defaultInterval);
});
/**
* Called whenever the application is restored from minimized state
*
* Clears appMinimizedTimer if the app is restored within 30s
* from minimized state
*/
eventEmitter.on('appRestored', () => {
log.send(logLevels.INFO, 'Application was restored from minimized state');
setIsAutoReload(false);
if (appMinimizedTimer) {
clearTimeout(appMinimizedTimer);
}
});
/**
* Called whenever the system in locked
* and waits for 30s to optimize memory
*/
eventEmitter.on('sys-locked', () => {
log.send(logLevels.INFO, 'System screen was locked');
powerMonitorTimer = setTimeout(() => {
log.send(logLevels.INFO, 'System screen was locked for more than 30s so calling requestMemoryInfo');
requestMemoryInfo();
}, defaultIntervalSymLock);
});
/**
* Called whenever the system in locked
*
* Clears powerMonitorTimer if the system is unlocked within 30s
* from locked state
*/
eventEmitter.on('sys-unlocked', () => {
log.send(logLevels.INFO, 'System screen was unlocked');
setIsAutoReload(false);
if (powerMonitorTimer) {
clearTimeout(powerMonitorTimer);
}
});
/**
* Sets the preload window
*
@ -192,6 +136,13 @@ function requestMemoryInfo() {
}
}
/**
* Requests memory info from the renderer every 4 hrs
*/
setInterval(() => {
requestMemoryInfo();
}, memoryRefreshInterval);
module.exports = {
setIsInMeeting,
setPreloadMemoryInfo,

View File

@ -214,12 +214,6 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) {
// event sent to renderer process to remove snack bar
mainWindow.webContents.send('window-leave-full-screen');
});
mainWindow.on('minimize', () => {
eventEmitter.emit('appMinimized');
});
mainWindow.on('restore', () => {
eventEmitter.emit('appRestored');
});
if (initialBounds) {
// maximizes the application if previously maximized