This repository has been archived by the owner on Jun 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.js
93 lines (76 loc) · 2.22 KB
/
main.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
const { app, BrowserWindow } = require('electron')
const initMain = require('./app/main')
// import MenuBuilder from './menu'
let mainWindow = null
// if (process.env.NODE_ENV === 'production') {
// const sourceMapSupport = require('source-map-support')
// sourceMapSupport.install()
// }
if (
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
) {
require('electron-debug')()
// const path = require('path')
// const p = path.join(__dirname, '..', 'app', 'node_modules')
// require('module').globalPaths.push(p)
}
const installExtensions = async () => {
const installer = require('electron-devtools-installer')
const forceDownload = !!process.env.UPGRADE_EXTENSIONS
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS']
return Promise.all(
extensions.map(name => installer.default(installer[name], forceDownload))
).catch(console.log)
}
/**
* Add event listeners...
*/
app.on('window-all-closed', () => {
// Respect the OSX convention of having the application in memory even
// after all windows have been closed
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('ready', async () => {
initMain()
if (
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
) {
await installExtensions()
}
mainWindow = new BrowserWindow({
show: false,
width: 1200,
height: 728,
minWidth: 1200,
minHeight: 728,
titleBarStyle: 'hiddenInset',
movable: true
})
mainWindow.loadURL(`file://${__dirname}/app/renderer/index.html`)
// @TODO: Use 'ready-to-show' event
// https://github.com/electron/electron/blob/master/docs/api/browser-window.md#using-ready-to-show-event
mainWindow.webContents.on('did-finish-load', () => {
if (!mainWindow) {
throw new Error('"mainWindow" is not defined')
}
mainWindow.show()
mainWindow.focus()
})
mainWindow.on('show', event => {
if (process.env.NODE_ENV === 'development')
mainWindow.webContents.openDevTools()
})
mainWindow.on('close', () => {
mainWindow.webContents.closeDevTools()
})
mainWindow.on('closed', () => {
mainWindow = null
})
// const menuBuilder = new MenuBuilder(mainWindow)
// menuBuilder.buildMenu()
})
app.commandLine.appendSwitch('ignore-certificate-errors', 'true');