Skip to content

Commit 5131b36

Browse files
committed
[update] support multiple windows
1 parent cee99f5 commit 5131b36

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

main/index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ const startServer = require('./server')
66
const setMenu = require('./menu')
77
const setIPCEvents = require('./ipc-events')
88

9-
let win
9+
const windows = []
1010

1111
async function createWindow() {
12+
let win
1213
let server
14+
1315
try {
1416
// when starting the window run the server
1517
server = await startServer()
@@ -32,6 +34,8 @@ async function createWindow() {
3234
},
3335
})
3436

37+
windows.push(win)
38+
3539
// open our server URL or the build directory in production
3640
win.loadURL(dev ? 'http://localhost:8000' : `file://${resolve('./build')}/index.html`)
3741

@@ -46,6 +50,8 @@ async function createWindow() {
4650

4751
win.on('close', () => {
4852
win = null
53+
const position = windows.indexOf(win)
54+
windows.splice(position, 1)
4955
if (server) server.close()
5056
})
5157

@@ -68,7 +74,7 @@ app.on('window-all-closed', () => {
6874
})
6975

7076
app.on('activate', () => {
71-
if (win === null) {
77+
if (windows.length === 0) {
7278
createWindow()
7379
}
7480
})

0 commit comments

Comments
 (0)