-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
73 lines (57 loc) · 1.58 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
const { app, BrowserWindow } = require('electron')
const chalk = require('chalk')
function isDevelopment() {
return process.env.NODE_ENV === 'development'
}
const APP_NAME = isDevelopment() ? 'React example (development)' : 'React example'
let win
function onReady() {
if (isDevelopment()) {
installDevExtensions()
}
createWindow()
}
function installDevExtensions() {
const installExtension = require('electron-devtools-installer').default
const REACT_DEVELOPER_TOOLS = require('electron-devtools-installer').REACT_DEVELOPER_TOOLS
console.log(chalk.blue(`Installing DevTools extensions...`));
return new Promise((resolve, reject) => {
installExtension(REACT_DEVELOPER_TOOLS)
.then((name) => {
console.log(`${chalk.green(`✓`)} ${name}`)
console.log()
resolve()
})
.catch((err) => {
console.log(chalk.red(`An error occurred: ${err}`))
console.log()
reject()
})
})
}
function createWindow () {
win = new BrowserWindow({title: APP_NAME})
win.maximize()
if (isDevelopment()) {
win.loadURL(`http://localhost:${process.env.PORT || 3000}/`)
} else {
// Load prod build
win.loadURL(`file://${__dirname}/build/index.html`)
}
// Do not update window title after loading pages
win.on('page-title-updated', (event) => event.preventDefault())
win.on('closed', () => {
win = null
})
}
app.on('ready', onReady)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (win === null) {
createWindow()
}
})