Skip to content

Commit

Permalink
[CmdNotFound]Improve installation workflow (#30727)
Browse files Browse the repository at this point in the history
* [CmdNotFound]Improve installation workflow

* Fix typo

* Fix XAML styling

* Update src/settings-ui/Settings.UI/SettingsXAML/Views/CmdNotFoundPage.xaml

Co-authored-by: Davide Giacometti <[email protected]>

* Update src/settings-ui/Settings.UI/SettingsXAML/Views/CmdNotFoundPage.xaml

Co-authored-by: Davide Giacometti <[email protected]>

* Update src/settings-ui/Settings.UI/SettingsXAML/Views/CmdNotFoundPage.xaml

Co-authored-by: Davide Giacometti <[email protected]>

* Update src/settings-ui/Settings.UI/SettingsXAML/Views/CmdNotFoundPage.xaml

Co-authored-by: Davide Giacometti <[email protected]>

* Update src/settings-ui/Settings.UI/SettingsXAML/Views/CmdNotFoundPage.xaml

Co-authored-by: Davide Giacometti <[email protected]>

* Update src/settings-ui/Settings.UI/SettingsXAML/Views/CmdNotFoundPage.xaml

Co-authored-by: Davide Giacometti <[email protected]>

* Don't create window for checking requirements

* Hide install/uninstall buttons for CmdNotFound module

* Also install winget before Powershell 7

* Better detect processor architecture

* Fix spellcheck

* [CMDNotFound] UX improvements (#30740)

* UI improvements

* Updated label

* Update CmdNotFoundPage.xaml

* Update CmdNotFoundPage.xaml

* Update CmdNotFoundPage.xaml

* Better version detection

* Add some logging

* Add missing package install that's a prerequisite for winget

* Remove unused AllExperiments include

* Fix Logger library include

* Update PATH Environment variable after installing PS

* Fix OOBE UI spacing

* Use Invoke-WebRequest to get the deps and then install them from local path

* Spellcheck

* TEMP -> TMP

* User path is supposed to come after machine path

---------

Co-authored-by: Davide Giacometti <[email protected]>
Co-authored-by: Niels Laute <[email protected]>
Co-authored-by: Stefan Markovic <[email protected]>
  • Loading branch information
4 people committed Jan 5, 2024
1 parent 5f2d821 commit a7907ff
Show file tree
Hide file tree
Showing 12 changed files with 456 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ Kybd
languagesjson
lastcodeanalysissucceeded
Lastdevice
LASTEXITCODE
LAYOUTRTL
LCIDTo
lcl
Expand Down Expand Up @@ -917,6 +918,7 @@ MSIFASTINSTALL
MSIHANDLE
msiquery
MSIRESTARTMANAGERCONTROL
msixbundle
MSIXCA
MSLLHOOKSTRUCT
Mso
Expand Down
3 changes: 3 additions & 0 deletions installer/PowerToysSetup/Settings.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
</RegistryKey>
<File Id="CommandNotFound_Scripts_EnableModule.ps1" Source="$(var.SettingsV2AssetsFilesPath)\Scripts\EnableModule.ps1" />
<File Id="CommandNotFound_Scripts_DisableModule.ps1" Source="$(var.SettingsV2AssetsFilesPath)\Scripts\DisableModule.ps1" />
<File Id="CommandNotFound_Scripts_CheckCmdNotFoundRequirements.ps1" Source="$(var.SettingsV2AssetsFilesPath)\Scripts\CheckCmdNotFoundRequirements.ps1" />
<File Id="CommandNotFound_Scripts_InstallWinGetClientModule.ps1" Source="$(var.SettingsV2AssetsFilesPath)\Scripts\InstallWinGetClientModule.ps1" />
<File Id="CommandNotFound_Scripts_InstallPowerShell7.ps1" Source="$(var.SettingsV2AssetsFilesPath)\Scripts\InstallPowerShell7.ps1" />
</Component>
</DirectoryRef>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Write-Host $PSVersionTable
if ($PSVersionTable.PSVersion -ge 7.4)
{
Write-Host "PowerShell 7.4 or greater detected."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
else
{
Write-Host "PowerShell 7.4 or greater not detected. Installation instructions can be found on https://learn.microsoft.com/powershell/scripting/install/installing-powershell-on-windows `r`n"
# 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)
{
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 not detected. Installation instructions can be found on https://www.powershellgallery.com/packages/Microsoft.WinGet.Client `r`n"
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}

if (!(Test-Path $PROFILE))
{
Write-Host "Profile file $PROFILE not found".
New-Item -Path $PROFILE -ItemType File
Write-Host "Created profile file $PROFILE".
}

$profileContent = Get-Content -Path $PROFILE -Raw

if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756")))
{
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.
}
else
{
Write-Host "Command Not Found module is not registered in the profile file."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ if($atLeastOneInstanceFound)
{
Set-Content -Path $PROFILE -Value $newContent
Write-Host "Removed the Command Not Found reference from the profile file."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
} else {
Write-Host "No instance of Command Not Found was found in the profile file."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ $profileContent = Get-Content -Path $PROFILE -Raw
if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756")))
{
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"
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.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

if ((Get-AppxPackage microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.21")
{
Write-Host "Detected winget. Will try to install PowerShell."
}
else
{
Write-Host "WinGet not detected. Will try to install."
# To speed up Invoke-WebRequest. Older versions are very slow when printing the progress.
$ProgressPreference = 'SilentlyContinue'
$cpuArchitecture="x64"
$detectedArchitecture=""
if ($env:PROCESSOR_ARCHITEW6432 -eq $null) {
$detectedArchitecture=$env:PROCESSOR_ARCHITECTURE
} else {
$detectedArchitecture=$env:PROCESSOR_ARCHITEW6432
}
Write-Host "Detected the CPU architecture:$detectedArchitecture"
if ($detectedArchitecture -ne "AMD64")
{
Write-Host "Mismatch with AMD64, setting it to arm64, since that's where we're likely running."
$cpuArchitecture="arm64"
}
if((Get-AppxPackage Microsoft.VCLibs.140.00).Version -ge [System.Version]"14.0.30704")
{
Write-Host "Detected Microsoft.VCLibs.140.00."
}
else
{
Write-Host "Microsoft.VCLibs.140.00 not detected. Will try to install."
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.$cpuArchitecture.14.00.Desktop.appx -OutFile "$Env:TMP\Microsoft.VCLibs.14.00.appx"
Add-AppxPackage -Path "$Env:TMP\Microsoft.VCLibs.14.00.appx"
Remove-Item -Path "$Env:TMP\Microsoft.VCLibs.14.00.appx" -Force
}
if((Get-AppxPackage Microsoft.VCLibs.140.00.UWPDesktop).Version -ge [System.Version]"14.0.30704")
{
Write-Host "Detected Microsoft.VCLibs.140.00.UWPDesktop"
}
else
{
Write-Host "Microsoft.VCLibs.140.00.UWPDesktop not detected. Will try to install."
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.$cpuArchitecture.14.00.Desktop.appx -OutFile "$Env:TMP\Microsoft.VCLibs.14.00.Desktop.appx"
Add-AppxPackage -Path "$Env:TMP\Microsoft.VCLibs.14.00.Desktop.appx"
Remove-Item -Path "$Env:TMP\Microsoft.VCLibs.14.00.Desktop.appx" -Force
}
if (Get-AppxPackage Microsoft.UI.Xaml.2.7)
{
Write-Host "Detected Microsoft.UI.Xaml.2.7"
}
else
{
Write-Host "Microsoft.UI.Xaml.2.7 not detected. Will try to install."
Write-Host "Downloading to $Env:TMP\microsoft.ui.xaml.2.7.3.zip"
Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.3 -OutFile "$Env:TMP\microsoft.ui.xaml.2.7.3.zip"
Write-Host "Extracting $Env:TMP\microsoft.ui.xaml.2.7.3.zip"
Expand-Archive "$Env:TMP\microsoft.ui.xaml.2.7.3.zip" -DestinationPath "$Env:TMP\microsoft.ui.xaml.2.7.3"
Write-Host "Installing $Env:TMP\microsoft.ui.xaml.2.7.3\tools\AppX\$cpuArchitecture\Release\Microsoft.UI.Xaml.2.7.appx"
Add-AppxPackage "$Env:TMP\microsoft.ui.xaml.2.7.3\tools\AppX\$cpuArchitecture\Release\Microsoft.UI.Xaml.2.7.appx"
Remove-Item -Path "$Env:TMP\microsoft.ui.xaml.2.7.3" -Recurse -Force
Remove-Item -Path "$Env:TMP\microsoft.ui.xaml.2.7.3.zip" -Force
}
Write-Host "Getting winget to the latest stable"
Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile "$Env:TMP\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
Add-AppxPackage -Path "$Env:TMP\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
Remove-Item -Path "$Env:TMP\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force

#winget is not visible right away, so reload the PATH variable.
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
}

winget install Microsoft.PowerShell --source winget
if ($LASTEXITCODE -eq 0)
{
Write-Host "Powershell 7 successfully installed."
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
else
{
Write-Host "Powershell 7 was not installed."
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if (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.
}
else {
Install-Module -Name Microsoft.WinGet.Client
if (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.
} else {
Write-Host "WinGet Client module not detected. Installation instructions can be found on https://www.powershellgallery.com/packages/Microsoft.WinGet.Client `r`n"
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
}
}
35 changes: 22 additions & 13 deletions src/settings-ui/Settings.UI/PowerToys.Settings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,28 @@
<NoWarn>VSTHRD002;VSTHRD110;VSTHRD100;VSTHRD200;VSTHRD101</NoWarn>
</PropertyGroup>

<ItemGroup>
<None Update="Assets\Settings\icon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="Assets\Settings\icon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Update="Assets\Settings\Scripts\EnableModule.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\Settings\Scripts\DisableModule.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="Assets\Settings\Scripts\CheckCmdNotFoundRequirements.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\Settings\Scripts\InstallWinGetClientModule.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\Settings\Scripts\InstallPowerShell7.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\Settings\Scripts\EnableModule.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\Settings\Scripts\DisableModule.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<controls:OOBEPageControl x:Uid="Oobe_CmdNotFound" HeroImage="ms-appx:///Assets/Settings/Modules/OOBE/CmdNotFound.png">

<controls:OOBEPageControl.PageContent>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Vertical" Spacing="12">
<TextBlock x:Uid="Oobe_HowToUse" Style="{ThemeResource OobeSubtitleStyle}" />

<controls:ShortcutWithTextLabelControl x:Name="HotkeyControl" x:Uid="Oobe_CmdNotFound_HowToUse" />
<toolkitcontrols:MarkdownTextBlock x:Uid="Oobe_CmdNotFound_HowToUse" Background="Transparent" />

<StackPanel
Margin="0,24,0,0"
Expand Down
Loading

0 comments on commit a7907ff

Please sign in to comment.