From 37593d73ce7cdcf06f8f84e2fb499f0d2f6e0098 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sun, 2 Aug 2026 21:03:12 +0100 Subject: [PATCH] Implement logging for Windows launch arguments in single instance management - Added `logWindowsLaunchArgs` function to log launch arguments and sources for better debugging on Windows. - Integrated logging into `ensureSingleInstanceLock` and instance handling to provide insights during instance management. - Enhanced existing logging to include context-specific messages for improved clarity in the Windows environment. --- src/bun/index.js | 14 +++++++++++++- src/desktop/single-instance.js | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/bun/index.js b/src/bun/index.js index 0dc587f..3c5b565 100644 --- a/src/bun/index.js +++ b/src/bun/index.js @@ -1,16 +1,28 @@ import { captureLaunchUrl, closeSingleInstanceServer, - ensureSingleInstanceLock + ensureSingleInstanceLock, + logWindowsLaunchArgs } from '../desktop/single-instance.js' +if (process.platform === 'win32') { + logWindowsLaunchArgs('index-before-lock') +} + const launchUrl = captureLaunchUrl() const gotSingleInstanceLock = await ensureSingleInstanceLock({ launchUrl }) if (!gotSingleInstanceLock) { + if (process.platform === 'win32') { + console.log('[launch-args][index] exiting secondary instance') + } process.exit(0) } +if (process.platform === 'win32') { + console.log('[launch-args][index] acquired single instance lock') +} + const { createAppRpc } = await import('../desktop/rpc.js') const { registerGlobalShortcuts, diff --git a/src/desktop/single-instance.js b/src/desktop/single-instance.js index 53c27da..a0948a0 100644 --- a/src/desktop/single-instance.js +++ b/src/desktop/single-instance.js @@ -162,6 +162,19 @@ function collectLaunchSources() { return sources } +export function logWindowsLaunchArgs(context = 'startup') { + if (process.platform !== 'win32') { + return + } + + const launchSources = getWindowsLaunchSources() + const launchUrl = captureLaunchUrl() + + console.log(`[launch-args][${context}] process.argv:`, process.argv) + console.log(`[launch-args][${context}] launch sources:`, launchSources) + console.log(`[launch-args][${context}] captured url:`, launchUrl ?? null) +} + export function captureLaunchUrl() { const argvUrl = findProtocolUrl(process.argv) if (argvUrl) { @@ -249,6 +262,11 @@ function dispatchMessage(message) { const resolved = resolveIncomingMessage(message) if (!resolved) return + if (process.platform === 'win32') { + console.log('[launch-args][dispatch]', message) + console.log('[launch-args][dispatch] resolved:', resolved) + } + if (!handlers.onDeepLink && !handlers.onFocus) { pendingMessages.push(resolved) return @@ -364,8 +382,14 @@ export async function ensureSingleInstanceLock({ launchUrl } = {}) { const payload = buildLaunchPayload(launchUrl) + if (process.platform === 'win32') { + logWindowsLaunchArgs('ensure-single-instance-lock') + console.log('[launch-args][single-instance] payload:', payload) + } + if (process.platform === 'win32') { if (await forwardToRunningInstance(payload)) { + console.log('[launch-args][single-instance] forwarded to running instance') return false }