-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathmain.js
More file actions
104 lines (89 loc) · 2.16 KB
/
main.js
File metadata and controls
104 lines (89 loc) · 2.16 KB
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
const { app, BrowserWindow, Menu, shell } = require('electron')
const path = require('path')
const url = require('url')
const { ipcMain, dialog } = require('electron');
ipcMain.on('dialog:openFile', (event, options) => {
event.returnValue = dialog.showOpenDialogSync(options) || null;
});
ipcMain.on('dialog:saveFile', (event, options) => {
event.returnValue = dialog.showSaveDialogSync(options) || null;
});
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
let win
function createWindow () {
win = new BrowserWindow({
width: 1000,
height: 700,
icon: path.join(__dirname, 'assets/images/app-icon.png'),
webPreferences: {
enableRemoteModule: true,
preload: path.join(__dirname, 'handlers.js'),
contextIsolation: false
}
})
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
win.webContents.on('new-window', (e, url) => {
e.preventDefault()
shell.openExternal(url)
})
win.on('closed', () => win = null)
setupMenu()
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (win === null) {
createWindow()
}
})
function setupMenu () {
const menus = []
if (process.platform === 'darwin') {
menus.push({
label: 'Application',
submenu: [
{ role: 'quit' }
]
})
menus.push({
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'selectall' }
]
})
}
if (process.env.NODE_ENV === 'development') {
menus.push({
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: () => win.reload()
},
{
label: 'Toggle Developer Tools',
accelerator: 'Alt+Command+I',
click: () => win.toggleDevTools()
},
]
})
}
if (menus.length > 0) {
Menu.setApplicationMenu(Menu.buildFromTemplate(menus))
}
}