mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-10-07 22:16:43 +00:00
Optimize installed app detection (#771)
This commit is contained in:
@@ -37,6 +37,16 @@ function Import-AppDetailsFromJson {
|
||||
return $apps
|
||||
}
|
||||
|
||||
$installedAppNames = @{}
|
||||
if ($OnlyInstalled) {
|
||||
# Get-AppxPackage is expensive; query it once and use its package names for the catalog lookup.
|
||||
foreach ($installedApp in @(Get-AppxPackage -ErrorAction SilentlyContinue)) {
|
||||
if ($installedApp.Name -is [string]) {
|
||||
$installedAppNames[$installedApp.Name] = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($appData in $jsonContent.Apps) {
|
||||
# Handle AppId as array (could be single or multiple IDs)
|
||||
$appIdArray = @(
|
||||
@@ -51,8 +61,7 @@ function Import-AppDetailsFromJson {
|
||||
if ($OnlyInstalled) {
|
||||
$isInstalled = $false
|
||||
foreach ($appId in $appIdArray) {
|
||||
# Check Get-AppxPackage first (fast, no process launch)
|
||||
if (Get-AppxPackage -Name $appId) {
|
||||
if ($installedAppNames.ContainsKey($appId)) {
|
||||
$isInstalled = $true
|
||||
break
|
||||
}
|
||||
|
||||
@@ -187,13 +187,14 @@ Describe 'Import-AppDetailsFromJson' {
|
||||
}
|
||||
|
||||
It 'filters to installed apps using Appx and winget detection' {
|
||||
Mock Get-AppxPackage { param($Name) if ($Name -eq 'Two.App') { [PSCustomObject]@{ Name = $Name } } }
|
||||
Mock Get-AppxPackage { [PSCustomObject]@{ Name = 'Two.App' } }
|
||||
Mock Test-AppInWingetList { $false }
|
||||
|
||||
$apps = @(Import-AppDetailsFromJson -OnlyInstalled -InstalledList @())
|
||||
|
||||
$apps | Should -HaveCount 1
|
||||
$apps[0].AppId | Should -Be 'Two.App'
|
||||
Should -Invoke Get-AppxPackage -Times 1 -Exactly
|
||||
}
|
||||
|
||||
It 'loads presets and preserves their ID arrays' {
|
||||
|
||||
Reference in New Issue
Block a user