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