Skip to content

Commit c87ef43

Browse files
authored
CmdPal: Add URI protocol command to reload extension (#41445)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This PR introduces a new way to reload extensions externally and makes the feature configurable in the settings UI. - Adds a new URI protocol command `x-cmdpal://reload` → triggers an extension reload - Introduces a new "For Developers" section on the General settings page - Includes an option to enable/disable the external reload feature - **Note:** This change depends on the fix in #41344 to work correctly. Pictures? Pictures! <img width="2312" height="1334" alt="image" src="https://github.com/user-attachments/assets/6457ef5b-e75e-4118-86b7-7e20505527a3" /> <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #40542 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed
1 parent 14a45e3 commit c87ef43

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public partial class SettingsModel : ObservableObject
4242

4343
public bool IgnoreShortcutWhenFullscreen { get; set; }
4444

45+
public bool AllowExternalReload { get; set; }
46+
4547
public Dictionary<string, ProviderSettings> ProviderSettings { get; set; } = [];
4648

4749
public Dictionary<string, CommandAlias> Aliases { get; set; } = [];

src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ public bool UseLowLevelGlobalHotkey
3838
}
3939
}
4040

41+
public bool AllowExternalReload
42+
{
43+
get => _settings.AllowExternalReload;
44+
set
45+
{
46+
_settings.AllowExternalReload = value;
47+
Save();
48+
}
49+
}
50+
4151
public bool ShowAppDetails
4252
{
4353
get => _settings.ShowAppDetails;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,21 @@ public void HandleLaunchNonUI(AppActivationArguments? activatedEventArgs)
521521
WeakReferenceMessenger.Default.Send<OpenSettingsMessage>(new());
522522
return;
523523
}
524+
else if (uri.StartsWith("x-cmdpal://reload", StringComparison.OrdinalIgnoreCase))
525+
{
526+
var settings = App.Current.Services.GetService<SettingsModel>();
527+
if (settings?.AllowExternalReload == true)
528+
{
529+
Logger.LogInfo("External Reload triggered");
530+
WeakReferenceMessenger.Default.Send<ReloadCommandsMessage>(new());
531+
}
532+
else
533+
{
534+
Logger.LogInfo("External Reload is disabled");
535+
}
536+
537+
return;
538+
}
524539
}
525540
}
526541
}

src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
<RepositionThemeTransition IsStaggeringEnabled="False" />
3535
</StackPanel.ChildrenTransitions>-->
3636

37+
<!-- 'Activation' section -->
38+
3739
<TextBlock x:Uid="ActivationSettingsHeader" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
3840

3941
<controls:SettingsExpander
@@ -66,6 +68,8 @@
6668
</ComboBox>
6769
</controls:SettingsCard>
6870

71+
<!-- 'Behavior' section -->
72+
6973
<TextBlock x:Uid="BehaviorSettingsHeader" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
7074

7175
<controls:SettingsCard x:Uid="Settings_GeneralPage_ShowAppDetails_SettingsCard" HeaderIcon="{ui:FontIcon Glyph=&#xE8A0;}">
@@ -84,7 +88,16 @@
8488
<ToggleSwitch IsOn="{x:Bind viewModel.ShowSystemTrayIcon, Mode=TwoWay}" />
8589
</controls:SettingsCard>
8690

87-
<!-- Example 'About' section -->
91+
<!-- 'For Developers' section -->
92+
93+
<TextBlock x:Uid="ForDevelopersSettingsHeader" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
94+
95+
<controls:SettingsCard x:Uid="Settings_GeneralPage_AllowExternalReload_SettingsCard" HeaderIcon="{ui:FontIcon Glyph=&#xE777;}">
96+
<ToggleSwitch IsOn="{x:Bind viewModel.AllowExternalReload, Mode=TwoWay}" />
97+
</controls:SettingsCard>
98+
99+
<!-- 'About' section -->
100+
88101
<TextBlock x:Uid="AboutSettingsHeader" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
89102

90103
<controls:SettingsExpander x:Uid="Settings_GeneralPage_About_SettingsExpander" HeaderIcon="{ui:BitmapIcon Source=ms-appx:///Assets/StoreLogo.png}">

src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,13 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
441441
<data name="NavigationPaneOpened" xml:space="preserve">
442442
<value>Navigation page opened</value>
443443
</data>
444+
<data name="Settings_GeneralPage_AllowExternalReload_SettingsCard.Header" xml:space="preserve">
445+
<value>Enable external reload</value>
446+
</data>
447+
<data name="Settings_GeneralPage_AllowExternalReload_SettingsCard.Description" xml:space="preserve">
448+
<value>Trigger reload of the extension externally with the x-cmdpal://reload command</value>
449+
</data>
450+
<data name="ForDevelopersSettingsHeader.Text" xml:space="preserve">
451+
<value>For Developers</value>
452+
</data>
444453
</root>

0 commit comments

Comments
 (0)