PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

[Settings]Singleton doesn't work

Open noraa-junker opened this issue 5 years ago • 23 comments

ℹ Computer information

  • PowerToys version: 0.25
  • PowerToy Utility: Settings
  • Running PowerToys as Admin: Yes
  • Windows build number: image

📝 Provide detailed reproduction steps (if any)

  1. Open settings window
  2. Open a second settings window with middle click on the taskbar icon

✔️ Expected result

The second settings window open

❌ Actual result

A error message appears

📷 Screenshots

image

noraa-junker avatar Nov 30 '20 15:11 noraa-junker

Middle clicking the PT run icon in the taskbar directly runs the Microsoft.PowerToys.Settings.UI.Runner.exe which cannot be run by the user manually but only by PowerToys Runner. That's what I think is the reason

Also I don't think you can launch multiple instances of PowerToys Settings (Why would you?)

ghost avatar Nov 30 '20 15:11 ghost

If i'm fast i can press on start of PT multiple times on the icon and the settings window appears so multiple times

noraa-junker avatar Nov 30 '20 15:11 noraa-junker

No, you don't need more then one instance. But the software should handle this smoothly. ~https://docs.microsoft.com/en-us/windows/uwp/launch-resume/multi-instance-uwp~

Jay-o-Way avatar Nov 30 '20 16:11 Jay-o-Way

No, you don't need more then one instance. But the software should handle this smoothly. https://docs.microsoft.com/en-us/windows/uwp/launch-resume/multi-instance-uwp

That's for a UWP App. PowerToys is not UWP

ghost avatar Nov 30 '20 16:11 ghost

In ColorPickerUI Mutex is used to allow single instance https://github.com/microsoft/PowerToys/blob/6cee767ddfdc1a95c90c1ba3feb45038c681ea4f/src/modules/colorPicker/ColorPickerUI/App.xaml.cs#L51

davidegiacometti avatar Nov 30 '20 17:11 davidegiacometti

That's for a UWP App. PowerToys is not UWP

UWP, WinUI(3), WPF, Fluent Design, XAML ... So many terms. "software should handle this smoothly" is the thing I really wanted to say.

Jay-o-Way avatar Nov 30 '20 17:11 Jay-o-Way

Can we get crisp repro steps here without VS possibly running?

  1. Settings is actually a UWP technically under the hood. It is a WPF app with a XAML Island.
  2. In theory, this scenario is actually handled.
  3. if i map a button on my logitech mouse to 'middle' it doesn't interact with the tray icon. I can't repro this. Only way i can get settings to fire is:
    • left click tray icon
    • right click tray icon and go to settings
    • Start PowerToys via PT Run / Start menu with PowerToys already running
  4. Typically that error you see there happens if you run the Settings app via Visual Studio directly or try to launch the app directly.

crutkas avatar Nov 30 '20 18:11 crutkas

Also you'll never get two instances of Settings open, only one. If that is the ask here, we don't have plans.

crutkas avatar Nov 30 '20 18:11 crutkas

Can we get crisp repro steps here without VS possibly running?

  1. Settings is actually a UWP technically under the hood. It is a WPF app with a XAML Island.
  2. In theory, this scenario is actually handled.
  3. if i map a button on my logitech mouse to 'middle' it doesn't interact with the tray icon. I can't repro this. Only way i can get settings to fire is:
    • left click tray icon
    • right click tray icon and go to settings
    • Start PowerToys via PT Run / Start menu with PowerToys already running
  4. Typically that error you see there happens if you run the Settings app via Visual Studio directly or try to launch the app directly.

See my comment in issue #6471.

htcfreek avatar Nov 30 '20 18:11 htcfreek

I think for repro you need a hp elitedesk 800 g1 with 250 apllications installed.

I will do my best to give you a good repro.

noraa-junker avatar Nov 30 '20 19:11 noraa-junker

@Aaron-Junker Not for the repro of opening two windows via

  1. Press Win+B
  2. Selecting the PT Tray Icon
  3. Pressing Enter or NumPad Enter

htcfreek avatar Nov 30 '20 19:11 htcfreek

My repro is

  • Open Settings
  • right-click the taskbar button
  • click the top menu item

See also #5234. (I know the body of Niels's issue only focuses on the text, but the behavior of this issue is well mentioned in the comments)

Jay-o-Way avatar Nov 30 '20 20:11 Jay-o-Way

I see what i was doing. I was doing systray! not taskbar. Suprised the singleton isn't catching this.

crutkas avatar Nov 30 '20 20:11 crutkas

Betting this and https://github.com/microsoft/PowerToys/issues/6471 could be solved by fixing the singleton. I still think this is a lower priority bug

crutkas avatar Nov 30 '20 20:11 crutkas

Yes I think its a singleton problem

noraa-junker avatar Dec 01 '20 08:12 noraa-junker

Changed the title to reflect that actual problem: the Settings app can only be opened from the runner.

enricogior avatar Dec 05 '20 06:12 enricogior

@enricogior Can't we just allow users to run Microsoft.PowerToys.Settings.UI.Runner.exe and have it open without error?

(Of course, don't allow multiple instances)

ghost avatar Dec 05 '20 14:12 ghost

@alannt777 with the current architecture we cannot, the Settings should only be opened by the runner.

enricogior avatar Dec 06 '20 00:12 enricogior

Any update so far?

Jay-o-Way avatar Mar 27 '21 13:03 Jay-o-Way

no, this is also a bug only i would say "PT community" has really hit based on bug reports. This is a low priority issue based on other things we're seeing reports of.

crutkas avatar Mar 30 '21 05:03 crutkas

I still experience this btw

noraa-junker avatar Oct 30 '21 19:10 noraa-junker

https://blogs.windows.com/windowsdeveloper/2022/01/28/making-the-app-single-instanced-part-3/

Jay-o-Way avatar Sep 28 '22 23:09 Jay-o-Way

I believe this issue stems from from the open_menu_from_another_instance method. PowerToys/src/runner/main.cpp

This function is called successfully, however in WinMain the check for --open-settings on line 425 ends up yielding an empty string leading to the open_menu_from_another_instance call parameter "". The check on Line 85 checks the std::optional has a value, but doesn't check for an empty string.

I have included this fix in #23220 to ensure the settings window can be open even with a hidden icon.

BLM16 avatar Jan 10 '23 00:01 BLM16

Does this still happen? /needinfo

stefansjfw avatar Apr 24 '23 15:04 stefansjfw

@stefansjfw https://github.com/microsoft/PowerToys/pull/23220 was supposed to have the fix for this, wouldn't it still happen?

crutkas avatar Apr 24 '23 16:04 crutkas

Does this still happen? /needinfo

It does

Jay-o-Way avatar Apr 25 '23 09:04 Jay-o-Way

ping @BLM16

Jay-o-Way avatar Apr 25 '23 09:04 Jay-o-Way

My fix is part of #23220 because it was giving me problems while testing. I'm not sure what the current status on getting that merged is.

There was a single change to the function that is supposed to do this already since a blank string was passed rather than null. It fixed the issue locally, however, it may not be the full solution.

Would you like me to extract that and make it a separate PR? We could get that merged earlier than the icon removal if it works.

BLM16 avatar Apr 25 '23 12:04 BLM16

I see what i was doing. I was doing systray! not taskbar. Suprised the singleton isn't catching this.

Got it now. This opened my eyes :)

Would you like me to extract that and make it a separate PR? We could get that merged earlier than the icon removal if it works.

That would be cool. Please open the PR with that fix. Although, I believe opening settings app from taskbar item right click opens Settings App directly, not through runner, so not sure that cpp change will fix it, but let's see

stefansjfw avatar Apr 25 '23 13:04 stefansjfw

Apparently not everyone experiences this crash on the latest version. Is this still a reproducible issue in v0.69.1? I was experiencing a crash relating to this, however that might have been on one of my dev versions rather than a stable release.

BLM16 avatar May 03 '23 12:05 BLM16