-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
109 lines (89 loc) · 2.18 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
97
98
99
100
101
102
103
104
105
106
107
108
109
const os = require('os')
const path = require('path')
const osu = require('node-os-utils')
const { app, Menu, ipcMain, Tray } = require('electron')
const log = require('electron-log')
const Store = require('./Store')
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
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 instance
tray = new AppTray(icon, mainWindow)
mainWindow.on('ready', () => (mainWindow=null))
})
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