-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (46 loc) · 1.42 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
// Basic stuff picked up from https://github.com/electron-userland/electron-webpack-quick-start
const { app, BrowserWindow } = require('electron');
const Url = require('url');
const path = require('path');
// we just assume if the arguments exist it's run in a dev mode
const envDev = process.argv[2];
// global reference to mainWindow (necessary to prevent window from being garbage collected)
let mainWindow;
function createMainWindow() {
window = new BrowserWindow({
width: 800,
height: 242,
resizable: !!envDev,
maximizable: false,
icon: path.join(__dirname, 'app', 'assets', 'images', 'icon.png')
});
if (envDev) {
window.webContents.openDevTools();
}
window.loadURL(Url.format({
pathname: path.join(__dirname, 'dist', 'index.html'),
protocol: 'file',
slashes: true
}));
window.on('closed', () => {
mainWindow = null;
});
return window;
}
// quit application when all windows are closed
app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) {
mainWindow = createMainWindow();
}
});
// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow();
});