question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for launching the application with a file on Windows/Linux

See original GitHub issue

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.

  • 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

  1. Invoking from electronize start

    c:\path\to\custom\app>electronize start /args .\file.custom --dog=woof --test=true
    
  2. Invoking the compiled Electron executable

    c:\path\to\custom\app>myapp.exe .\file.custom --dog=woof --test=true
    
  3. 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.

  1. 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'
    
  2. 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:open
  • Created 2 years ago
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
danatcofocommented, Jan 3, 2022

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

0reactions
dlittycommented, Jul 19, 2023

Yes please!

Thanks, Dan On Jul 18, 2023 at 2:30 PM -0400, Florian Rappl @.***>, wrote:

I think it was not - if we could get that back it would be awesome! — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run Linux GUI apps with WSL
Install support for Linux GUI apps. Prerequisites. You will need to be on Windows 10 Build 19044+ or Windows 11 to access this...
Read more >
How to run a Windows app on Linux with Wine
I'm going to show you how to install the Notepad++ Windows app with the help of Wine. Here's what you need to do....
Read more >
Run your favorite Windows applications on Linux
Computer screen with files or windows open ... Here's how running Windows apps on Linux can be made seamless with ... sudo dnf...
Read more >
How to run Windows apps on Linux with Bottles - YouTube
The first step to install anything will be to create a bottle to run the application in. The "+" button lets you do...
Read more >
Easily Run Windows Apps On Linux With Bottles - YouTube
Need to run Windows programs on Linux ? Bottles can help with that! Bottles is a frontend to WINE. Choose between Gaming and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found