This commit is contained in:
GabiNun2
2026-06-21 18:43:10 +03:00
parent 04858ff849
commit 4587ffaaca
+11 -21
View File
@@ -1,37 +1,27 @@
function Invoke-WPFAppxRemoval { function Invoke-WPFAppxRemoval {
<#
.SYNOPSIS
Removes the selected AppX packages in a background runspace.
#>
if ($sync.ProcessRunning) { if ($sync.ProcessRunning) {
$msg = "A process is currently running. Please wait for it to finish." [System.Windows.MessageBox]::Show("A process is currently running.", "Winutil", "OK", "Warning")
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
return return
} }
$selected = @($sync.selectedAppx) $selected = @($sync.selectedAppx)
if ($selected.Count -eq 0) { if (-not $selected) {
$msg = "Please select the AppX packages you wish to remove." [System.Windows.MessageBox]::Show("Select AppX packages to remove.", "Winutil", "OK", "Warning")
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
return return
} }
$totalSteps = $selected.Count $apps = $sync.configs.appxHashtable
$completedSteps = 0
$handle = Invoke-WPFRunspace -ParameterList @(("selected", $selected), ("completedSteps", $completedSteps), ("totalSteps", $totalSteps)) -ScriptBlock { Invoke-WPFRunspace -ParameterList @(("selected", $selected),("apps", $apps)) -ScriptBlock {
param($selected, $completedSteps, $totalSteps) param($selected, $apps)
$sync.ProcessRunning = $true $sync.ProcessRunning = $true
for ($i = 0; $i -lt $selected.Count; $i++) { foreach ($key in $selected) {
$key = $selected[$i] $package = $apps[$key].PackageId
$appInfo = $sync.configs.appxHashtable.$key
$packageId = $appInfo.PackageId
Write-Host "Removing $packageId" Write-Host "Removing $package"
Get-AppxPackage -Name $packageId -AllUsers | Remove-AppxPackage -AllUsers Get-AppxPackage -Name $package -AllUsers | Remove-AppxPackage -AllUsers
} }
$sync.ProcessRunning = $false $sync.ProcessRunning = $false
@@ -40,4 +30,4 @@ function Invoke-WPFAppxRemoval {
Write-Host "-- AppX Removal Finished ---" Write-Host "-- AppX Removal Finished ---"
Write-Host "=================================" Write-Host "================================="
} }
} }