mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-10 19:50:28 +08:00
fix: read silentStart config synchronously to avoid race condition
This commit is contained in:
parent
85f430f188
commit
8384953fb7
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user