fix: read silentStart config synchronously to avoid race condition

This commit is contained in:
xmk23333 2026-01-01 10:57:45 +08:00
parent 85f430f188
commit 8384953fb7

View File

@ -12,7 +12,7 @@ export let mainWindow: BrowserWindow | null = null
let quitTimeout: NodeJS.Timeout | null = null
export async function createWindow(): Promise<void> {
const { useWindowFrame = false } = await getAppConfig()
const { useWindowFrame = false, silentStart = false, autoQuitWithoutCore = false, autoQuitWithoutCoreDelay = 60 } = await getAppConfig()
const mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 600,
@ -47,7 +47,7 @@ export async function createWindow(): Promise<void> {
})
mainWindowState.manage(mainWindow)
setupWindowEvents(mainWindow, mainWindowState)
setupWindowEvents(mainWindow, mainWindowState, { silentStart, autoQuitWithoutCore, autoQuitWithoutCoreDelay })
if (is.dev) {
mainWindow.webContents.openDevTools()
@ -60,17 +60,20 @@ export async function createWindow(): Promise<void> {
}
}
interface WindowConfig {
silentStart: boolean
autoQuitWithoutCore: boolean
autoQuitWithoutCoreDelay: number
}
function setupWindowEvents(
window: BrowserWindow,
windowState: ReturnType<typeof windowStateKeeper>
windowState: ReturnType<typeof windowStateKeeper>,
config: WindowConfig
): void {
window.on('ready-to-show', async () => {
const {
silentStart = false,
autoQuitWithoutCore = false,
autoQuitWithoutCoreDelay = 60
} = await getAppConfig()
const { silentStart, autoQuitWithoutCore, autoQuitWithoutCoreDelay } = config
window.on('ready-to-show', () => {
if (autoQuitWithoutCore && !window.isVisible()) {
scheduleQuitWithoutCore(autoQuitWithoutCoreDelay)
}