-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
48 lines (37 loc) · 1.35 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
'use strict'
const electron = require('electron')
const chokidar = require('chokidar') // add chokidar
const app = electron.app // this is our app
const BrowserWindow = electron.BrowserWindow // This is a Module that creates windows
let mainWindow // saves a global reference to mainWindow so it doesn't get garbage collected
app.on('ready', createWindow) // called when electron has initialized
// tell chokidar to watch these files for changes
// reload the window if there is one
chokidar.watch(['ports.js', 'index.html', 'elm.js']).on('change', () => {
if (mainWindow) {
mainWindow.reload()
}
})
// This will create our app window, no surprise there
function createWindow () {
mainWindow = new BrowserWindow({
width: 1024,
height: 768
})
// display the index.html file
mainWindow.loadURL(`file://${ __dirname }/index.html`)
// open dev tools by default so we can see any console errors
mainWindow.webContents.openDevTools()
mainWindow.on('closed', function () {
mainWindow = null
})
}
/* Mac Specific things */
// when you close all the windows on a non-mac OS it quits the app
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') { app.quit() }
})
// if there is no mainWindow it creates one (like when you click the dock icon)
app.on('activate', () => {
if (mainWindow === null) { createWindow() }
})