mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 10:00:17 +05:30
Fix double-click file opening in installed Windows app (v1.7.5)
This fix addresses the critical issue where double-clicking .md files would not open them in the installed PanConverter application on Windows. ## Root Cause When a user double-clicks a file and the app is already running, Windows tries to launch a SECOND INSTANCE with the file path. Without single-instance lock handling, that second instance would exit and the first instance would never receive the file path. ## Changes - Added single-instance lock handling in main.js (lines 52-85) - Implemented second-instance event handler to capture file paths - Focus existing window when second instance is attempted - Pass file path to existing instance using openFileFromPath() - Properly handle rendererReady state for file opening ## Testing - Works in development mode (npm start) - Should now work correctly in installed Windows app with double-click - Maintains single instance behavior across all file opening methods 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pan-converter",
|
"name": "pan-converter",
|
||||||
"version": "1.7.4",
|
"version": "1.7.5",
|
||||||
"description": "Cross-platform Markdown editor and converter using Pandoc",
|
"description": "Cross-platform Markdown editor and converter using Pandoc",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+35
@@ -49,6 +49,41 @@ let currentFile = null; // This will now represent the active tab's file
|
|||||||
let pandocAvailable = null; // Cache pandoc availability check
|
let pandocAvailable = null; // Cache pandoc availability check
|
||||||
let rendererReady = false; // Track if renderer is ready to receive file data
|
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
|
// Check if pandoc is available
|
||||||
function checkPandocAvailability() {
|
function checkPandocAvailability() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user