Implement logging for Windows launch arguments in single instance management
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

- 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.
This commit is contained in:
Tom Butcher 2026-08-02 21:03:12 +01:00
parent 93df523b7c
commit 37593d73ce
2 changed files with 37 additions and 1 deletions

View File

@ -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,

View File

@ -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
}