From daead7a5f7f2e61cfb68c9da283f989d6c0a7a81 Mon Sep 17 00:00:00 2001 From: Anirudh Sevugan Date: Thu, 27 Feb 2025 23:56:19 +0530 Subject: [PATCH] Update main.js --- simpliplay/main.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/simpliplay/main.js b/simpliplay/main.js index bf7a9ba..bc27b7b 100644 --- a/simpliplay/main.js +++ b/simpliplay/main.js @@ -185,6 +185,12 @@ app.whenReady().then(() => { createWindow(); setupMenu(); + // Handle file opening from command-line arguments (Windows/Linux) + const args = process.argv.slice(1); // Skip the first argument (app path) + const fileArg = args.find(arg => !arg.startsWith('-') && !arg.includes('electron')); + + if (fileArg) openFileSafely(fileArg); + setTimeout(() => { if (mainWindow) { mainWindow.on("focus", () => { @@ -195,9 +201,10 @@ app.whenReady().then(() => { } }, 100); + // Handle file opening from Finder (macOS) app.on("open-file", (event, filePath) => { event.preventDefault(); - openFile(filePath); + openFileSafely(filePath); }); app.on("activate", () => { @@ -205,6 +212,16 @@ app.whenReady().then(() => { }); }); +let hasOpenedFile = false; + +function openFileSafely(filePath) { + if (!hasOpenedFile) { + hasOpenedFile = true; + openFile(filePath); + setTimeout(() => hasOpenedFile = false, 1000); // Reset after 1 sec + } +} + app.on("window-all-closed", () => { globalShortcut.unregisterAll();