Update main.js

This commit is contained in:
Anirudh Sevugan 2025-02-27 23:56:19 +05:30 committed by GitHub
parent e5c2badb8d
commit daead7a5f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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();