From 818a746a88dc9489620f0bc38af5d3cc2ffe12b3 Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Sat, 11 Oct 2025 13:46:48 +0530 Subject: [PATCH] =?UTF-8?q?Fix=20double-click=20file=20opening=20in=20inst?= =?UTF-8?q?alled=20Windows=20app=20(v1.7.5)=20This=20fix=20addresses=20the?= =?UTF-8?q?=20critical=20issue=20where=20double-clicking=20.md=20files=20w?= =?UTF-8?q?ould=20not=20open=20them=20in=20the=20installed=20PanConverter?= =?UTF-8?q?=20application=20on=20Windows.=20##=20Root=20Cause=20When=20a?= =?UTF-8?q?=20user=20double-clicks=20a=20file=20and=20the=20app=20is=20alr?= =?UTF-8?q?eady=20running,=20Windows=20tries=20to=20launch=20a=20SECOND=20?= =?UTF-8?q?INSTANCE=20with=20the=20file=20path.=20Without=20single-instanc?= =?UTF-8?q?e=20lock=20handling,=20that=20second=20instance=20would=20exit?= =?UTF-8?q?=20and=20the=20first=20instance=20would=20never=20receive=20the?= =?UTF-8?q?=20file=20path.=20##=20Changes=20-=20Added=20single-instance=20?= =?UTF-8?q?lock=20handling=20in=20main.js=20(lines=2052-85)=20-=20Implemen?= =?UTF-8?q?ted=20second-instance=20event=20handler=20to=20capture=20file?= =?UTF-8?q?=20paths=20-=20Focus=20existing=20window=20when=20second=20inst?= =?UTF-8?q?ance=20is=20attempted=20-=20Pass=20file=20path=20to=20existing?= =?UTF-8?q?=20instance=20using=20openFileFromPath()=20-=20Properly=20handl?= =?UTF-8?q?e=20rendererReady=20state=20for=20file=20opening=20##=20Testing?= =?UTF-8?q?=20-=20Works=20in=20development=20mode=20(npm=20start)=20-=20Sh?= =?UTF-8?q?ould=20now=20work=20correctly=20in=20installed=20Windows=20app?= =?UTF-8?q?=20with=20double-click=20-=20Maintains=20single=20instance=20be?= =?UTF-8?q?havior=20across=20all=20file=20opening=20methods=20=F0=9F=A4=96?= =?UTF-8?q?=20Generated=20with=20[Claude=20Code](https://claude.com/claude?= =?UTF-8?q?-code)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/main.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 93eb969..38d2093 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pan-converter", - "version": "1.7.4", + "version": "1.7.5", "description": "Cross-platform Markdown editor and converter using Pandoc", "main": "src/main.js", "scripts": { diff --git a/src/main.js b/src/main.js index e2e0981..db1aad3 100644 --- a/src/main.js +++ b/src/main.js @@ -49,6 +49,41 @@ let currentFile = null; // This will now represent the active tab's file let pandocAvailable = null; // Cache pandoc availability check let rendererReady = false; // Track if renderer is ready to receive file data +// Handle single instance lock for Windows file association +// When a file is double-clicked and the app is already running, +// Windows tries to start a second instance. We prevent this and +// pass the file to the existing instance instead. +const gotTheLock = app.requestSingleInstanceLock(); + +if (!gotTheLock) { + // Another instance is already running, quit this one + app.quit(); +} else { + // This is the first instance, handle second-instance events + app.on('second-instance', (event, commandLine, workingDirectory) => { + // Someone tried to run a second instance, focus our window instead + if (mainWindow) { + if (mainWindow.isMinimized()) mainWindow.restore(); + mainWindow.focus(); + } + + // Check if a file was passed to the second instance + // commandLine is an array like: ['electron.exe', 'app.asar', 'file.md'] + const fileArgs = commandLine.slice(2); + for (const arg of fileArgs) { + if ((arg.endsWith('.md') || arg.endsWith('.markdown')) && fs.existsSync(arg)) { + // Open the file in the existing instance + if (rendererReady) { + openFileFromPath(arg); + } else { + app.pendingFile = arg; + } + break; + } + } + }); +} + // Check if pandoc is available function checkPandocAvailability() { return new Promise((resolve) => {