From 7ced97ce5a43ef39f0483e66d2231a79a2dd2422 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Wed, 28 Nov 2018 21:38:19 +0530 Subject: [PATCH] [R53] ELECTRON-879 (Bump Electron version to 4.0.0-beta.7) (#528) * ELECTRON-879 - Fix memory refresh and upgrade electron to 4.x.x * ELECTRON-879 - Remove files from aip electron 3.x.x * ELECTRON-879 - Add supporting (dll) files --- installer/win/Symphony-x64.aip | 126 +++++++-------------------------- installer/win/Symphony-x86.aip | 126 +++++++-------------------------- js/main.js | 39 +++++----- js/mainApiMgr.js | 8 +-- js/memoryMonitor.js | 29 +++----- js/preload/preloadMain.js | 2 - package.json | 4 +- 7 files changed, 87 insertions(+), 247 deletions(-) diff --git a/installer/win/Symphony-x64.aip b/installer/win/Symphony-x64.aip index 1ef1884d..0ed65986 100644 --- a/installer/win/Symphony-x64.aip +++ b/installer/win/Symphony-x64.aip @@ -107,52 +107,18 @@ + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -163,17 +129,14 @@ - - + - - - + @@ -183,65 +146,30 @@ - + - + - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - @@ -254,8 +182,7 @@ - - + @@ -285,19 +212,20 @@ - - + - + + + @@ -308,13 +236,9 @@ - - - - diff --git a/installer/win/Symphony-x86.aip b/installer/win/Symphony-x86.aip index b98808bc..98aadb53 100644 --- a/installer/win/Symphony-x86.aip +++ b/installer/win/Symphony-x86.aip @@ -106,52 +106,18 @@ + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -162,16 +128,13 @@ - - + - - - + @@ -180,66 +143,31 @@ - + - + - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - @@ -252,8 +180,7 @@ - - + @@ -283,19 +210,20 @@ - - + - + + + @@ -306,13 +234,9 @@ - - - - diff --git a/js/main.js b/js/main.js index 34efca59..e6a9a1e2 100644 --- a/js/main.js +++ b/js/main.js @@ -73,25 +73,30 @@ function initializeCrashReporter(podUrl) { } -// only allow a single instance of app. -const shouldQuit = app.makeSingleInstance((argv) => { - // Someone tried to run a second instance, we should focus our window. - let mainWin = windowMgr.getMainWindow(); - if (mainWin) { - isAppAlreadyOpen = true; - if (mainWin.isMinimized()) { - mainWin.restore(); - } - mainWin.focus(); - } - processProtocolAction(argv); -}); - let allowMultiInstance = getCmdLineArg(process.argv, '--multiInstance', true) || isDevEnv; -// quit if another instance is already running, ignore for dev env or if app was started with multiInstance flag -if (!allowMultiInstance && shouldQuit) { - app.quit(); +if (!allowMultiInstance) { + const gotTheLock = app.requestSingleInstanceLock(); + + // quit if another instance is already running, ignore for dev env or if app was started with multiInstance flag + if (!gotTheLock) { + app.quit() + } else { + app.on('second-instance', (event, argv) => { + // Someone tried to run a second instance, we should focus our window. + let mainWin = windowMgr.getMainWindow(); + if (mainWin) { + isAppAlreadyOpen = true; + if (mainWin.isMinimized()) { + mainWin.restore(); + } + mainWin.focus(); + } + processProtocolAction(argv); + }); + } +} else { + app.releaseSingleInstanceLock(); } /** diff --git a/js/mainApiMgr.js b/js/mainApiMgr.js index b5811846..bd71c601 100644 --- a/js/mainApiMgr.js +++ b/js/mainApiMgr.js @@ -152,11 +152,9 @@ electron.ipcMain.on(apiName, (event, arg) => { break; } case apiCmds.optimizeMemoryConsumption: - if (typeof arg.memory === 'object' - && typeof arg.memory.workingSetSize === 'number' - && typeof arg.activeRequests === 'number') { - log.send(logLevels.INFO, 'Received memory info from renderer'); - setPreloadMemoryInfo(arg.memory, arg.activeRequests); + if (typeof arg.activeRequests === 'number') { + log.send(logLevels.INFO, 'Received active network request from renderer processes'); + setPreloadMemoryInfo(arg.activeRequests); } break; case apiCmds.optimizeMemoryRegister: diff --git a/js/memoryMonitor.js b/js/memoryMonitor.js index 878e5c44..1dd49697 100644 --- a/js/memoryMonitor.js +++ b/js/memoryMonitor.js @@ -1,5 +1,5 @@ 'use strict'; - +const { app } = require('electron'); const systemIdleTime = require('@paulcbetts/system-idle-time'); const log = require('./log.js'); @@ -7,7 +7,6 @@ const logLevels = require('./enums/logLevels.js'); const { getMainWindow, setIsAutoReload, getIsOnline } = require('./windowMgr'); const { getConfigField } = require('./config'); -const maxMemory = 800; const memoryRefreshThreshold = 60 * 60 * 1000; const maxIdleTime = 4 * 60 * 60 * 1000; const memoryRefreshInterval = 60 * 60 * 1000; @@ -25,13 +24,8 @@ setInterval(gatherMemory, 1000 * 60); * Gathers system memory and logs it to the remote system */ function gatherMemory() { - let memory = process.getProcessMemoryInfo(); - let details = - 'workingSetSize: ' + memory.workingSetSize + - ' peakWorkingSetSize: ' + memory.peakWorkingSetSize + - ' privatesBytes: ' + memory.privatesBytes + - ' sharedBytes: ' + memory.sharedBytes; - log.send(logLevels.INFO, details); + let appMetrics = app.getAppMetrics(); + log.send(logLevels.INFO, appMetrics); } /** @@ -41,17 +35,15 @@ function gatherMemory() { */ function optimizeMemory() { - if (!preloadMemory || !preloadMemory.memoryInfo || !preloadMemory.cpuUsage) { - log.send(logLevels.INFO, `Memory info not available`); + if (!preloadMemory.cpuUsage) { + log.send(logLevels.INFO, `cpu usage not available`); return; } - const memoryConsumed = (preloadMemory.memoryInfo && preloadMemory.memoryInfo.workingSetSize / 1024) || 0; const cpuUsagePercentage = preloadMemory.cpuUsage.percentCPUUsage; const activeNetworkRequest = preloadMemory.activeRequests === 0; - if (memoryConsumed > maxMemory - && cpuUsagePercentage <= cpuUsageThreshold + if (cpuUsagePercentage <= cpuUsageThreshold && !isInMeeting && getIsOnline() && canReload @@ -66,7 +58,7 @@ function optimizeMemory() { if (mainWindow && !mainWindow.isDestroyed()) { setIsAutoReload(true); log.send(logLevels.INFO, `Reloading the app to optimize memory usage as - memory consumption was ${memoryConsumed} + memory consumption is no longer detectable CPU usage percentage was ${preloadMemory.cpuUsage.percentCPUUsage} user was in a meeting? ${isInMeeting} pending network request on the client was ${preloadMemory.activeRequests} @@ -86,7 +78,7 @@ function optimizeMemory() { } else { log.send(logLevels.INFO, `Not Reloading the app as application was refreshed less than a hour ago? ${canReload ? 'no' : 'yes'} - memory consumption was ${memoryConsumed} + memory consumption is no longer detectable CPU usage percentage was ${preloadMemory.cpuUsage.percentCPUUsage} user was in a meeting? ${isInMeeting} pending network request on the client was ${preloadMemory.activeRequests} @@ -105,13 +97,12 @@ function setIsInMeeting(meetingStatus) { /** * Sets preload memory info and calls optimize memory func * - * @param memoryInfo - memory consumption of the preload main script * @param activeRequests - pending active network requests on the client */ -function setPreloadMemoryInfo(memoryInfo, activeRequests) { +function setPreloadMemoryInfo(activeRequests) { log.send(logLevels.INFO, 'Memory info received from preload process now running optimize memory logic'); const cpuUsage = process.getCPUUsage(); - preloadMemory = { memoryInfo, cpuUsage, activeRequests }; + preloadMemory = { cpuUsage, activeRequests }; optimizeMemory(); } diff --git a/js/preload/preloadMain.js b/js/preload/preloadMain.js index d20a7b83..1534e12a 100644 --- a/js/preload/preloadMain.js +++ b/js/preload/preloadMain.js @@ -504,11 +504,9 @@ function createAPI() { local.ipcRenderer.on('memory-info-request', () => { if (window.name === 'main') { - const memory = process.getProcessMemoryInfo(); const activeRequests = typeof local.activeRequests === 'function' ? local.activeRequests() : 0; local.ipcRenderer.send(apiName, { cmd: apiCmds.optimizeMemoryConsumption, - memory, activeRequests, }); } diff --git a/package.json b/package.json index 48d5617e..20c21da4 100644 --- a/package.json +++ b/package.json @@ -86,8 +86,8 @@ "browserify": "16.2.3", "chromedriver": "2.42.0", "cross-env": "5.2.0", - "electron": "3.0.9", - "electron-builder": "20.28.4", + "electron": "4.0.0-beta.7", + "electron-builder": "20.38.0", "electron-builder-squirrel-windows": "12.3.0", "electron-chromedriver": "3.0.0-beta.1", "electron-packager": "12.1.0",