forked from CyanSalt/todu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.js
63 lines (55 loc) · 1.22 KB
/
window.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
const {app, BrowserWindow, Menu} = require('electron')
const path = require('path')
let frame = null
function init() {
frame = new BrowserWindow({
title: 'TODU',
width: 900,
height: 700,
minWidth: 450,
})
frame.loadURL(`file://${__dirname}/src/index.html`)
frame.on('closed', () => {
frame = null
})
frame.setMenu(createMenu())
frame.setMenuBarVisibility(false)
// this handler must be binded in main process
frame.webContents.session.on('will-download', (e, item, webContents) => {
item.setSavePath(path.resolve(app.getPath('downloads'), item.getFilename()))
})
}
function createMenu() {
return Menu.buildFromTemplate([
{
label: 'Toggle Developer Tools',
accelerator: 'CommandOrControl+Shift+I',
click() {
frame && frame.webContents.openDevTools()
}
}
])
}
const second = app.makeSingleInstance((argv, directory) => {
if (frame) {
if (frame.isMinimized()) {
frame.restore()
}
frame.focus()
}
return true
})
if (second) {
app.quit()
}
app.on('ready', init)
app.on('activate', () => {
if (frame === null) {
init()
}
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})