diff --git a/README.md b/README.md index 0ac5414..b1b7d0b 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,9 @@ available until its replacement is fully activated, then older versions are remo PDF Presenter is the first portable release package. The desktop profile follows its preview channel, verifies `SHA256SUMS`, and creates a Start menu shortcut at Start → Config Central → idle-org that launches `pdf-presenter.exe` directly -with its embedded icon. It is also registered as a per-user PDF handler. After -the first `cc update-software` or full apply, open its Windows Default Apps page: +with its embedded icon. It is also registered as a per-user PDF handler, with a +separate PDF document icon based on its turquoise presentation mark. After the +first `cc update-software` or full apply, open its Windows Default Apps page: ```powershell Start-Process 'ms-settings:defaultapps?registeredAppUser=ConfigCentral.idle-org.pdf-presenter' diff --git a/TASKS.md b/TASKS.md index af566e1..9ab6fe0 100644 --- a/TASKS.md +++ b/TASKS.md @@ -163,3 +163,4 @@ open until it is run on disposable machines with the required account setups. - [x] Refresh Config Central from an immutable remote snapshot before `update-software` applies portable and declared WinGet updates (163 Linux Pester tests pass; 5 Windows-only skips). - [x] Register PDF Presenter as a per-user `.pdf` handler and document the one-time supported Windows Default Apps selection (167 Linux Pester tests pass; Windows acceptance remains open above). - [x] Remove superseded portable versions after successful activation while retaining the working version on failed updates and retrying interrupted cleanup (168 Linux Pester tests pass; 5 Windows-only skips). +- [x] Give PDF Presenter associations a dedicated branded PDF document icon that remains stable across portable updates (169 Linux Pester tests pass; 5 Windows-only skips). diff --git a/assets/pdf-presenter-pdf.ico b/assets/pdf-presenter-pdf.ico new file mode 100644 index 0000000..bb0ae98 Binary files /dev/null and b/assets/pdf-presenter-pdf.ico differ diff --git a/assets/pdf-presenter-pdf.png b/assets/pdf-presenter-pdf.png new file mode 100644 index 0000000..2975be2 Binary files /dev/null and b/assets/pdf-presenter-pdf.png differ diff --git a/docs/advanced_commands.md b/docs/advanced_commands.md index 0f67622..3f7a737 100644 --- a/docs/advanced_commands.md +++ b/docs/advanced_commands.md @@ -382,11 +382,13 @@ records the active version and hashes. A successful update removes older managed version directories. The working version remains active when download, verification, or setup fails. Removing the profile entry does not uninstall anything. -The package also declares `displayName` and `fileAssociations`, which register -PDF Presenter per user as a `.pdf` handler with Windows Default Apps. The open -command passes the selected PDF directly to the active executable. Windows -requires the user to confirm the protected default-app choice. After applying -the package, open its settings page and select PDF Presenter for `.pdf`: +The package also declares `displayName`, `fileAssociations`, and a dedicated +`fileAssociationIcon`, which register PDF Presenter per user as a `.pdf` handler +with Windows Default Apps. Config Central copies the icon into the stable package +root so Explorer does not depend on a versioned executable. The open command +passes the selected PDF directly to the active executable. Windows requires the +user to confirm the protected default-app choice. After applying the package, +open its settings page and select PDF Presenter for `.pdf`: ```powershell Start-Process 'ms-settings:defaultapps?registeredAppUser=ConfigCentral.idle-org.pdf-presenter' diff --git a/docs/manifest-contract.md b/docs/manifest-contract.md index be7dc75..e6d8daa 100644 --- a/docs/manifest-contract.md +++ b/docs/manifest-contract.md @@ -110,6 +110,10 @@ points each open command and icon at the active verified executable. Config Central does not overwrite Windows' protected default-app user choice; the user selects the registered handler once in Windows Settings or Explorer. +An optional repository-relative `fileAssociationIcon` below `assets/` supplies +a stable `.ico` for associated documents. Config Central copies and verifies it +in the package root instead of pointing Explorer at a versioned executable icon. + Apply downloads and verifies the pinned archive, rejects unsafe ZIP paths and links, stages a new directory, and only then switches the receipt. After activation, older managed version directories are removed. Download, diff --git a/profiles/desktop-apps.json b/profiles/desktop-apps.json index c83834e..7296fa4 100644 --- a/profiles/desktop-apps.json +++ b/profiles/desktop-apps.json @@ -20,7 +20,8 @@ "executableTemplate": "pdf-presenter-portable-x86_64-pc-windows-gnu-v{version}/pdf-presenter.exe", "checksumAsset": "SHA256SUMS", "displayName": "PDF Presenter", - "fileAssociations": [".pdf"] + "fileAssociations": [".pdf"], + "fileAssociationIcon": "assets/pdf-presenter-pdf.ico" }, { "id": "clsid2.mpc-hc", "source": "winget", "scope": "machine", "update": "latest" }, { "id": "XnSoft.XnViewMP", "source": "winget", "scope": "machine", "update": "latest" }, diff --git a/schemas/profile.schema.json b/schemas/profile.schema.json index 585d99c..6010b41 100644 --- a/schemas/profile.schema.json +++ b/schemas/profile.schema.json @@ -130,6 +130,10 @@ "type": "string", "pattern": "^\\.[a-z0-9]{1,16}$" } + }, + "fileAssociationIcon": { + "type": "string", + "pattern": "^assets/[A-Za-z0-9_-][A-Za-z0-9._/-]*\\.ico$" } }, "allOf": [ @@ -191,6 +195,9 @@ "fileAssociations": [ "displayName" ], + "fileAssociationIcon": [ + "fileAssociations" + ], "releaseApi": [ "releaseChannel", "assetTemplate", @@ -245,6 +252,11 @@ "fileAssociations" ] }, + { + "required": [ + "fileAssociationIcon" + ] + }, { "required": [ "executable" diff --git a/src/Manifest.psm1 b/src/Manifest.psm1 index 5c16ede..49736ed 100644 --- a/src/Manifest.psm1 +++ b/src/Manifest.psm1 @@ -72,6 +72,12 @@ function Assert-PortableDeclaration { if ($extension -cnotmatch '^\.[a-z0-9]{1,16}$' -or -not $seenAssociations.Add($extension)) { throw "Invalid or duplicate portable file association '$extension'." } } } + $associationIcon = [string](Get-OptionalProperty $Item 'fileAssociationIcon') + if ($associationIcon) { + if (-not $associations.Count) { throw 'Portable fileAssociationIcon requires fileAssociations.' } + if ($associationIcon -notmatch '^assets/[A-Za-z0-9_-][A-Za-z0-9._/-]*\.ico$' -or + @($associationIcon -split '/' | Where-Object { $_ -in @('', '.', '..') }).Count) { throw 'Unsafe portable fileAssociationIcon path.' } + } $releaseFields = @('releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate') $hasReleaseField = [bool]($releaseFields | Where-Object { $null -ne $Item.PSObject.Properties[$_] }) @@ -110,7 +116,7 @@ function Assert-ItemList { if ($Kind -eq 'package') { Assert-AllowedProperties $item @( 'id', 'source', 'scope', 'version', 'update', 'enabled', 'provider', 'url', 'sha256', 'executable', - 'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations' + 'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations', 'fileAssociationIcon' ) "$Location[$index]" if ([string]::IsNullOrWhiteSpace([string](Get-OptionalProperty $item 'id'))) { throw "$Location[$index].id is required." } $source = [string](Get-OptionalProperty $item 'source' 'winget') @@ -121,7 +127,7 @@ function Assert-ItemList { $key = "portable/$key" Assert-PortableDeclaration $item $source } - elseif (@('url', 'sha256', 'executable', 'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations') | Where-Object { $null -ne $item.PSObject.Properties[$_] }) { throw 'Portable fields cannot be used by WinGet packages.' } + elseif (@('url', 'sha256', 'executable', 'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations', 'fileAssociationIcon') | Where-Object { $null -ne $item.PSObject.Properties[$_] }) { throw 'Portable fields cannot be used by WinGet packages.' } $scope = Get-OptionalProperty $item 'scope' if ($null -ne $scope -and $scope -notin @('user', 'machine')) { throw "Invalid package scope at $Location[$index]." } $update = [string](Get-OptionalProperty $item 'update' 'latest') @@ -192,7 +198,7 @@ function Add-ManifestItems { $normalized = [ordered]@{ id = [string]$item.id; source = $source; update = [string](Get-OptionalProperty $item 'update' 'latest') } foreach ($field in @( 'scope', 'version', 'provider', 'url', 'sha256', 'executable', - 'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations' + 'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations', 'fileAssociationIcon' )) { $value = Get-OptionalProperty $item $field if ($null -ne $value) { diff --git a/src/PortablePackages.psm1 b/src/PortablePackages.psm1 index eb40dc1..2583c35 100644 --- a/src/PortablePackages.psm1 +++ b/src/PortablePackages.psm1 @@ -40,6 +40,7 @@ function Get-PortablePaths { Root = $root Receipt = Join-Path $root 'current.json' Launcher = Join-Path $root 'launch.ps1' + AssociationIcon = Join-Path $root 'file-association.ico' Shortcut = $(if ($programs) { Join-Path $programs "Config Central/$($Package.source)/$($Package.id).lnk" } else { $null }) } } @@ -53,9 +54,20 @@ function Test-PortableLegacyLauncher { (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant() -in $script:LegacyPortableLauncherHashes } +function Get-PortableAssociationIconSource { + param($Package) + if (-not $Package.PSObject.Properties['fileAssociationIcon']) { return $null } + $repositoryRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..')) + $source = [IO.Path]::GetFullPath((Join-Path $repositoryRoot ([string]$Package.fileAssociationIcon))) + if (-not $source.StartsWith(($repositoryRoot.TrimEnd([IO.Path]::DirectorySeparatorChar) + [IO.Path]::DirectorySeparatorChar), [StringComparison]::OrdinalIgnoreCase) -or + -not (Test-Path -LiteralPath $source -PathType Leaf)) { throw "Portable file association icon is missing or outside the repository: '$($Package.fileAssociationIcon)'." } + return $source +} + function Get-PortableAssociationSpec { - param($Package, [Parameter(Mandatory)][string]$Executable) + param($Package, [Parameter(Mandatory)][string]$Executable, [string]$Icon) if (-not $Package.PSObject.Properties['fileAssociations']) { return @() } + if ([string]::IsNullOrWhiteSpace($Icon)) { $Icon = $Executable } $registeredName = "ConfigCentral.$($Package.source).$($Package.id)" $capabilitiesPath = "Software\ConfigCentral\Applications\$($Package.source)\$($Package.id)\Capabilities" foreach ($extension in @($Package.fileAssociations)) { @@ -68,6 +80,7 @@ function Get-PortableAssociationSpec { displayName = [string]$Package.displayName description = "$($Package.displayName) $($suffix.ToUpperInvariant()) document" executable = [IO.Path]::GetFullPath($Executable) + icon = [IO.Path]::GetFullPath($Icon) } } } @@ -89,8 +102,8 @@ function Set-PortableRegistryValue { } function Test-PortableFileAssociations { - param($Package, [Parameter(Mandatory)][string]$Executable) - $specs = @(Get-PortableAssociationSpec -Package $Package -Executable $Executable) + param($Package, [Parameter(Mandatory)][string]$Executable, [string]$Icon) + $specs = @(Get-PortableAssociationSpec -Package $Package -Executable $Executable -Icon $Icon) if (-not $specs.Count) { return $true } if (-not $IsWindows) { return $false } foreach ($spec in $specs) { @@ -99,7 +112,7 @@ function Test-PortableFileAssociations { (Get-PortableRegistryValue $spec.capabilitiesPath 'ApplicationName') -ne $spec.displayName -or (Get-PortableRegistryValue "$($spec.capabilitiesPath)\FileAssociations" $spec.extension) -ne $spec.progId -or (Get-PortableRegistryValue "Software\Classes\$($spec.progId)" '') -ne $spec.description -or - (Get-PortableRegistryValue "Software\Classes\$($spec.progId)\DefaultIcon" '') -ne "$($spec.executable),0" -or + (Get-PortableRegistryValue "Software\Classes\$($spec.progId)\DefaultIcon" '') -ne "$($spec.icon),0" -or (Get-PortableRegistryValue "Software\Classes\$($spec.progId)\shell\open\command" '') -ne $command -or $null -eq (Get-PortableRegistryValue "Software\Classes\$($spec.extension)\OpenWithProgids" $spec.progId)) { return $false } } @@ -107,14 +120,14 @@ function Test-PortableFileAssociations { } function Set-PortableFileAssociations { - param($Package, [Parameter(Mandatory)][string]$Executable) - foreach ($spec in @(Get-PortableAssociationSpec -Package $Package -Executable $Executable)) { + param($Package, [Parameter(Mandatory)][string]$Executable, [string]$Icon) + foreach ($spec in @(Get-PortableAssociationSpec -Package $Package -Executable $Executable -Icon $Icon)) { Set-PortableRegistryValue 'Software\RegisteredApplications' $spec.registeredName $spec.capabilitiesPath Set-PortableRegistryValue $spec.capabilitiesPath 'ApplicationName' $spec.displayName Set-PortableRegistryValue $spec.capabilitiesPath 'ApplicationDescription' "Open supported documents with $($spec.displayName)." Set-PortableRegistryValue "$($spec.capabilitiesPath)\FileAssociations" $spec.extension $spec.progId Set-PortableRegistryValue "Software\Classes\$($spec.progId)" '' $spec.description - Set-PortableRegistryValue "Software\Classes\$($spec.progId)\DefaultIcon" '' "$($spec.executable),0" + Set-PortableRegistryValue "Software\Classes\$($spec.progId)\DefaultIcon" '' "$($spec.icon),0" Set-PortableRegistryValue "Software\Classes\$($spec.progId)\shell\open\command" '' ('"' + $spec.executable + '" "%1"') Set-PortableRegistryValue "Software\Classes\$($spec.extension)\OpenWithProgids" $spec.progId '' } @@ -250,7 +263,14 @@ function Get-PortablePackagePlan { else { $missing = $true } $activeExecutable = Join-Path $paths.Root "$($receipt.directory)/$($receipt.executable)" if ($paths.Shortcut -and -not (Test-PortableShortcut -Path $paths.Shortcut -Executable $activeExecutable)) { $missing = $true } - if (-not (Test-PortableFileAssociations -Package $Package -Executable $activeExecutable)) { $missing = $true } + $associationIcon = $activeExecutable + if ($Package.PSObject.Properties['fileAssociationIcon']) { + $associationIconSource = Get-PortableAssociationIconSource -Package $Package + if (-not (Test-Path -LiteralPath $paths.AssociationIcon -PathType Leaf) -or + (Get-FileHash -LiteralPath $paths.AssociationIcon -Algorithm SHA256).Hash -ne (Get-FileHash -LiteralPath $associationIconSource -Algorithm SHA256).Hash) { $missing = $true } + $associationIcon = $paths.AssociationIcon + } + if (-not (Test-PortableFileAssociations -Package $Package -Executable $activeExecutable -Icon $associationIcon)) { $missing = $true } if ($receipt.version -eq $Package.version -and $receipt.sha256 -ne $Package.sha256) { throw 'Archive checksum changed without a version change; publish a new version before retrying.' } if ($missing) { if ($receipt.version -ne $Package.version -and ($Package.update -eq 'install-only' -or [version]$receipt.version -gt [version]$Package.version)) { throw 'Installed files are missing; pin the installed version to repair it without changing update policy.' } @@ -411,7 +431,14 @@ function Invoke-PortablePackageOperation { [IO.File]::Move((Join-Path $staging 'launch.ps1'), $paths.Launcher, $true) $installedExecutable = Join-Path $destination $package.executable Set-PortableShortcut -Paths $paths -Executable $installedExecutable - Set-PortableFileAssociations -Package $package -Executable $installedExecutable + $associationIcon = $installedExecutable + if ($package.PSObject.Properties['fileAssociationIcon']) { + $associationIconSource = Get-PortableAssociationIconSource -Package $package + Copy-Item -LiteralPath $associationIconSource -Destination (Join-Path $staging 'file-association.ico') + [IO.File]::Move((Join-Path $staging 'file-association.ico'), $paths.AssociationIcon, $true) + $associationIcon = $paths.AssociationIcon + } + Set-PortableFileAssociations -Package $package -Executable $installedExecutable -Icon $associationIcon Assert-PortableStopped $paths.Root $receipt = [ordered]@{ schemaVersion = 1; version = $package.version; sha256 = $package.sha256; directory = $directory; executable = $package.executable; files = $files } $temporary = Join-Path $staging 'current.json' diff --git a/tests/Manifest.Tests.ps1 b/tests/Manifest.Tests.ps1 index 5916e67..a60370f 100644 --- a/tests/Manifest.Tests.ps1 +++ b/tests/Manifest.Tests.ps1 @@ -26,6 +26,7 @@ Describe 'Manifest resolution' { $presenter.displayName | Should -Be 'PDF Presenter' ($presenter.fileAssociations -is [Array]) | Should -BeTrue $presenter.fileAssociations | Should -Be @('.pdf') + $presenter.fileAssociationIcon | Should -Be 'assets/pdf-presenter-pdf.ico' $result.packages.id | Should -Not -Contain 'cpvalente.ontime' } diff --git a/tests/PortablePackages.Tests.ps1 b/tests/PortablePackages.Tests.ps1 index 2da9221..42b1186 100644 --- a/tests/PortablePackages.Tests.ps1 +++ b/tests/PortablePackages.Tests.ps1 @@ -69,12 +69,17 @@ Describe 'Portable package lifecycle' { It 'registers declared file handlers and repairs missing registration' { $package | Add-Member displayName 'Test Presenter' $package | Add-Member fileAssociations @('.pdf') + $package | Add-Member fileAssociationIcon 'assets/pdf-presenter-pdf.ico' Mock Test-PortableFileAssociations { $false } (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Succeeded' + Test-Path (Get-PortablePaths $package $root).AssociationIcon | Should -BeTrue Should -Invoke Set-PortableFileAssociations -Times 1 -Exactly -ParameterFilter { $Package.id -eq 'presenter' -and $Executable -like '*bundle*app.exe' } (Get-PortablePackagePlan $package $root).reason | Should -Match 'file associations' + Mock Test-PortableFileAssociations { $true } + Remove-Item (Get-PortablePaths $package $root).AssociationIcon + (Get-PortablePackagePlan $package $root).action | Should -Be 'Install' } It 'migrates the previous managed launcher without treating it as a local edit' { $paths = Get-PortablePaths $package $root @@ -238,12 +243,20 @@ Describe 'Portable file association registration' { $spec.progId | Should -Be 'ConfigCentral.idle-org.pdf-presenter.pdf' $spec.capabilitiesPath | Should -Be 'Software\ConfigCentral\Applications\idle-org\pdf-presenter\Capabilities' $spec.extension | Should -Be '.pdf' + $spec.icon | Should -Be $spec.executable + } + It 'uses a dedicated document icon when one is supplied' { + $package = [pscustomobject]@{ id = 'pdf-presenter'; source = 'idle-org'; displayName = 'PDF Presenter'; fileAssociations = @('.pdf') } + $executable = [IO.Path]::GetFullPath("$TestDrive/app/pdf-presenter.exe") + $icon = [IO.Path]::GetFullPath("$TestDrive/app/file-association.ico") + (Get-PortableAssociationSpec -Package $package -Executable $executable -Icon $icon).icon | Should -Be $icon } It 'writes a quoted PDF open command and per-user Default Apps registration' { $package = [pscustomobject]@{ id = 'pdf-presenter'; source = 'idle-org'; displayName = 'PDF Presenter'; fileAssociations = @('.pdf') } $executable = [IO.Path]::GetFullPath("$TestDrive/path with spaces/pdf-presenter.exe") + $icon = [IO.Path]::GetFullPath("$TestDrive/path with spaces/file-association.ico") Mock Set-PortableRegistryValue {} - Set-PortableFileAssociations -Package $package -Executable $executable + Set-PortableFileAssociations -Package $package -Executable $executable -Icon $icon Should -Invoke Set-PortableRegistryValue -Times 8 -Exactly Should -Invoke Set-PortableRegistryValue -Times 1 -Exactly -ParameterFilter { $Path -eq 'Software\RegisteredApplications' -and $Name -eq 'ConfigCentral.idle-org.pdf-presenter' @@ -251,6 +264,9 @@ Describe 'Portable file association registration' { Should -Invoke Set-PortableRegistryValue -Times 1 -Exactly -ParameterFilter { $Path -like '*\shell\open\command' -and $Name -eq '' -and $Value -eq ('"' + $executable + '" "%1"') } + Should -Invoke Set-PortableRegistryValue -Times 1 -Exactly -ParameterFilter { + $Path -like '*\DefaultIcon' -and $Name -eq '' -and $Value -eq ($icon + ',0') + } } } } diff --git a/tests/Schema.Tests.ps1 b/tests/Schema.Tests.ps1 index a260c25..7f8d68c 100644 --- a/tests/Schema.Tests.ps1 +++ b/tests/Schema.Tests.ps1 @@ -24,5 +24,10 @@ Describe 'Published manifest schemas' { $profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema | Should -BeTrue $package.fileAssociations = @('pdf') $profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema -ErrorAction SilentlyContinue | Should -BeFalse + $package.fileAssociations = @('.pdf') + $package.fileAssociationIcon = '../outside.ico' + $profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema -ErrorAction SilentlyContinue | Should -BeFalse + $package.fileAssociationIcon = 'assets/example.ico' + $profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema | Should -BeTrue } }