-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
70 lines (58 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let windowStateKeeper;
let mainWindowState;
// Lazy load window state singleton
function init({ app, screen, remote }) {
if (!windowStateKeeper) {
windowStateKeeper = require("./electron-window-state");
}
if (!mainWindowState) {
mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 600,
resetToCenter: true
}, app || remote.app, screen || remote.screen);
}
}
function getElectron() {
const electron = require('electron');
return electron;
}
function getRemote() {
// "remote" module was deprecated in Electron 12, and will be removed in Electron 14
// https://www.electronjs.org/docs/latest/breaking-changes#removed-remote-module
const { app: remoteApp, screen: remoteScreen } = require('@electron/remote');
return {
app: remoteApp,
screen: remoteScreen
};
}
// Apply window state and monitor changes
exports.onWindow = (win) => {
const electron = getElectron();
init(electron);
if ((mainWindowState.x !== undefined) && (mainWindowState.y !== undefined)) {
win.setBounds({
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height
});
}
mainWindowState.manage(win);
};
// Render maximize/restore button correctly
exports.reduceUI = (state, action) => {
const electron = getElectron();
// renderer requires remote module
if (electron.remote == null) {
electron.remote = getRemote();
}
switch (action.type) {
case "CONFIG_LOAD":
case "CONFIG_RELOAD": {
init(electron);
return state.set("maximized", mainWindowState.isMaximized);
}
}
return state;
};