Skip to content

Commit 951a71e

Browse files
committed
Additional RAM optimizations
1 parent b910e2b commit 951a71e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/electron.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ const fs = require('fs')
33
const { nativeTheme, systemPreferences, Menu, Tray, ipcMain, app, screen, globalShortcut, powerMonitor } = require('electron')
44
const Utils = require("./Utils")
55

6+
// Expose GC
7+
app.commandLine.appendSwitch('js-flags', '--expose_gc --max-old-space-size=128')
8+
require("v8").setFlagsFromString('--expose_gc'); global.gc = require("vm").runInNewContext('gc');
9+
610
// Handle multiple instances before continuing
711
const singleInstanceLock = app.requestSingleInstanceLock()
812
if (!singleInstanceLock) {
@@ -1475,7 +1479,8 @@ function createPanel(toggleOnLoad = false) {
14751479
backgroundThrottling: false,
14761480
spellcheck: false,
14771481
enableWebSQL: false,
1478-
v8CacheOptions: "none"
1482+
v8CacheOptions: "none",
1483+
additionalArguments: "--expose_gc"
14791484
}
14801485
});
14811486

@@ -1504,6 +1509,7 @@ function createPanel(toggleOnLoad = false) {
15041509
sendToAllWindows("panelBlur")
15051510
showPanel(false)
15061511
}
1512+
global.gc()
15071513
})
15081514

15091515
mainWindow.on('move', (e) => {
@@ -1874,10 +1880,11 @@ function createTray() {
18741880
tray.on('mouse-move', async () => {
18751881
const now = Date.now()
18761882
if(lastMouseMove + 500 > now) return false;
1883+
lastMouseMove = now
18771884
bounds = tray.getBounds()
18781885
bounds = screen.dipToScreenRect(null, bounds)
18791886
tryEagerUpdate()
1880-
lastMouseMove = now
1887+
sendToAllWindows('panel-unsleep')
18811888
})
18821889

18831890
nativeTheme.on('updated', async () => {

src/panel-preload.js

+11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function setPanelVisibility(visible) {
3131
if (window.isAcrylic) {
3232
window.isAcrylic = false
3333
}
34+
setTimeout(() => { if(!window.showPanel && window.sleep) window.thisWindow.setBounds({width:0})}, 1000)
35+
window.dispatchEvent(new CustomEvent('sleepUpdated', {
36+
detail: true
37+
}))
3438
}
3539

3640

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

142146
ipc.on("panelBlur", (e) => {
147+
global.gc()
143148
// Update browser var to avoid Electron bugs
144149
browser = remote.getCurrentWindow()
145150
if (!browser.webContents.isDevToolsOpened()) {
@@ -150,6 +155,12 @@ ipc.on("panelBlur", (e) => {
150155
}
151156
})
152157

158+
ipc.on("panel-unsleep", () => {
159+
window.dispatchEvent(new CustomEvent('sleepUpdated', {
160+
detail: false
161+
}))
162+
})
163+
153164
// Monitor info updated
154165
ipc.on("monitors-updated", (e, monitors) => {
155166
if (JSON.stringify(window.allMonitors) === JSON.stringify(monitors)) return false;

0 commit comments

Comments
 (0)