Skip to content

Commit

Permalink
Added timeout to loading appslist from winget (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphire committed Apr 1, 2024
1 parent 989aa8d commit f878ebf
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Win11Debloat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,18 @@ function ShowAppSelectionForm {
$listOfApps = ""

if ($onlyInstalledCheckBox.Checked -and ($global:wingetInstalled -eq $true)) {
# Get list of installed apps via winget
$listOfApps = winget list --accept-source-agreements --disable-interactivity
# Attempt to get a list of installed apps via winget, times out after 10 seconds
$job = Start-Job { return winget list --accept-source-agreements --disable-interactivity }
$jobDone = $job | Wait-Job -TimeOut 10

if (-not $jobDone) {
# Show error that the script was unable to get list of apps from winget
[System.Windows.MessageBox]::Show('Unable to load list of installed apps via winget, some apps may not be displayed in the list.','Error','Ok','Error')
}
else {
# Add output of job (list of apps) to $listOfApps
$listOfApps = Receive-Job -Job $job
}
}

# Go through appslist and add items one by one to the selectionBox
Expand Down Expand Up @@ -270,7 +280,7 @@ function RemoveApps {
}
else {
# Uninstall app via winget
winget uninstall --accept-source-agreements --id $app
winget uninstall --accept-source-agreements --disable-interactivity --id $app
}
}
else {
Expand Down Expand Up @@ -424,11 +434,10 @@ function PrintFromFile {


# Check if winget is installed
try {
$global:wingetVersion = winget -v
if (Get-AppxPackage -Name "*Microsoft.DesktopAppInstaller*") {
$global:wingetInstalled = $true
}
catch {
else {
$global:wingetInstalled = $false
}

Expand Down

0 comments on commit f878ebf

Please sign in to comment.