-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
84 lines (76 loc) · 2.22 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
76
77
78
79
80
81
82
83
84
const path = require('path')
const { app, BrowserWindow } = require('electron')
const isDevelopment = process.env.NODE_ENV === 'DEV'
let mainWindow
let forceQuit = false
const installExtensions = async () => {
console.log('Installing extensions')
const installer = require('electron-devtools-installer')
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS']
const forceDownload = !!process.env.UPGRADE_EXTENSIONS
for (const name of extensions) {
try {
console.log('Installing', name)
await installer.default(installer[name], forceDownload)
} catch (e) {
console.log(`Error installing ${name} extension: ${e.message}`)
}
}
console.log('Installed extensions.')
}
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('ready', async () => {
mainWindow = new BrowserWindow({
width: 1000,
height: 800,
minWidth: 640,
minHeight: 480,
show: false
})
if (isDevelopment) {
await installExtensions()
const chokidar = require('chokidar')
chokidar.watch('./index.js').on('change',
() => {
app.relaunch()
app.exit()
})
mainWindow.loadURL('http://localhost:4567')
} else {
mainWindow.loadFile(path.resolve(path.join(__dirname, './dist/index.html')))
}
// show window once on first load
mainWindow.webContents.once('did-finish-load', () => {
mainWindow.show()
})
mainWindow.webContents.on('did-finish-load', () => {
// Handle window logic properly on macOS:
// 1. App should not terminate if window has been closed
// 2. Click on icon in dock should re-open the window
// 3. ⌘+Q should close the window and quit the app
if (process.platform === 'darwin') {
mainWindow.on('close', function (e) {
if (!forceQuit) {
e.preventDefault()
mainWindow.hide()
}
})
app.on('activate', () => {
mainWindow.show()
})
app.on('before-quit', () => {
forceQuit = true
})
} else {
mainWindow.on('closed', () => {
mainWindow = null
})
}
})
})