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

[Run] Allow executables to be picked up from custom program sources #30328

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

albertony
Copy link

@albertony albertony commented Dec 9, 2023

Summary of the Pull Request

Make it possible to configure that executables such as bat, cmd and exe should be picked up from custom ProgramSources in %LocalAppData%\Microsoft\PowerToys\PowerToys Run\Settings\Plugins\Microsoft.Plugin.Program\ProgramPluginSettings.json.

PR Checklist

Detailed Description of the Pull Request / Additional comments

This is still just small improvements of a hidden feature, extending #19632. I, and I think many others judging from feature requests etc, see a lot of potential in PT Run as the launcher tool if it gets a few important improvements. But for me personally, I think this small change is enough for me to be able to stick with it as is until someone takes the time to do some bigger improvements (like exposing these customizations to UI).

In the existing implementation, the fact that bat and exe are included in the default value of ProgramPluginSettings.ProgramSuffixes has no effect, as these extensions are later excluded by hardcoded Win32Program.ExecutableApplicationExtensions list. I don't see a reason why they should be included in the source search, only to exclude them later in the Linq expression? But also, this means regular executables with extensions such as .exe and .bat etc. will never be picked up from the Desktop and any customized ProgramPluginSettings.ProgramSources, so one typically need to create shortcuts for every program to be picked up. E.g. adding a directory containing the SysInternals suite to ProgramSources, and for PowerToys Run to pick up all tools would be very convenient (without having to litter my PATH with all different such "tool" locations).

With this PR I suggest:

  • Remove the use of Win32Program.ExecutableApplicationExtensions for excluding results from program paths.
    • The effect of this is that ProgramPluginSettings.ProgramSuffixes completely decides what should be picked up, and classified as Application in the UI.
  • To avoid changing the default behavior to exe and bat now starting to be picked up for all/default sources, then remove these from the default ProgramPluginSettings.ProgramSuffixes list.
  • Somewhat unrelated: Include cmd in addition to bat in ProgramPluginSettings.RunCommandSuffixes, since it is the "modern" cmd.exe specific extension I find supporting bat but not cmd a bit too limiting.

Some other alternatives / more improvements could be:

  • Search for ProgramPluginSettings.RunCommandSuffixes in all sources, not just PATH.
  • Introduce separate ProgramPluginSettings.RunCommandSources to differentiate which locations should be searched for RunCommand from those for Program.
  • Consider all/more of a typical PATHEXT (.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC) in ProgramPluginSettings.RunCommandSuffixes.

Validation Steps Performed

@albertony
Copy link
Author

@microsoft-github-policy-service agree

@albertony albertony force-pushed the run-suffix-improvements branch from 8882613 to 0f902d9 Compare December 10, 2023 10:27
@htcfreek
Copy link
Collaborator

@albertony
Please link an existing issue or create a new one for tracking your work on it.

Is it correct that there won't be any user interface to change the settings?

@albertony
Copy link
Author

Issue created:

Is it correct that there won't be any user interface to change the settings?

Correct. Same as the other mentioned PR, which fixed that anything from ProgramSources are picked up at all.

@jaimecbernardo
Copy link
Collaborator

Pretty interesting... I think this actually will fix some interesting bugs too.
The exclusion was brought in here: #11364
And I suspect that's one thing that went through and wasn't noticed... that "not". I suspect this might be the root cause for some issues we have about executables not being found. For example executables that are listed in registry seem to be removed here. I'll give this a test for any weird regressions.

@jaimecbernardo
Copy link
Collaborator

At this moment, this is creating many duplicated entries for me, indeed. Wondering if we need to nuke existing Program extension from ProgramPluginSettings.json on the next version, since even if we do code changes, that's "default settings" and won't be visible.
Anyway, it'd make more sense for executables to be programs instead of run commands, right?

@albertony
Copy link
Author

At this moment, this is creating many duplicated entries for me, indeed. Wondering if we need to nuke existing Program extension from ProgramPluginSettings.json on the next version, since even if we do code changes, that's "default settings" and won't be visible.

You mean your json still contains the previous default value of ProgramSuffixes, leading to duplicates? In my experience the ProgramPluginSettings.json seem to get overwritten on PT updates, so I have in my routine to backup and merge back my customizations in this file anyway, but maybe this need to be more explicit/forced next time then, to be sure.

Anyway, it'd make more sense for executables to be programs instead of run commands, right?

Not sure exactly what you meant by this? I actually have never paid much attention to the distinction between run commands and programs when using the tool myself, and I don't really understand what the intention behind the separation is. I think in existing version run commands in reality are always executables found from PATH, right? Issue #30486 wants an easy way to exclude executables from results, that could be to set EnablePathEnvironmentVariableSource to false, or some new switch to turn on/off Programs vs RunCommands, or modify the ProgramSuffixes/RunCommandSuffixes to fit.

@jaimecbernardo
Copy link
Collaborator

You mean your json still contains the previous default value of ProgramSuffixes, leading to duplicates? In my experience the ProgramPluginSettings.json seem to get overwritten on PT updates, so I have in my routine to backup and merge back my customizations in this file anyway, but maybe this need to be more explicit/forced next time then, to be sure.

The settings clearing is something we're aiming to fix with #30187

Not sure exactly what you meant by this? I actually have never paid much attention to the distinction between run commands and programs when using the tool myself, and I don't really understand what the intention behind the separation is. I think in existing version run commands in reality are always executables found from PATH, right? Issue #30486 wants an easy way to exclude executables from results, that could be to set EnablePathEnvironmentVariableSource to false, or some new switch to turn on/off Programs vs RunCommands, or modify the ProgramSuffixes/RunCommandSuffixes to fit.

I need to check the distinction too. But from what I saw the Applications in registry are almost all .exe . 🤔 Thinking this needs some more thought before we make big changes here.

@jaimecbernardo jaimecbernardo self-assigned this Dec 20, 2023
@albertony
Copy link
Author

Thinking this needs some more thought before we make big changes here.

I see what you mean. I was kind of hoping this was a small enough fix that it could be taken as is, while considering more in depth changes. But that's your call, of course. 👍

Choose a reason for hiding this comment

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

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

Comments suppressed due to low confidence (1)

src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/Win32Program.cs:1011

  • Add a null check for the 'program' object to prevent a potential NullReferenceException.
program.AppType = ApplicationType.RunCommand;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants