-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
96 lines (86 loc) · 2.08 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, BrowserWindow, Menu, ipcMain } = require('electron')
const path = require('path')
const log = require('electron-log')
const Store = require('./Store')
const MainWindow = require('./MainWindow')
const AppTray = require('./AppTray')
// Set env
// process.env.NODE_ENV = 'development'
process.env.NODE_ENV = 'production'
const isDev = process.env.NODE_ENV !== 'production'
const isMac = process.platform === 'darwin'
const isWin = process.platform === 'win32'
let mainWindow
let tray
// init store & defaults
const store = new Store({
configName: 'user-settings',
defaults: {
settings: {
cpuOverload: 80,
alertFrequency: 5
}
}
})
app.on( 'ready',()=>{
const mainMenu = Menu.buildFromTemplate(menu)
Menu.setApplicationMenu(mainMenu)
mainWindow = new MainWindow('./app/index.html',isDev)
mainWindow.webContents.on('dom-ready', ()=>{
mainWindow.webContents.send('settings:get', store.get('settings'))
})
mainWindow.on('close', e =>{
if (!app.isQuitting){
e.preventDefault()
mainWindow.hide()
}
return true
})
const icon = path.join(__dirname, 'assets', 'icons', 'icon.png')
//create tray
tray = new AppTray(icon, mainWindow)
})
const menu = [
// ...(isWin ? [{ 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 (!isWin) {
app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createMainWindow()
}
})
app.allowRendererProcessReuse = true