Skip to content

Commit 0f2e4c6

Browse files
authored
fix: quit confirmation dialog (#647)
* fix: quit confirmation dialog * test: leftover * test: quit confirmation dialog
1 parent c217516 commit 0f2e4c6

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

e2e-tests/fixtures/electron.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export const test = base.extend<ElectronFixtures>({
2020

2121
await use(app)
2222

23+
const window = await app.firstWindow()
24+
await window.evaluate(() => {
25+
// mock confirm quit
26+
localStorage.setItem('doNotShowAgain_confirm_quit', 'true')
27+
})
28+
2329
// Ensure app is closed and video is recorded
2430
const appToClose = app.close()
2531
await appToClose

main/src/main.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,17 @@ app.on('will-finish-launching', () => {
389389
log.info('App will finish launching - preparing for potential restart')
390390
})
391391

392-
app.on('before-quit', (e) => blockQuit('before-quit', e))
392+
app.on('before-quit', (e) => {
393+
if (mainWindow) {
394+
mainWindow.show()
395+
mainWindow.focus()
396+
mainWindow.webContents.send('show-quit-confirmation')
397+
}
398+
399+
if (!isQuitting) {
400+
e.preventDefault()
401+
}
402+
})
393403
app.on('will-quit', (e) => blockQuit('will-quit', e))
394404

395405
// Docker / Ctrl-C etc.
@@ -457,8 +467,8 @@ ipcMain.handle('hide-app', () => {
457467
mainWindow?.hide()
458468
})
459469

460-
ipcMain.handle('quit-app', () => {
461-
app.quit()
470+
ipcMain.handle('quit-app', (e) => {
471+
blockQuit('before-quit', e)
462472
})
463473

464474
ipcMain.handle('get-toolhive-port', () => getToolhivePort())

renderer/src/common/components/settings/tabs/__tests__/general-tab.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const mockElectronAPI = {
2525
optIn: vi.fn(),
2626
optOut: vi.fn(),
2727
},
28-
quitApp: vi.fn(),
2928
}
3029

3130
Object.defineProperty(window, 'electronAPI', {

renderer/src/common/components/settings/tabs/__tests__/settings-tabs.test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const mockElectronAPI = {
1616
optIn: vi.fn(),
1717
optOut: vi.fn(),
1818
},
19-
quitApp: vi.fn(),
2019
}
2120

2221
Object.defineProperty(window, 'electronAPI', {
@@ -35,10 +34,6 @@ vi.mock('@/common/hooks/use-auto-launch', () => ({
3534
}),
3635
}))
3736

38-
vi.mock('@/common/hooks/use-confirm-quit', () => ({
39-
useConfirmQuit: vi.fn().mockReturnValue(vi.fn().mockResolvedValue(true)),
40-
}))
41-
4237
const renderWithProviders = (component: React.ReactElement) => {
4338
const queryClient = new QueryClient({
4439
defaultOptions: {

0 commit comments

Comments
 (0)