-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
62 lines (51 loc) · 1.27 KB
/
Copy pathmain.js
File metadata and controls
62 lines (51 loc) · 1.27 KB
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
const { app, BrowserWindow } = require('electron')
const path = require('path')
var connect = require('connect')
var serveStatic = require('serve-static')
const server = connect()
server.use(
'/',
serveStatic(path.join(__dirname, 'dist'), {
index: ['index.html', '/']
})
)
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
webSecurity: false, // forbit CSP
preload: path.join(__dirname, 'preload.js')
}
})
// win.webContents.openDevTools(); // openDevTools
const port = 9526;
server.listen(port, function () {
console.log(`Server is running at http://localhost:${port}`)
setTimeout(() => {
win.loadURL(`http://localhost:${port}`);
}, 500); // delay 500ms to load URL
})
// Close the server when the main window is closed
win.on('closed', function () {
win = null;
server.close();
});
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
process.on('uncaughtException', (error) => {
console.error(error);
});