Introduce Command Not Found module (#26319)

* Introduce Command Not Found module

* rewrite module to depend on WinGet PowerShell module

* address Dongbo's feedback

* try and implement settings UI

* fix SUI build; try and store PowerShell object

* add and use object pool

* apply Dongbo's feedback

* add warm up; implement IPooledObjectPolicy

* Add module interface

* WIP trying to import module from settings

* Add EnableModule.ps1

* spellcheck

* spellcheck again

* Installer. Add DisableModule.ps1

* Fix styling

* Give the user some output from installing

* Prettify the Settings controls

* Add button to check PowerShell 7's version

* Fix Settings Assets paths

* Fix PowerShell 7 output

* Make module enable and disable scripts give better information

* Fix spellcheck

* Fix image files and placeholders

* Don't remove CmdNotFound on upgrade and don't fail on uninstall of
CmdNotFound

* Consistent install module scripts location on debug and installed

* installer: Avoid messageboxes and hide powershell on uninstalling CmdNotFound

* Fix psd1 file resolution when installed

* Fix spellcheck

* Add telemetry events

* Fix gpo files

* If GPO is set, enable/disable module on PT start depending on gpo value

* Cleanup module interface

* Cleanup settings code

* If GPO is set, disable Settings page logic

* Adding icons

* Update settings UI and strings

* Add telemetry for suggestions and feedbacks

* Fix sln file

* Fix build

* minor fixes

* Updating icon

* Remove global.json

* Remove unused PowerShell dependency

* Don't use preview version of Automation and fix NOTICE

* Fix signing

* Fix NOTICE.md

* Fix version checking for getfilesiginforedist.dll

* Fix spellchecker

* Fix README.md

* Fix false positives section in expect.txt

* Add logs to module interface

---------

Co-authored-by: Stefan Markovic <stefan@janeasystems.com>
Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
This commit is contained in:
Carlos Zamora
2024-01-03 07:43:42 -08:00
committed by GitHub
parent 3b90f73bd0
commit 46f5316858
65 changed files with 1633 additions and 63 deletions

View File

@@ -395,6 +395,7 @@ namespace Microsoft.PowerToys.Settings.UI
case "Overview": return typeof(GeneralPage);
case "AlwaysOnTop": return typeof(AlwaysOnTopPage);
case "Awake": return typeof(AwakePage);
case "CmdNotFound": return typeof(CmdNotFoundPage);
case "ColorPicker": return typeof(ColorPickerPage);
case "FancyZones": return typeof(FancyZonesPage);
case "FileLocksmith": return typeof(FileLocksmithPage);

View File

@@ -0,0 +1,32 @@
<Page
x:Class="Microsoft.PowerToys.Settings.UI.OOBE.Views.OobeCmdNotFound"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Microsoft.PowerToys.Settings.UI.OOBE.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkitcontrols="using:CommunityToolkit.WinUI.UI.Controls"
mc:Ignorable="d">
<controls:OOBEPageControl x:Uid="Oobe_CmdNotFound" HeroImage="ms-appx:///Assets/Settings/Modules/OOBE/CmdNotFound.png">
<controls:OOBEPageControl.PageContent>
<StackPanel Orientation="Vertical">
<TextBlock x:Uid="Oobe_HowToUse" Style="{ThemeResource OobeSubtitleStyle}" />
<controls:ShortcutWithTextLabelControl x:Name="HotkeyControl" x:Uid="Oobe_CmdNotFound_HowToUse" />
<StackPanel
Margin="0,24,0,0"
Orientation="Horizontal"
Spacing="12">
<Button x:Uid="OOBE_Settings" Click="SettingsLaunchButton_Click" />
<HyperlinkButton NavigateUri="https://aka.ms/PowerToysOverview_CmdNotFound" Style="{StaticResource TextButtonStyle}">
<TextBlock x:Uid="LearnMore_CmdNotFound" TextWrapping="Wrap" />
</HyperlinkButton>
</StackPanel>
</StackPanel>
</controls:OOBEPageControl.PageContent>
</controls:OOBEPageControl>
</Page>

View File

@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
{
public sealed partial class OobeCmdNotFound : Page
{
public OobePowerToysModule ViewModel { get; set; }
public OobeCmdNotFound()
{
this.InitializeComponent();
ViewModel = new OobePowerToysModule(OobeShellPage.OobeShellHandler.Modules[(int)PowerToysModules.CmdNotFound]);
DataContext = ViewModel;
}
private void SettingsLaunchButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (OobeShellPage.OpenMainWindowCallback != null)
{
OobeShellPage.OpenMainWindowCallback(typeof(CmdNotFoundPage));
}
ViewModel.LogOpeningSettingsEvent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ViewModel.LogOpeningModuleEvent();
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
ViewModel.LogClosingModuleEvent();
}
}
}

View File

@@ -69,6 +69,10 @@
x:Uid="Shell_Awake"
Icon="{ui:BitmapIcon Source=/Assets/Settings/FluentIcons/FluentIconsAwake.png}"
Tag="Awake" />
<NavigationViewItem
x:Uid="Shell_CmdNotFound"
Icon="{ui:BitmapIcon Source=/Assets/Settings/FluentIcons/FluentIconsCmdNotFound.png}"
Tag="CmdNotFound" />
<NavigationViewItem
x:Uid="Shell_ColorPicker"
Icon="{ui:BitmapIcon Source=/Assets/Settings/FluentIcons/FluentIconsColorPicker.png}"

View File

@@ -79,6 +79,11 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
ModuleName = "Awake",
IsNew = false,
});
Modules.Insert((int)PowerToysModules.CmdNotFound, new OobePowerToysModule()
{
ModuleName = "CmdNotFound",
IsNew = true,
});
Modules.Insert((int)PowerToysModules.ColorPicker, new OobePowerToysModule()
{
ModuleName = "ColorPicker",
@@ -250,6 +255,7 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
case "WhatsNew": NavigationFrame.Navigate(typeof(OobeWhatsNew)); break;
case "AlwaysOnTop": NavigationFrame.Navigate(typeof(OobeAlwaysOnTop)); break;
case "Awake": NavigationFrame.Navigate(typeof(OobeAwake)); break;
case "CmdNotFound": NavigationFrame.Navigate(typeof(OobeCmdNotFound)); break;
case "ColorPicker": NavigationFrame.Navigate(typeof(OobeColorPicker)); break;
case "CropAndLock": NavigationFrame.Navigate(typeof(OobeCropAndLock)); break;
case "EnvironmentVariables": NavigationFrame.Navigate(typeof(OobeEnvironmentVariables)); break;

View File

@@ -0,0 +1,60 @@
<Page
x:Class="Microsoft.PowerToys.Settings.UI.Views.CmdNotFoundPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:custom="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:CommunityToolkit.WinUI"
AutomationProperties.LandmarkType="Main"
mc:Ignorable="d">
<custom:SettingsPageControl x:Uid="CmdNotFound" ModuleImageSource="ms-appx:///Assets/Settings/Modules/CmdNotFound.png">
<custom:SettingsPageControl.ModuleContent>
<StackPanel ChildrenTransitions="{StaticResource SettingsCardsAnimations}" Orientation="Vertical">
<InfoBar
x:Uid="GPO_IsSettingForced"
IsClosable="False"
IsOpen="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabledGpoConfigured}"
IsTabStop="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabledGpoConfigured}"
Severity="Informational" />
<controls:SettingsCard
x:Uid="CmdNotFound_Enable"
HeaderIcon="{ui:BitmapIcon Source=/Assets/Settings/FluentIcons/FluentIconsCmdNotFound.png}"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabledGpoConfigured, Converter={StaticResource BoolNegationConverter}}">
<StackPanel Orientation="Horizontal" Spacing="8">
<Button
x:Uid="CmdNotFound_InstallButton"
Command="{x:Bind ViewModel.InstallModuleEventHandler}"
Style="{StaticResource AccentButtonStyle}" />
<HyperlinkButton x:Uid="CmdNotFound_UninstallButton" Command="{x:Bind ViewModel.UninstallModuleEventHandler}" />
</StackPanel>
<controls:SettingsCard.Description>
<StackPanel Orientation="Vertical">
<TextBlock x:Uid="CmdNotFound_Enable_DescriptionText" />
<HyperlinkButton x:Uid="CmdNotFound_CheckCompatibility" Command="{x:Bind ViewModel.CheckPowershellVersionEventHandler}" />
</StackPanel>
</controls:SettingsCard.Description>
</controls:SettingsCard>
<TextBlock
x:Uid="CmdNotFound_ModuleInstallationLogs"
Margin="0,12,0,4"
Style="{ThemeResource BodyStrongTextBlockStyle}" />
<TextBox
Height="300"
FontFamily="Consolas"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabledGpoConfigured, Converter={StaticResource BoolNegationConverter}}"
IsReadOnly="True"
Text="{x:Bind Mode=OneWay, Path=ViewModel.CommandOutputLog}"
TextWrapping="Wrap" />
</StackPanel>
</custom:SettingsPageControl.ModuleContent>
<custom:SettingsPageControl.PrimaryLinks>
<custom:PageLink x:Uid="LearnMore_CmdNotFound" Link="https://aka.ms/PowerToysOverview_CmdNotFound" />
</custom:SettingsPageControl.PrimaryLinks>
</custom:SettingsPageControl>
</Page>

View File

@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public sealed partial class CmdNotFoundPage : Page
{
private CmdNotFoundViewModel ViewModel { get; set; }
public CmdNotFoundPage()
{
ViewModel = new CmdNotFoundViewModel();
DataContext = ViewModel;
InitializeComponent();
}
}
}

View File

@@ -115,6 +115,11 @@
helpers:NavHelper.NavigateTo="views:AwakePage"
Icon="{ui:BitmapIcon Source=/Assets/Settings/FluentIcons/FluentIconsAwake.png}" />
<NavigationViewItem
x:Uid="Shell_CmdNotFound"
helpers:NavHelper.NavigateTo="views:CmdNotFoundPage"
Icon="{ui:BitmapIcon Source=/Assets/Settings/FluentIcons/FluentIconsCmdNotFound.png}" />
<NavigationViewItem
x:Uid="Shell_ColorPicker"
helpers:NavHelper.NavigateTo="views:ColorPickerPage"