2026-07-19 22:06:07 +02:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Loads application details from Apps.json.
|
|
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
Reads the application definitions from Apps.json, optionally filters the
|
|
|
|
|
results to installed applications, and returns normalized app objects for
|
|
|
|
|
display and selection.
|
|
|
|
|
|
|
|
|
|
.PARAMETER OnlyInstalled
|
|
|
|
|
Filters the results to applications detected through Appx or the supplied
|
|
|
|
|
winget installation list.
|
|
|
|
|
|
|
|
|
|
.PARAMETER InstalledList
|
|
|
|
|
A pre-fetched winget installation list used when filtering installed apps.
|
|
|
|
|
|
|
|
|
|
.PARAMETER InitialCheckedFromJson
|
|
|
|
|
Sets each returned app's IsChecked value from its SelectedByDefault setting.
|
|
|
|
|
|
|
|
|
|
.OUTPUTS
|
|
|
|
|
System.Management.Automation.PSCustomObject[]
|
|
|
|
|
Application detail objects containing display, selection, and removal data.
|
|
|
|
|
#>
|
|
|
|
|
function Import-AppDetailsFromJson {
|
2026-02-15 23:08:54 +01:00
|
|
|
param (
|
|
|
|
|
[switch]$OnlyInstalled,
|
2026-06-22 22:13:01 +02:00
|
|
|
[object[]]$InstalledList = $null,
|
2026-02-15 23:08:54 +01:00
|
|
|
[switch]$InitialCheckedFromJson
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$apps = @()
|
|
|
|
|
try {
|
|
|
|
|
$jsonContent = Get-Content -Path $script:AppsListFilePath -Raw | ConvertFrom-Json
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
Write-Error "Failed to read Apps.json: $_"
|
|
|
|
|
return $apps
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($appData in $jsonContent.Apps) {
|
2026-03-23 22:59:04 +01:00
|
|
|
# Handle AppId as array (could be single or multiple IDs)
|
2026-07-19 22:06:07 +02:00
|
|
|
$appIdArray = @(
|
|
|
|
|
foreach ($rawAppId in @($appData.AppId)) {
|
|
|
|
|
if ($rawAppId -isnot [string]) { continue }
|
|
|
|
|
$normalizedAppId = $rawAppId.Trim()
|
|
|
|
|
if ($normalizedAppId.Length -gt 0) { $normalizedAppId }
|
|
|
|
|
}
|
|
|
|
|
)
|
2026-03-23 22:59:04 +01:00
|
|
|
if ($appIdArray.Count -eq 0) { continue }
|
2026-02-15 23:08:54 +01:00
|
|
|
|
|
|
|
|
if ($OnlyInstalled) {
|
2026-03-23 22:59:04 +01:00
|
|
|
$isInstalled = $false
|
|
|
|
|
foreach ($appId in $appIdArray) {
|
2026-06-22 22:13:01 +02:00
|
|
|
# Check Get-AppxPackage first (fast, no process launch)
|
|
|
|
|
if (Get-AppxPackage -Name $appId) {
|
2026-03-23 22:59:04 +01:00
|
|
|
$isInstalled = $true
|
|
|
|
|
break
|
|
|
|
|
}
|
2026-06-22 22:13:01 +02:00
|
|
|
|
|
|
|
|
# Then check the pre-fetched winget list
|
|
|
|
|
if ($InstalledList -and (Test-AppInWingetList -appId $appId -InstalledList $InstalledList)) {
|
2026-06-22 20:10:53 +07:00
|
|
|
$isInstalled = $true
|
2026-03-23 22:59:04 +01:00
|
|
|
break
|
|
|
|
|
}
|
2026-02-15 23:08:54 +01:00
|
|
|
}
|
2026-06-22 22:13:01 +02:00
|
|
|
|
2026-03-23 22:59:04 +01:00
|
|
|
if (-not $isInstalled) { continue }
|
2026-02-15 23:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-23 22:59:04 +01:00
|
|
|
# Use first AppId for fallback names, join all for display
|
|
|
|
|
$primaryAppId = $appIdArray[0]
|
|
|
|
|
$appIdDisplay = $appIdArray -join ', '
|
|
|
|
|
$friendlyName = if ($appData.FriendlyName) { $appData.FriendlyName } else { $primaryAppId }
|
|
|
|
|
$displayName = if ($appData.FriendlyName) { "$($appData.FriendlyName) ($appIdDisplay)" } else { $appIdDisplay }
|
2026-02-15 23:08:54 +01:00
|
|
|
$isChecked = if ($InitialCheckedFromJson) { $appData.SelectedByDefault } else { $false }
|
|
|
|
|
|
|
|
|
|
$apps += [PSCustomObject]@{
|
2026-03-23 22:59:04 +01:00
|
|
|
AppId = $appIdArray
|
|
|
|
|
AppIdDisplay = $appIdDisplay
|
2026-02-18 00:26:10 +01:00
|
|
|
FriendlyName = $friendlyName
|
2026-02-15 23:08:54 +01:00
|
|
|
DisplayName = $displayName
|
|
|
|
|
IsChecked = $isChecked
|
|
|
|
|
Description = $appData.Description
|
|
|
|
|
SelectedByDefault = $appData.SelectedByDefault
|
2026-03-15 22:58:06 +01:00
|
|
|
Recommendation = $appData.Recommendation
|
2026-06-22 22:13:01 +02:00
|
|
|
RemovalMethod = if ($appData.RemovalMethod -and $appData.RemovalMethod -eq 'WinGet') { 'WinGet' } else { 'Appx' }
|
2026-02-15 23:08:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $apps
|
|
|
|
|
}
|