Skip to content

Conversation

@stefansjfw
Copy link
Contributor

Related to #37908

@stefansjfw stefansjfw requested a review from zadjii-msft March 19, 2025 10:16
@zadjii-msft
Copy link
Member

Does this result in a cold launch from the Start Menu / taskbar not showing the window? Is there any way for us to differentiate the taskbar launch case from the PT enable case?

@zadjii-msft zadjii-msft added the Product-Command Palette Refers to the Command Palette utility label Mar 19, 2025
@stefansjfw
Copy link
Contributor Author

Does this result in a cold launch from the Start Menu / taskbar not showing the window? Is there any way for us to differentiate the taskbar launch case from the PT enable case?

I guess we can pass some dummy arg to CmdPal when starting from PowerToys...

@zadjii-msft
Copy link
Member

wow windows.applicationmodel.core.applistentry really doesn't give us a lot to work with.

I suppose we could add an app execution alias, and then CreateProcess(...., SW_HIDE) to create the window hidden when launched from PT. App execution aliases are notoriously flaky though

@stefansjfw
Copy link
Contributor Author

I tried SW_HIDE, doesn't work :( It's either shown for a second and then hidden or not hidden at all. I guess Window.Activate() overrides it somehow

@stefansjfw
Copy link
Contributor Author

never mind, I did what you need. Take a look

@crutkas crutkas added the Priority-0 Bugs that we consider release-blocking/recall-class (P0) label Mar 19, 2025
sei.lpFile = appPath.c_str();
sei.lpParameters = commandLineArgs.c_str();
sei.lpDirectory = dir.c_str();
sei.nShow = SW_SHOWNORMAL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we instead stick SW_HIDE in here, and get rid of the arg, and instead get the PInvoke.GetStartupInfo(), can we see if SW_HIDE was set there, and not show the window in that case?

(I feel like I don't really want to add a magic hidden arg to our exe, but I'll accept it for now if it's the only way)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give it a try

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't work. even if I pass SW_HIDE when launching, PInvoke says SW_SHOW is there. No idea why

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn. Mmk. We can come up with something more clever in the future. Thanks for taking a look!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the CmdPal startup behavior to prevent the window from showing automatically unless launched by PowerToys.

  • Introduces a command line argument check in App.xaml.cs for the "RunFromPT" flag to conditionally activate the window.
  • Adds an Activate() call in MainWindow.xaml.cs during hotkey processing to ensure the window is brought forward when handling hotkey commands.

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs Added command line argument logic to conditionally skip window activation on startup.
src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs Added an Activate() call before summoning commands via hotkeys.
Files not reviewed (1)
  • src/modules/cmdpal/CmdPalModuleInterface/dllmain.cpp: Language not supported
Comments suppressed due to low confidence (3)

src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs:70

  • [nitpick] Consider renaming 'runFromPT' to a more descriptive name such as 'isLaunchedFromPowerToys' to improve clarity.
bool runFromPT = false;

src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs:73

  • Using the magic string "RunFromPT" directly may lead to inconsistencies; consider defining it as a constant.
if (arg == "RunFromPT")

src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs:469

  • Verify that invoking Activate() in this context does not conflict with the intended hidden startup behavior, particularly for non-root hotkeys.
Activate();

@shuaiyuanxx shuaiyuanxx self-requested a review March 20, 2025 05:52
Copy link
Contributor

@shuaiyuanxx shuaiyuanxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues were found during the test.

Copy link
Contributor

@moooyo moooyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer merge in first. We can use a better implementation in the future.

@zadjii-msft zadjii-msft merged commit dadd306 into main Mar 20, 2025
15 checks passed
@zadjii-msft
Copy link
Member

I'm putting notes in here, because #38393 is off the rails


I bet we can use this somehow:

https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/applifecycle/applifecycle-rich-activation#activation-details-for-packaged-apps

rather than trying to use the shell:AppsFolder thing, which clearly doesn't work immediately on install always

colin-tso pushed a commit to colin-tso/PowerToys that referenced this pull request Apr 8, 2025
Adds a command line arg to not show CmdPal on startup. When starting from PT Run, we won't immediately show the window. 

as noted in microsoft#37908
@crutkas crutkas deleted the stefan/cmdpal_do_not_show_on_startup branch April 10, 2025 05:24
sadirano pushed a commit to sadirano/PowerToys that referenced this pull request Jun 10, 2025
Adds a command line arg to not show CmdPal on startup. When starting from PT Run, we won't immediately show the window. 

as noted in microsoft#37908
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority-0 Bugs that we consider release-blocking/recall-class (P0) Product-Command Palette Refers to the Command Palette utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants