-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-browser.js
64 lines (60 loc) · 1.38 KB
/
index-browser.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
const path = require('path');
const http = require('http');
const {app, ipcMain, BrowserWindow} = require('electron');
const url = process.argv[2] || ('file://' + path.join(__dirname, 'index.html'));
const _requestAppReady = () => new Promise((accept, reject) => {
app.on('ready', () => {
accept();
});
app.on('error', err => {
reject(err);
});
});
_requestAppReady()
.then(() => {
ipcMain.on('ipc', (event, e) => {
const {method} = e;
switch (method) {
case 'show': {
win.show();
break;
}
case 'hide': {
win.hide();
break;
}
case 'quit': {
process.exit(0);
break;
}
}
});
const win = new BrowserWindow({
width: 1280,
height: 1024,
show: false,
backgroundThrottling: false,
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, 'api.js'),
// webSecurity: false,
},
});
win.loadURL(url);
win.webContents.openDevTools({
mode: 'detach',
});
win.webContents.on('did-fail-load', () => {
process.exit(1);
});
win.webContents.on('crashed', () => {
process.exit(0);
});
win.webContents.on('devtools-closed', () => {
process.exit(0);
});
})
.catch(err => {
console.warn(err.stack);
process.exit(1);
});