Skip to content

Commit

Permalink
Additional RAM optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
xanderfrangos committed May 6, 2021
1 parent b910e2b commit 951a71e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const fs = require('fs')
const { nativeTheme, systemPreferences, Menu, Tray, ipcMain, app, screen, globalShortcut, powerMonitor } = require('electron')
const Utils = require("./Utils")

// Expose GC
app.commandLine.appendSwitch('js-flags', '--expose_gc --max-old-space-size=128')
require("v8").setFlagsFromString('--expose_gc'); global.gc = require("vm").runInNewContext('gc');

// Handle multiple instances before continuing
const singleInstanceLock = app.requestSingleInstanceLock()
if (!singleInstanceLock) {
Expand Down Expand Up @@ -1475,7 +1479,8 @@ function createPanel(toggleOnLoad = false) {
backgroundThrottling: false,
spellcheck: false,
enableWebSQL: false,
v8CacheOptions: "none"
v8CacheOptions: "none",
additionalArguments: "--expose_gc"
}
});

Expand Down Expand Up @@ -1504,6 +1509,7 @@ function createPanel(toggleOnLoad = false) {
sendToAllWindows("panelBlur")
showPanel(false)
}
global.gc()
})

mainWindow.on('move', (e) => {
Expand Down Expand Up @@ -1874,10 +1880,11 @@ function createTray() {
tray.on('mouse-move', async () => {
const now = Date.now()
if(lastMouseMove + 500 > now) return false;
lastMouseMove = now
bounds = tray.getBounds()
bounds = screen.dipToScreenRect(null, bounds)
tryEagerUpdate()
lastMouseMove = now
sendToAllWindows('panel-unsleep')
})

nativeTheme.on('updated', async () => {
Expand Down
11 changes: 11 additions & 0 deletions src/panel-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function setPanelVisibility(visible) {
if (window.isAcrylic) {
window.isAcrylic = false
}
setTimeout(() => { if(!window.showPanel && window.sleep) window.thisWindow.setBounds({width:0})}, 1000)
window.dispatchEvent(new CustomEvent('sleepUpdated', {
detail: true
}))
}


Expand Down Expand Up @@ -140,6 +144,7 @@ ipc.on('tray-clicked', () => {
})

ipc.on("panelBlur", (e) => {
global.gc()
// Update browser var to avoid Electron bugs
browser = remote.getCurrentWindow()
if (!browser.webContents.isDevToolsOpened()) {
Expand All @@ -150,6 +155,12 @@ ipc.on("panelBlur", (e) => {
}
})

ipc.on("panel-unsleep", () => {
window.dispatchEvent(new CustomEvent('sleepUpdated', {
detail: false
}))
})

// Monitor info updated
ipc.on("monitors-updated", (e, monitors) => {
if (JSON.stringify(window.allMonitors) === JSON.stringify(monitors)) return false;
Expand Down

0 comments on commit 951a71e

Please sign in to comment.