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

Allow only single instance #7

Closed
waltersenekal opened this issue Sep 18, 2024 · 3 comments
Closed

Allow only single instance #7

waltersenekal opened this issue Sep 18, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@waltersenekal
Copy link

Hi, thanks for sharing your program, i love it
I would suggest that you make it that only one instance can run at a time

internal static class Program
{

  static Mutex mutex = new Mutex(true, "{B13D5A64-7F53-48A8-B022-3F65E35C1A1E}");

  [STAThread]
  public static void Main()
  {
    if (mutex.WaitOne(TimeSpan.Zero, true))
    {
      Application.SetCompatibleTextRenderingDefault(false);
      Application.EnableVisualStyles();
      Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);

      using WindowOpeningListener windowOpeningListener = new WindowOpeningListenerImpl();
      windowOpeningListener.windowOpened += (_, window) => SecurityKeyChooser.chooseUsbSecurityKey(window);

      foreach (SystemWindow fidoPromptWindow in SystemWindow.FilterToplevelWindows(SecurityKeyChooser.isFidoPromptWindow))
      {
        SecurityKeyChooser.chooseUsbSecurityKey(fidoPromptWindow);
      }

      _ = I18N.getStrings(I18N.Key.SMARTPHONE); // ensure localization is loaded eagerly

      Application.Run();
    }
    else
    {
      // Notify the user and exit
      MessageBox.Show("Another instance of the application is already running.");
    }
  }

}

@Aldaviva
Copy link
Owner

Thanks for the suggestion, that's a great idea. I will add that.

@Aldaviva Aldaviva self-assigned this Sep 18, 2024
@Aldaviva Aldaviva added the enhancement New feature or request label Sep 18, 2024
@Aldaviva Aldaviva added this to the 0.2.0 milestone Sep 18, 2024
Aldaviva added a commit that referenced this issue Sep 19, 2024
@Aldaviva
Copy link
Owner

Added, this program will now exit if there is another instance of itself already running in the same user account.

@Aldaviva
Copy link
Owner

Released in 0.2.0.

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

No branches or pull requests

2 participants