From ca748384cfa341627ee59c704654c650f6df285c Mon Sep 17 00:00:00 2001 From: Todd Schavey Date: Tue, 28 Dec 2021 21:40:53 -0500 Subject: [PATCH] fix #647 process argv for open-file for win and linux --- src/ElectronNET.Host/main.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ElectronNET.Host/main.js b/src/ElectronNET.Host/main.js index 622342e..02c3ff7 100644 --- a/src/ElectronNET.Host/main.js +++ b/src/ElectronNET.Host/main.js @@ -18,6 +18,27 @@ let launchUrl; let manifestJsonFileName = 'electron.manifest.json'; let watchable = false; + +// handle for opening the app with a file for win and linux +if (process && process.argv.length > 1) { + + let firstAppArgument = process.argv[1]; + + // With invoked via electronize, the first argument is the path to the main.js. + // Per issue #337, the /args switch can also be present. If either are present, + // we need to check the subsequent argument. + if (firstAppArgument === '..\\..\\main.js' || firstAppArgument === '../../main.js' || firstAppArgument === '/args') { + if (process.argv.length > 2) { + firstAppArgument = process.argv[2]; + } + } + + // only append the first app arg if it is not already a switch + if (!firstAppArgument.startsWith("--")) { + app.commandLine.appendSwitch("open-file", firstAppArgument); + } +} + if (app.commandLine.hasSwitch('manifest')) { manifestJsonFileName = app.commandLine.getSwitchValue('manifest'); }