[Fixes] Improve Error Handling + UI (#3437)

* add proper error handling + Taskbaritem support to WPFSystemRepair

* implement other fixes

- add Taskbarprogress to WPFFixesNetwork
- add Taskbarprogress to WPFFixesUpdate
- add Error handling + Taskbarprogress to WPFFixesWinget
- add finalisation in WPFSystemRepair
This commit is contained in:
MyDrift
2025-06-26 20:35:03 +02:00
committed by GitHub
parent 686e65adcb
commit 5e65505007
4 changed files with 50 additions and 16 deletions

View File

@ -8,13 +8,20 @@ function Invoke-WPFFixesNetwork {
Write-Host "Resetting Network with netsh"
Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo"
# Reset WinSock catalog to a clean state
Start-Process -NoNewWindow -FilePath "netsh" -ArgumentList "winsock", "reset"
Set-WinUtilTaskbaritem -state "Normal" -value 0.35 -overlay "logo"
# Resets WinHTTP proxy setting to DIRECT
Start-Process -NoNewWindow -FilePath "netsh" -ArgumentList "winhttp", "reset", "proxy"
Set-WinUtilTaskbaritem -state "Normal" -value 0.7 -overlay "logo"
# Removes all user configured IP settings
Start-Process -NoNewWindow -FilePath "netsh" -ArgumentList "int", "ip", "reset"
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
Write-Host "Process complete. Please reboot your computer."
$ButtonType = [System.Windows.MessageBoxButton]::OK

View File

@ -30,6 +30,8 @@ function Invoke-WPFFixesUpdate {
param($Aggressive = $false)
Write-Progress -Id 0 -Activity "Repairing Windows Update" -PercentComplete 0
Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
Write-Host "Starting Windows Update Repair..."
# Wait for the first progress bar to show, otherwise the second one won't show
Start-Sleep -Milliseconds 200
@ -190,12 +192,15 @@ function Invoke-WPFFixesUpdate {
try {
(New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow()
} catch {
Set-WinUtilTaskbaritem -state "Error" -overlay "warning"
Write-Warning "Failed to create Windows Update COM object: $_"
}
Start-Process -NoNewWindow -FilePath "wuauclt" -ArgumentList "/resetauthorization", "/detectnow"
Write-Progress -Id 10 -ParentId 0 -Activity "Forcing discovery" -Status "Completed" -PercentComplete 100
Write-Progress -Id 0 -Activity "Repairing Windows Update" -Status "Completed" -PercentComplete 100
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
$ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageboxTitle = "Reset Windows Update "
$Messageboxbody = ("Stock settings loaded.`n Please reboot your computer")

View File

@ -8,7 +8,16 @@ function Invoke-WPFFixesWinget {
BravoNorris for the fantastic idea of a button to reinstall winget
#>
# Install Choco if not already present
try {
Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
Install-WinUtilChoco
Start-Process -FilePath "choco" -ArgumentList "install winget -y --force" -NoNewWindow -Wait
} catch {
Write-Error "Failed to install winget: $_"
Set-WinUtilTaskbaritem -state "Error" -overlay "warning"
} finally {
Write-Host "==> Finished Winget Repair"
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
}
}

View File

@ -104,6 +104,9 @@ function Invoke-WPFSystemRepair {
Write-Progress -Id 1 -Activity $childProgressBarActivity -Status "DISM Completed" -PercentComplete 100 -Completed
}
try {
Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
$childProgressBarActivity = "Scanning for corruption"
Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 0
# Step 1: Run chkdsk to fix disk and filesystem corruption before proceeding with system file repairs
@ -121,4 +124,14 @@ function Invoke-WPFSystemRepair {
# Step 4: Run SFC again to ensure system files are repaired using the now-fixed system image
Invoke-SFC
Write-Progress -Id 0 -Activity "Repairing Windows" -PercentComplete 100 -Completed
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
} catch {
Write-Error "An error occurred while repairing the system: $_"
Set-WinUtilTaskbaritem -state "Error" -overlay "warning"
} finally {
Write-Host "==> Finished System Repair"
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
}
}