-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
84 lines (76 loc) · 1.7 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
const { app, BrowserWindow, Menu, ipcMain } = require('electron')
const path = require('path')
let win
function createWindow() {
let options = {
width: 775,
height: 650,
minWidth: 300,
minHeight: 90,
frame: false,
icon: './public/Nevis Logo.png',
show: false,
webPreferences: {
nodeIntegration: true,
},
}
let pathname = ''
if (process.env.NODE_ENV === 'development')
pathname = 'http://localhost:8080/'
else pathname = `file://${path.join(__dirname, '/dist/index.html')}`
win = new BrowserWindow(options)
win.loadURL(pathname)
win.on('ready-to-show', () => {
win.show()
win.webContents.send('resize', win.getSize())
win.focus()
})
win.on('closed', () => {
win = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
app.quit()
})
app.on('activate', () => {
if (win === null) {
createWindow()
}
})
// Context Menu
const contextMenu = [
{
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
role: 'copy',
},
{
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
role: 'cut',
},
{
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
role: 'paste',
},
]
const ContextMenu = Menu.buildFromTemplate(contextMenu)
app.on('browser-window-created', function (event, win) {
win.webContents.on('context-menu', function (e, params) {
ContextMenu.popup(win, params.x, params.y)
})
})
// Menu Titlebar Icon
let maximized = false
ipcMain.on('window', function (event, arg) {
if (arg === 'maximize') {
if (maximized === false) win.maximize()
else win.unmaximize()
maximized = !maximized
event.sender.send('window', maximized)
} else if (arg === 'minimize') {
win.minimize()
}
})