-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
96 lines (82 loc) · 2.21 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const { app, Menu, ipcMain } = require("electron");
const Store = require("./Store");
const path = require("path");
const MainWindow = require("./MainWindow");
const AppTray = require("./AppTray");
// Set env
process.env.NODE_ENV = "production";
const isDev = process.env.NODE_ENV !== "production" ? true : false;
const isMac = process.platform === "darwin" ? true : false;
let mainWindow;
let tray;
//Init Store && defalts
const store = new Store({
configName: "user-settings",
defaults: {
settings: {
cpuOverload: 80,
alertFrequency: 5,
},
},
});
function createMainWindow() {
mainWindow = new MainWindow("./app/index.html", isDev);
}
app.on("ready", () => {
createMainWindow();
mainWindow.webContents.on("dom-ready", () => {
mainWindow.webContents.send("settings:get", store.get("settings"));
});
const mainMenu = Menu.buildFromTemplate(menu);
Menu.setApplicationMenu(mainMenu);
mainWindow.on("close", (e) => {
if (!app.isQuitting) {
e.preventDefault();
mainWindow.hide();
}
return true;
});
const icon = path.join(__dirname, "assets", "icons", "tray_icon.png");
//create tray
tray = new AppTray(icon, mainWindow);
});
const menu = [
...(isMac ? [{ role: "appMenu" }] : []),
{
role: "fileMenu",
},
{
label: "View",
submenu: [{
label: "Toggle Navigation",
click: () => mainWindow.webContents.send("nav:toggle"),
}, ],
},
...(isDev ?
[{
label: "Developer",
submenu: [
{ role: "reload" },
{ role: "forcereload" },
{ type: "separator" },
{ role: "toggledevtools" },
],
}, ] :
[]),
];
//Set settings
ipcMain.on("settings:set", (e, value) => {
store.set("settings", value);
mainWindow.webContents.send("settings:get", store.get("settings"));
});
app.on("window-all-closed", () => {
if (!isMac) {
app.quit();
}
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createMainWindow();
}
});
app.allowRendererProcessReuse = true;