fix(app-removal): detect WinGet uninstall failures by exit code, not English text (#658)

This commit is contained in:
HetCreep
2026-06-22 19:53:45 +07:00
committed by GitHub
parent ac54bde383
commit a6d59c0dc1

View File

@@ -82,12 +82,17 @@ function RemoveApps {
} }
else { else {
# Uninstall app via WinGet # Uninstall app via WinGet
$wingetOutput = Invoke-NonBlocking -ScriptBlock { $wingetResult = Invoke-NonBlocking -ScriptBlock {
param($appId) param($appId)
winget uninstall --accept-source-agreements --disable-interactivity --id $appId $global:LASTEXITCODE = 0
$output = winget uninstall --accept-source-agreements --disable-interactivity --id $appId
[PSCustomObject]@{ ExitCode = $LASTEXITCODE; Output = $output }
} -ArgumentList $app } -ArgumentList $app
$wingetFailed = Select-String -InputObject $wingetOutput -Pattern "Uninstall failed with exit code|No installed package found matching input criteria|No package found matching input criteria" -SimpleMatch:$false # winget reports success/failure via its exit code, which is locale-independent.
# The previous match on English console text silently passed on non-English Windows.
# Treat a null result (timed out / not run) or any non-zero exit code as a failure.
$wingetFailed = ($null -eq $wingetResult) -or ($wingetResult.ExitCode -ne 0)
if ($isEdgeId) { if ($isEdgeId) {
if (-not $wingetFailed) { if (-not $wingetFailed) {
$edgeUninstallSucceeded = $true $edgeUninstallSucceeded = $true
@@ -117,6 +122,9 @@ function RemoveApps {
} }
} }
} }
elseif ($wingetFailed) {
Write-Host "Unable to uninstall $app via WinGet" -ForegroundColor Red
}
} }
continue continue