This repository has been archived by the owner on Sep 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
106 lines (91 loc) · 2.29 KB
/
app.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
97
98
99
100
101
102
103
104
105
106
const {
app,
Menu,
BrowserWindow
} = require('electron')
const { join } = require('path')
const { open } = require('zeelib')
const appUrl = 'http://127.0.0.1:9876'
// reporting crashes to server
// require('crash-reporter').start()
// allows for remote devtools, in the browser (or whatever)
// app.commandLine.appendSwitch('remote-debugging-port', '9191')
// app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1')
// show devtools if we're in dev
// if(process.env.NODE_ENV === 'dev'){
// require('electron-debug')({
// showDevTools: true
// })
// devHelper.setDevMenu()
// }
// basics of a menu
const menuTemplate = [{
label : 'Pharaoh'
, submenu : [{
label : 'Quit'
, accelerator : 'CmdOrCtrl+Q'
, role : 'quit'
, click : () => app.quit()
}]
}, {
label : 'Edit'
, submenu : [{
label : 'Cut'
, accelerator : 'CmdOrCtrl+X'
, role : 'cut'
}, {
label : 'Copy'
, accelerator : 'CmdOrCtrl+C'
, role : 'copy'
}, {
label : 'Paste'
, accelerator : 'CmdOrCtrl+V'
, role : 'paste'
}]
}]
let mainWindow = null
const createWindow = () => {
// load up that menu
Menu.setApplicationMenu(Menu.buildFromTemplate(menuTemplate))
// create the window, with its options
mainWindow = new BrowserWindow({
width : 1200
, height : 800
, 'accept-first-mouse' : true
, 'title-bar-style' : 'hidden'
, 'node-integration' : true
, 'auto-hide-menu-bar' : true
, 'icon' : join(__dirname, 'public', 'images', 'icon.png')
})
// open links externally
mainWindow.webContents.on('will-navigate', (e, url) => {
if (!url.includes(appUrl)) {
e.preventDefault()
open(url)
}
})
mainWindow.webContents.on('new-window', (e, url) => {
if (!url.includes(appUrl)) {
e.preventDefault()
open(url)
}
})
// load our app
mainWindow.loadURL(appUrl)
// open devtools
mainWindow.openDevTools()
// mainWindow.setMenu(null)
mainWindow.on('closed', () => {
mainWindow = null
})
}
app.on('ready', createWindow)
// stuff below is because OS X is fucking weird
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (!mainWindow) createWindow()
})