Main: Remove 'openedWindows' variable
Electron already has a built-in tracker for all opened windows, so it makes no sense to have custom code to handle it. One should always use what is given to you :^)
This commit is contained in:
parent
40d7278383
commit
718f9450d6
|
@ -33,7 +33,6 @@ function runApp() {
|
|||
const isDev = process.env.NODE_ENV === 'development'
|
||||
const isDebug = process.argv.includes('--debug')
|
||||
let mainWindow
|
||||
let openedWindows = []
|
||||
let startupUrl
|
||||
|
||||
// CORS somehow gets re-enabled in Electron v9.0.4
|
||||
|
@ -198,7 +197,7 @@ function runApp() {
|
|||
},
|
||||
show: false
|
||||
})
|
||||
openedWindows.push(newWindow)
|
||||
|
||||
if (replaceMainWindow) {
|
||||
mainWindow = newWindow
|
||||
}
|
||||
|
@ -253,13 +252,12 @@ function runApp() {
|
|||
newWindow.focus()
|
||||
})
|
||||
|
||||
newWindow.on('closed', () => {
|
||||
// Remove closed window
|
||||
openedWindows = openedWindows.filter((window) => window !== newWindow)
|
||||
if (newWindow === mainWindow) {
|
||||
newWindow.once('closed', () => {
|
||||
const allWindows = BrowserWindow.getAllWindows()
|
||||
if (allWindows.length !== 0 && newWindow === mainWindow) {
|
||||
// Replace mainWindow to avoid accessing `mainWindow.webContents`
|
||||
// Which raises "Object has been destroyed" error
|
||||
mainWindow = openedWindows[0]
|
||||
mainWindow = allWindows[0]
|
||||
}
|
||||
|
||||
console.log('closed')
|
||||
|
@ -368,9 +366,11 @@ function runApp() {
|
|||
})
|
||||
|
||||
ipcMain.on('syncWindows', (event, payload) => {
|
||||
const otherWindows = openedWindows.filter((window) => {
|
||||
const otherWindows = BrowserWindow.getAllWindows().filter(
|
||||
(window) => {
|
||||
return window.webContents.id !== event.sender.id
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
for (const window of otherWindows) {
|
||||
window.webContents.send('syncWindows', payload)
|
||||
|
|
Loading…
Reference in New Issue