The 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.
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'
The 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.
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.
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=$1and then can be accessed using typical commandline.hasSwitch processing.Example
Invoking from electronize start
Invoking the compiled Electron executable
To access the commandline arguments
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=trueresults in: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=trueresults in: