Skip to content

Commit

Permalink
fix: Should not call window api after it's closed
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jul 12, 2024
1 parent ef4215c commit 3cc8b66
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xmcl-electron-app/main/utils/windowSizeTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function createWindowTracker(app: LauncherApp, role: string, man: Install
}
async function track(browserWindow: BrowserWindow) {
const update = () => {
if (browserWindow.isDestroyed()) return
if (browserWindow.isMaximized()) return
const [width, height] = browserWindow.getSize()
const [x, y] = browserWindow.getPosition()
Expand All @@ -60,6 +61,7 @@ export function createWindowTracker(app: LauncherApp, role: string, man: Install
writeToFile()
}
const updateViaMaximized = () => {
if (browserWindow.isDestroyed()) return
config.maximized = browserWindow.isMaximized()
writeToFile()
}
Expand All @@ -72,6 +74,13 @@ export function createWindowTracker(app: LauncherApp, role: string, man: Install
browserWindow.on('maximize', updateViaMaximized)
browserWindow.on('unmaximize', updateViaMaximized)
browserWindow.on('will-move', update)
browserWindow.on('closed', () => {
browserWindow.removeListener('resize', update)
browserWindow.removeListener('moved', update)
browserWindow.removeListener('move', update)
browserWindow.removeListener('will-move', update)
browserWindow.removeListener('closed', update)
})
}
return {
getConfig,
Expand Down

0 comments on commit 3cc8b66

Please sign in to comment.