Skip to content

Commit 29d7dc0

Browse files
committed
fix(updates): resolve macOS quitAndInstall blocked by close handler
On macOS the window 'close' handler hides the window instead of quitting unless isQuitting is set. quitAndInstall closes windows before 'before-quit' fires, so the restart action stalled and the update only installed on manual quit. Set the flag synchronously before quitAndInstall via a shared quitState module.
1 parent 56a0399 commit 29d7dc0

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/main/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { registerIPC } from './ipc'
88
import { startThemeWatcher, stopThemeWatcher } from './ipc/handlers/theme'
99
import { validateStoredLicense } from './license'
1010
import { createMainMenu } from './menu/main'
11+
import { isQuitting, setQuitting } from './quitState'
1112
import { startMarkdownWatcher, stopMarkdownWatcher } from './storage'
1213
import { ensureFlatSpacesLayout } from './storage/providers/markdown/runtime/spaces'
1314
import { store } from './store'
@@ -24,7 +25,6 @@ const WINDOW_BOUNDS_SAVE_DELAY = 250
2425

2526
let mainWindow: BrowserWindow
2627
let saveWindowBoundsTimer: ReturnType<typeof setTimeout> | null = null
27-
let isQuitting = false
2828
let migrationResult: {
2929
folders: number
3030
snippets: number
@@ -117,7 +117,7 @@ function createWindow() {
117117
mainWindow.on('close', (event) => {
118118
flushWindowBoundsSave()
119119

120-
if (process.platform === 'darwin' && !isQuitting) {
120+
if (process.platform === 'darwin' && !isQuitting()) {
121121
event.preventDefault()
122122
mainWindow.hide()
123123
return
@@ -267,7 +267,7 @@ else {
267267
})
268268

269269
app.on('before-quit', () => {
270-
isQuitting = true
270+
setQuitting(true)
271271
flushWindowBoundsSave()
272272
stopThemeWatcher()
273273
stopMarkdownWatcher()

src/main/quitState.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Общий флаг «приложение реально завершается». На macOS обработчик 'close'
2+
// прячет окно вместо выхода, поэтому путь установки апдейта (quitAndInstall)
3+
// должен выставить флаг до закрытия окон, иначе выход блокируется.
4+
let quitting = false
5+
6+
export function setQuitting(value: boolean) {
7+
quitting = value
8+
}
9+
10+
export function isQuitting() {
11+
return quitting
12+
}

src/main/updates/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { autoUpdater } from 'electron-updater'
33
import { repository, version } from '../../../package.json'
44
import i18n from '../i18n'
55
import { send } from '../ipc'
6+
import { setQuitting } from '../quitState'
67
import { store } from '../store'
78
import { log } from '../utils'
89

@@ -38,6 +39,9 @@ async function runUpdateCheck() {
3839
}
3940

4041
export function installDownloadedUpdate() {
42+
// На macOS quitAndInstall закрывает окна, а обработчик 'close' без этого флага
43+
// спрятал бы окно вместо выхода и заблокировал установку.
44+
setQuitting(true)
4145
autoUpdater.quitAndInstall()
4246
}
4347

0 commit comments

Comments
 (0)