Add support for launching the application with a file on Windows/Linux
See original GitHub issueThe Problem
Applications built to edit file types typically prepare their electron.manifest.json files to perform file associations such that when a user double-clicks a custom filetype, the OS launches their applications.
- For OSX, ElectronNET addressed #478 and implemented support for this very behavior
- For Window, ElectronNET does not support this 😢
- For Linux, ElecteonNET does not support this 😢
Describe the solution you’d like
For both Windows and Linux, the OS will invoke the application executable and will pass it the location of the file to be processed as the first argument.
c:\path\to\my-custom-app\myapp.exe $1
Per the Electron documentation for open-file, handling this must be done via the processing the process.argv array.
Now, there does not seem to be a defacto, standard way of passing this information around like there is for the commandline.hasSwitch(switch) and commandline.getSwitchValue(switch)…which is already supported by ElectronNET.
Therefore, I propose we treat the first argument as a special case by internally adding it to the switches as --open-file=$1
and then can be accessed using typical commandline.hasSwitch processing.
Example
-
Invoking from electronize start
c:\path\to\custom\app>electronize start /args .\file.custom --dog=woof --test=true
-
Invoking the compiled Electron executable
c:\path\to\custom\app>myapp.exe .\file.custom --dog=woof --test=true
-
To access the commandline arguments
// ASP.NET code... // await Electron.App.CommandLine.GetSwitchValueAsync("open-file")); // returns ".\file.custom" await Electron.App.CommandLine.GetSwitchValueAsync("dog")); // returns "woof" await Electron.App.CommandLine.GetSwitchValueAsync("test")); // returns "true"
Additional Context
In my investigation in to implementing this on a fork, printing the process.argv[] array in ElectronNET.Host/main.js
, the following behavior is observed.
-
When running via
electronize start /watch /args c:\path\to\custom\file.custom --dog=woof --test=true
results in:process.argv[0]='C:\path\to\dotnet\project\obj\Host\node_modules\electron\dist\electron.exe' process.argv[1]='..\..\main.js' process.argv[2]='c:\path\to\custom\file.custom' process.argv[3]='--dog=woof' process.argv[4]='--test=true' process.argv[5]='--watch=true'
-
When running via published executable found in the unpacked directory:
C:\path\to\dotnet\project\bin\Desktop\win-unpacked\app.exe c:\path\to\custom\file.custom --dog=woof --test=true
results in:process.argv[0]='C:\path\to\dotnet\project\bin\Desktop\win-unpacked\app.exe' process.argv[1]='c:\path\to\custom\file.custom' process.argv[2]='--dog=woof' process.argv[3]='--test=true'
Issue Analytics
- State:
- Created 2 years ago
- Comments:21 (5 by maintainers)
Top GitHub Comments
It’s in @GregorBiswanger hands for merging and such, I’m simply an engaged party having a public app based on this project. 😃 he mentioned elsewhere that he has some vacation that is in effect now that will give him time to do the updates. I’d imagine it will happen this week or next. /shrug
Yes please!
Thanks, Dan On Jul 18, 2023 at 2:30 PM -0400, Florian Rappl @.***>, wrote: