mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b2afb5f15 | ||
|
|
c811af9d48 |
+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
-4
@@ -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) => {
|
||||||
@@ -1584,15 +1619,11 @@ function openFileFromPath(filePath) {
|
|||||||
currentFile = filePath;
|
currentFile = filePath;
|
||||||
const content = fs.readFileSync(filePath, 'utf-8');
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
if (mainWindow && mainWindow.webContents && rendererReady) {
|
if (mainWindow && mainWindow.webContents && rendererReady) {
|
||||||
console.log('Opening file (renderer ready):', filePath);
|
|
||||||
mainWindow.webContents.send('file-opened', { path: filePath, content });
|
mainWindow.webContents.send('file-opened', { path: filePath, content });
|
||||||
} else {
|
} else {
|
||||||
console.log('Renderer not ready, storing file:', filePath);
|
|
||||||
// Store file to open after renderer is ready
|
// Store file to open after renderer is ready
|
||||||
app.pendingFile = filePath;
|
app.pendingFile = filePath;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
console.error('File does not exist:', filePath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user