This repository has been archived by the owner on Jun 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (71 loc) · 1.96 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
71
72
73
74
75
const electron = require('electron')
const app = electron.app
const Menu = electron.Menu
const menuTemplate = [
{
label: 'The Hidden Button',
submenu: [
{
label: 'New Window',
accelerator: process.platform === 'darwin' ? 'Command+N' : 'Ctrl+N',
click (item, focusedWindow) {
createMainWindow()
}
},
{
label: 'Change Window URL',
accelerator: 'F5',
click (item, focusedWindow) {
focusedWindow.reload()
}
},
{
label: 'Pin Window (Always on Top)',
accelerator: process.platform === 'darwin' ? 'Command+P' : 'Ctrl+P',
click (item, focusedWindow) {
focusedWindow.isAlwaysOnTop() ? focusedWindow.setAlwaysOnTop(false) : focusedWindow.setAlwaysOnTop(true)
}
},
{
label: 'Previous',
accelerator: 'Backspace',
click (item, focusedWindow) {
focusedWindow.webContents.history.length - 2 >= 0 ? focusedWindow.loadURL(focusedWindow.webContents.history[focusedWindow.webContents.history.length - 2]) : null
}
},
{
label: 'Toggle Developer Tools',
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click (item, focusedWindow) {
focusedWindow ? focusedWindow.toggleDevTools() : null
}
}
]
}
]
const menu = Menu.buildFromTemplate(menuTemplate)
let mainWindow = Array, counter = 0
app.on('ready', () => {
createMainWindow()
})
app.on('activate', () => {
if (mainWindow.length < 1) {
createMainWindow()
}
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
function createMainWindow() {
mainWindow[counter] = new electron.BrowserWindow({
autoHideMenuBar: true
})
mainWindow[counter].setMenu(menu)
mainWindow[counter].loadFile('./src/index.html')
mainWindow[counter].on('close', () => {
mainWindow[counter] = null
})
counter++
}