Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

singleInstance Electron Manifest setting should handle command line arguments #520

Closed
Delpire opened this issue Dec 8, 2020 · 1 comment
Assignees
Labels
Milestone

Comments

@Delpire
Copy link

Delpire commented Dec 8, 2020

Currently there are two ways of enforcing an app to be single instance.

  1. Set "singleInstance": true in the electron manifest json
  2. Write code in .NET to request the single instance lock and handle the second instance accordingly.

The first option seems to be the most reliable and robust. It works the fastest since it is being done in the javascript before the ASP .NET Core application launches (at least that is my understanding). However, one major problem is that you cannot handle the command line arguments to this second instance.

The alternative to this, is to set this to false and write the code to handle it ourselves, but this has several problems. Firstly, I can't get the callback to work, see #519 . Secondly, the second instance will always launch the splash screen, which is undesired if I have an instance running (and not a problem using the singleInstance in the manifest).

I really think both problems should be fixed, but I would be happy with one of the following two solutions.
Solution 1: Allow the javascript to take arguments and pass them to .NET. Then we can just check for the lock and handle the arguments.
Solution 2: Provide a new setting to the electron.manifest.json that will cause main.js to first check if it has the lock, and if it does not have the lock, don't display the Splashscreen, but continue to call the ASP .NET Core stuff so that we can handle the arguments.

I believe the only work around (assuming I can get the callback working or that gets fixed), is to handle showing the splash screen myself. That concerns me because I believe the app will seem more responsive at launch when the javascript launches the splash screen. My app seems to take a long time to load, and I am concerned that the splash screen will take a long time to show up if I write that code myself in .NET

@Delpire Delpire added the Feature label Dec 8, 2020
@GregorBiswanger GregorBiswanger self-assigned this Dec 10, 2020
@GregorBiswanger GregorBiswanger added this to the 11.5.1 milestone Dec 10, 2020
@GregorBiswanger GregorBiswanger modified the milestones: 11.5.1, 11.5.2 Jan 21, 2021
@GregorBiswanger
Copy link
Member

Hi @Delpire, this feature is implemented for the next Electron.NET 13.5.1 release.

If the second instance is opened with arguments, the main application that has landed receives a focus. If you subscribe to this event, you can also request your new arguments.

As example:

Task.Run(async () =>
{
    var mainWindow = await Electron.WindowManager.CreateWindowAsync();
    mainWindow.OnFocus += async () =>
    {
        if(await Electron.App.CommandLine.HasSwitchAsync("message"))
        {
            var message = await Electron.App.CommandLine.GetSwitchValueAsync("message");
            await Electron.Dialog.ShowMessageBoxAsync(message);
        }
    };
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants