[CommandNotFound]Upgrade to use PSGallery release and support arm64 (#32766)

* [CommandNotFound] Add support for upgrading the module

* upgrade module as a part of upgrade installation; actually set content in EnableModule.ps1

* Fix XAML style to pass CI

* Remove CmdNotFound project from sln as well

* Remove CmdNotFound psd1 file from installer

* More installer fixes

* UpgradeCommandNotFound runs after InstallFiles

* Fix NOTICE.md

* Fix custom action condition

* Pass install folder to the custom action

* Upgrade-Module --> Update-Module

* actually install the module

* spell

* verify updated scripts work; make necessary changes

---------

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
Carlos Zamora
2024-05-16 05:45:06 -07:00
committed by GitHub
parent 07ca6c8e62
commit e1832a0a4a
28 changed files with 188 additions and 540 deletions

View File

@@ -10,10 +10,25 @@ else
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
if (Get-Module -ListAvailable -Name Microsoft.WinGet.Client)
if ($mods = Get-Module -ListAvailable -Name Microsoft.WinGet.Client)
{
Write-Host "WinGet Client module detected."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
$needsUpdate = $true;
foreach ($mod in $mods)
{
if ($mod.Version -ge "1.8.1133")
{
$needsUpdate = $false;
break;
}
}
if ($needsUpdate)
{
Write-Host "WinGet Client module needs to be updated."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
}
else {
Write-Host "WinGet Client module not detected. Installation instructions can be found on https://www.powershellgallery.com/packages/Microsoft.WinGet.Client `r`n"
@@ -30,6 +45,11 @@ if (!(Test-Path $PROFILE))
$profileContent = Get-Content -Path $PROFILE -Raw
if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756")))
{
Write-Host "Outdated version of Command Not Found module found in the profile file."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
elseif ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("f45873b3-b655-43a6-b217-97c00aa0db58")))
{
Write-Host "Command Not Found module is registered in the profile file."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.

View File

@@ -5,14 +5,14 @@ $linesToDeleteFound = $False
$atLeastOneInstanceFound = $False
$profileContent | ForEach-Object {
if ($_.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756") -and !$linesToDeleteFound)
if (($_.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756") -or $_.Contains("f45873b3-b655-43a6-b217-97c00aa0db58")) -and !$linesToDeleteFound)
{
$linesToDeleteFound = $True
$atLeastOneInstanceFound = $True
return
}
if ($_.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756") -and $linesToDeleteFound)
if (($_.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756") -or $_.Contains("f45873b3-b655-43a6-b217-97c00aa0db58")) -and $linesToDeleteFound)
{
$linesToDeleteFound = $False
return

View File

@@ -9,13 +9,36 @@ Enable-ExperimentalFeature PSFeedbackProvider
Write-Host "Enabling experimental feature: PSCommandNotFoundSuggestion"
Enable-ExperimentalFeature PSCommandNotFoundSuggestion
if (Get-Module -ListAvailable -Name Microsoft.WinGet.Client) {
$wingetModules = Get-Module -ListAvailable -Name Microsoft.WinGet.Client
if ($wingetModules) {
$moduleUpToDate = $false;
foreach ($mod in $wingetModules) {
if ($mod.Version -ge "1.8.1133") {
$moduleUpToDate = $true;
break;
}
}
if ($moduleUpToDate) {
Write-Host "WinGet Client module detected"
} else {
Write-Host "WinGet module needs to be updated. Run `"Update-Module -Name Microsoft.WinGet.Client`" to update `r`n"
}
}
else {
Write-Host "WinGet module was not found. Installation instructions can be found on https://www.powershellgallery.com/packages/Microsoft.WinGet.Client `r`n"
}
$CNFModule = Get-Module -ListAvailable -Name Microsoft.WinGet.CommandNotFound
if ($CNFModule) {
Write-Host "Microsoft.WinGet.CommandNotFound module detected"
} else {
Write-Host "Microsoft.WinGet.CommandNotFound was not found. Installing...`r`n"
Install-Module -Name Microsoft.WinGet.CommandNotFound -Force
Write-Host "Microsoft.WinGet.CommandNotFound module installed`r`n"
}
if (!(Test-Path $PROFILE))
{
Write-Host "Profile file $PROFILE not found".
@@ -26,15 +49,28 @@ if (!(Test-Path $PROFILE))
$profileContent = Get-Content -Path $PROFILE -Raw
if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756")))
{
if ($profileContent.Contains("Import-Module `"$scriptPath\WinGetCommandNotFound.psd1`""))
{
$profileContent = $profileContent.Replace("Import-Module `"$scriptPath\WinGetCommandNotFound.psd1`"",
"Import-Module -Name Microsoft.WinGet.CommandNotFound")
$profileContent = $profileContent.Replace("34de4b3d-13a8-4540-b76d-b9e8d3851756",
"f45873b3-b655-43a6-b217-97c00aa0db58")
Set-Content -Path $PROFILE -Value $profileContent
Write-Host "Module was successfully upgraded in the profile file."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
}
elseif ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("f45873b3-b655-43a6-b217-97c00aa0db58")))
{
Write-Host "Module is already registered in the profile file."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
else
{
Add-Content -Path $PROFILE -Value "`r`n#34de4b3d-13a8-4540-b76d-b9e8d3851756 PowerToys CommandNotFound module"
Add-Content -Path $PROFILE -Value "`r`nImport-Module `"$scriptPath\WinGetCommandNotFound.psd1`""
Add-Content -Path $PROFILE -Value "#34de4b3d-13a8-4540-b76d-b9e8d3851756"
Add-Content -Path $PROFILE -Value "`r`n#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module"
Add-Content -Path $PROFILE -Value "`r`nImport-Module -Name Microsoft.WinGet.CommandNotFound"
Add-Content -Path $PROFILE -Value "#f45873b3-b655-43a6-b217-97c00aa0db58"
Write-Host "Module was successfully registered in the profile file."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}

View File

@@ -1,7 +1,46 @@
if (Get-Module -ListAvailable -Name Microsoft.WinGet.Client)
$wingetModules = Get-Module -ListAvailable -Name Microsoft.WinGet.Client
if ($wingetModules)
{
Write-Host "WinGet Client module detected."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
$needsUpdate = $true;
foreach ($mod in $wingetModules)
{
if ($mod.Version -ge "1.8.1133")
{
$needsUpdate = $false;
break;
}
}
if ($needsUpdate)
{
Update-Module -Name Microsoft.WinGet.Client -Force
$wingetModules = Get-Module -ListAvailable -Name Microsoft.WinGet.Client
$updated = $false;
foreach ($mod in $wingetModules)
{
if ($mod.Version -ge "1.8.1133")
{
$updated = $true;
break;
}
}
if ($updated)
{
Write-Host "WinGet Client module updated."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
else
{
Write-Host "WinGet Client module detected."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
}
else
{
Write-Host "WinGet Client module detected."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
}
else {
Install-Module -Name Microsoft.WinGet.Client

View File

@@ -0,0 +1,29 @@
if (!(Test-Path $PROFILE))
{
return;
}
$profileContent = Get-Content -Path $PROFILE -Raw
$legacyGuid = "34de4b3d-13a8-4540-b76d-b9e8d3851756"
if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains($legacyGuid)))
{
# Upgrade Microsoft.WinGet.Client module
$wingetModule = Get-Module -ListAvailable -Name Microsoft.WinGet.Client
if ($wingetModule -and $wingetModule.Version -lt "1.8.1133") {
Update-Module -Name Microsoft.WinGet.Client
}
# Install Microsoft.WinGet.CommandNotFound module
if (-Not (Get-Module -ListAvailable -Name Microsoft.WinGet.CommandNotFound)) {
Install-Module -Name Microsoft.WinGet.CommandNotFound -Force
}
# Replace old module with new one (and new GUID comment)
$regex = "Import-Module .*WinGetCommandNotFound.psd1`""
if ($profileContent -match $regex)
{
$profileContent = $profileContent -replace $regex, "Import-Module -Name Microsoft.WinGet.CommandNotFound"
$profileContent = $profileContent -replace $legacyGuid, "f45873b3-b655-43a6-b217-97c00aa0db58"
Set-Content -Path $PROFILE -Value $profileContent
}
}

View File

@@ -17,10 +17,7 @@
TrueValue="Collapsed" />
<tkconverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
</Page.Resources>
<controls:SettingsPageControl
x:Uid="CmdNotFound"
IsEnabled="{x:Bind ViewModel.IsArm64Arch, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}"
ModuleImageSource="ms-appx:///Assets/Settings/Modules/CmdNotFound.png">
<controls:SettingsPageControl x:Uid="CmdNotFound" ModuleImageSource="ms-appx:///Assets/Settings/Modules/CmdNotFound.png">
<controls:SettingsPageControl.ModuleContent>
<StackPanel ChildrenTransitions="{StaticResource SettingsCardsAnimations}" Orientation="Vertical">
<InfoBar
@@ -65,7 +62,7 @@
BorderThickness="0"
CornerRadius="0"
IsClosable="False"
IsOpen="{x:Bind Mode=OneWay, Path=ViewModel.IsArm64Arch, Converter={StaticResource BoolNegationConverter}}">
IsOpen="True">
<InfoBar.ActionButton>
<HyperlinkButton x:Uid="CmdNotFound_CheckCompatibility" Command="{x:Bind ViewModel.CheckRequirementsEventHandler}">
<ToolTipService.ToolTip>
@@ -74,16 +71,10 @@
</HyperlinkButton>
</InfoBar.ActionButton>
</InfoBar>
<InfoBar
x:Uid="CmdNotFound_Arm64ArchBar"
BorderThickness="0"
CornerRadius="0"
IsClosable="False"
IsOpen="{x:Bind Mode=OneWay, Path=ViewModel.IsArm64Arch}" />
</StackPanel>
</tkcontrols:SettingsExpander.ItemsHeader>
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard x:Uid="CmdNotFound_PowerShellDetection" Visibility="{x:Bind ViewModel.IsArm64Arch, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
<tkcontrols:SettingsCard x:Uid="CmdNotFound_PowerShellDetection">
<tkcontrols:SwitchPresenter TargetType="x:Boolean" Value="{x:Bind ViewModel.IsPowerShell7Detected, Mode=OneWay}">
<tkcontrols:Case Value="True">
<StackPanel Orientation="Horizontal" Spacing="8">
@@ -113,7 +104,7 @@
</tkcontrols:SwitchPresenter>
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard x:Uid="CmdNotFound_WinGetClientDetection" Visibility="{x:Bind ViewModel.IsArm64Arch, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
<tkcontrols:SettingsCard x:Uid="CmdNotFound_WinGetClientDetection">
<tkcontrols:SwitchPresenter TargetType="x:Boolean" Value="{x:Bind ViewModel.IsWinGetClientModuleDetected, Mode=OneWay}">
<tkcontrols:Case Value="True">
<StackPanel Orientation="Horizontal" Spacing="8">

View File

@@ -4046,9 +4046,6 @@ Activate by holding the key for the character you want to add an accent to, then
<data name="GeneralPage_ShowWhatsNewAfterUpdates.Content" xml:space="preserve">
<value>Show the release notes after an update</value>
</data>
<data name="CmdNotFound_Arm64ArchBar.Title" xml:space="preserve">
<value>Command Not Found is not supported on the ARM64 architecture currently. We are actively working on a solution.</value>
</data>
<data name="QuickAccent_Prevent_Activation_On_Game_Mode.Content" xml:space="preserve">
<value>Do not activate when Game Mode is on</value>
<comment>"Game mode" is the Windows feature to prevent notification when playing a game.</comment>

View File

@@ -129,11 +129,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
get => _enabledStateIsGPOConfigured;
}
public bool IsArm64Arch
{
get => RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.Arm64;
}
public string RunPowerShellOrPreviewScript(string powershellExecutable, string powershellArguments, bool hidePowerShellWindow = false)
{
if (isPowerShellPreviewDetected)
@@ -228,7 +223,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
IsWinGetClientModuleDetected = true;
}
else if (result.Contains("WinGet Client module not detected."))
else if (result.Contains("WinGet Client module not detected.") || result.Contains("WinGet Client module needs to be updated."))
{
IsWinGetClientModuleDetected = false;
}
@@ -237,7 +232,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
IsCommandNotFoundModuleInstalled = true;
}
else if (result.Contains("Command Not Found module is not registered in the profile file."))
else if (result.Contains("Command Not Found module is not registered in the profile file.") || result.Contains("Outdated version of Command Not Found module found in the profile file."))
{
IsCommandNotFoundModuleInstalled = false;
}
@@ -266,7 +261,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
var ps1File = AssemblyDirectory + "\\Assets\\Settings\\Scripts\\InstallWinGetClientModule.ps1";
var arguments = $"-NoProfile -ExecutionPolicy Unrestricted -File \"{ps1File}\"";
var result = RunPowerShellOrPreviewScript("pwsh.exe", arguments);
if (result.Contains("WinGet Client module detected."))
if (result.Contains("WinGet Client module detected.") || result.Contains("WinGet Client module updated."))
{
IsWinGetClientModuleDetected = true;
}
@@ -284,7 +279,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
var arguments = $"-NoProfile -ExecutionPolicy Unrestricted -File \"{ps1File}\" -scriptPath \"{AssemblyDirectory}\\..\"";
var result = RunPowerShellOrPreviewScript("pwsh.exe", arguments);
if (result.Contains("Module is already registered in the profile file.") || result.Contains("Module was successfully registered in the profile file."))
if (result.Contains("Module is already registered in the profile file.")
|| result.Contains("Module was successfully registered in the profile file.")
|| result.Contains("Module was successfully upgraded in the profile file."))
{
IsCommandNotFoundModuleInstalled = true;
PowerToysTelemetry.Log.WriteEvent(new CmdNotFoundInstallEvent());