From 7273803e6f0213593ae04e03cd5c7d07b4934ac4 Mon Sep 17 00:00:00 2001 From: Kuingsmile <96409857+Kuingsmile@users.noreply.github.com> Date: Tue, 12 May 2026 14:40:34 +0800 Subject: [PATCH] :sparkles: Feature(custom): improve handling of second instance activation with timer ISSUES CLOSED: #522 --- src/main/lifeCycle/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/lifeCycle/index.ts b/src/main/lifeCycle/index.ts index 6fe7ca48..7b0a1dc4 100644 --- a/src/main/lifeCycle/index.ts +++ b/src/main/lifeCycle/index.ts @@ -226,8 +226,14 @@ class LifeCycle { } #onRunning() { + let pendingActivateWindowTimer: ReturnType | null = null + app.on('second-instance', (_, commandLine, workingDirectory) => { logger.info('detect second instance') + if (pendingActivateWindowTimer !== null) { + clearTimeout(pendingActivateWindowTimer) + pendingActivateWindowTimer = null + } const result = handleStartUpFiles(commandLine, workingDirectory) if (!result) { windowManager.create(IWindowList.SETTING_WINDOW) @@ -235,7 +241,13 @@ class LifeCycle { }) app.on('activate', () => { if (!windowManager.has(IWindowList.SETTING_WINDOW)) { - windowManager.create(IWindowList.SETTING_WINDOW) + if (pendingActivateWindowTimer !== null) clearTimeout(pendingActivateWindowTimer) + pendingActivateWindowTimer = setTimeout(() => { + pendingActivateWindowTimer = null + if (!windowManager.has(IWindowList.SETTING_WINDOW)) { + windowManager.create(IWindowList.SETTING_WINDOW) + } + }, 300) } }) const storedAutoStartEnabled = picgo.getConfig(configPaths.settings.autoStart) || false