Skip to content

Commit 7563bb1

Browse files
fix: Can't delete file after restoring window on macOS (#722)
1 parent b818b0c commit 7563bb1

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/main.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
stopProxyProcess,
1717
} from './main/proxy'
1818
import { getSettings, initSettings } from './main/settings'
19-
import { configureWatcher } from './main/watcher'
19+
import { closeWatcher, configureWatcher } from './main/watcher'
2020
import { showWindow, trackWindowState } from './main/window'
2121
import { BrowserServer } from './services/browser/server'
2222
import { ProxyStatus } from './types'
@@ -193,10 +193,13 @@ app.whenReady().then(
193193
// Quit when all windows are closed, except on macOS. There, it's common
194194
// for applications and their menu bar to stay active until the user quits
195195
// explicitly with Cmd + Q.
196-
app.on('window-all-closed', () => {
196+
app.on('window-all-closed', async () => {
197197
if (process.platform !== 'darwin') {
198198
app.quit()
199+
return
199200
}
201+
202+
await closeWatcher()
200203
})
201204

202205
app.on('activate', async () => {
@@ -209,10 +212,7 @@ app.on('activate', async () => {
209212
})
210213

211214
app.on('before-quit', async () => {
212-
// stop watching files to avoid crash on exit
213215
k6StudioState.appShuttingDown = true
214-
if (k6StudioState.watcher) {
215-
await k6StudioState.watcher.close()
216-
}
216+
await closeWatcher()
217217
return stopProxyProcess()
218218
})

src/main/watcher.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ export function configureWatcher(browserWindow: BrowserWindow) {
4040
browserWindow.webContents.send(UIHandler.REMOVE_FILE, file)
4141
})
4242
}
43+
44+
export async function closeWatcher() {
45+
// stop watching files to avoid crash on exit
46+
if (k6StudioState.watcher) {
47+
await k6StudioState.watcher.close()
48+
}
49+
}

0 commit comments

Comments
 (0)