Skip to content

Commit 7724e6d

Browse files
committed
align windows theme store with colors contract
1 parent b80b45c commit 7724e6d

3 files changed

Lines changed: 32 additions & 24 deletions

File tree

windows/scripts/theme-windows.ps1

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,28 @@ function Read-DreamSkinTheme {
378378
Directory = $directory
379379
ThemePath = $themePath
380380
ImagePath = $imagePath
381-
Theme = $theme
381+
Theme = Normalize-DreamSkinThemeContract -Theme $theme
382382
}
383383
}
384384

385+
function Normalize-DreamSkinThemeContract {
386+
param([Parameter(Mandatory = $true)][object]$Theme)
387+
if ($null -eq $Theme -or $Theme -is [string] -or $Theme -is [array]) {
388+
throw 'Theme contract must be a JSON object.'
389+
}
390+
if (-not $Theme.PSObject.Properties['id'] -or -not $Theme.PSObject.Properties['id'].Value) {
391+
$Theme | Add-Member -NotePropertyName id -NotePropertyValue 'custom' -Force
392+
}
393+
if (-not $Theme.PSObject.Properties['appearance'] -or -not $Theme.PSObject.Properties['appearance'].Value) {
394+
$Theme | Add-Member -NotePropertyName appearance -NotePropertyValue 'auto' -Force
395+
}
396+
if (-not $Theme.PSObject.Properties['art'] -or -not $Theme.PSObject.Properties['art'].Value) {
397+
$Theme | Add-Member -NotePropertyName art -NotePropertyValue `
398+
([pscustomobject]@{ focusX = $null; focusY = $null; safeArea = 'auto'; taskMode = 'auto' }) -Force
399+
}
400+
return $Theme
401+
}
402+
385403
function Write-DreamSkinTheme {
386404
param(
387405
[Parameter(Mandatory = $true)][string]$ThemeDirectory,
@@ -390,6 +408,7 @@ function Write-DreamSkinTheme {
390408
Assert-DreamSkinNoReparseComponents -Path $ThemeDirectory
391409
New-Item -ItemType Directory -Force -Path $ThemeDirectory | Out-Null
392410
Assert-DreamSkinNoReparseComponents -Path $ThemeDirectory
411+
$Theme = Normalize-DreamSkinThemeContract -Theme $Theme
393412
$json = $Theme | ConvertTo-Json -Depth 8
394413
$themePath = Join-Path $ThemeDirectory 'theme.json'
395414
Assert-DreamSkinNoReparseComponents -Path $themePath
@@ -538,7 +557,6 @@ function Set-DreamSkinActiveTheme {
538557
name = '自定义主题'
539558
appearance = 'auto'
540559
art = [pscustomobject]@{ focusX = $null; focusY = $null; safeArea = 'auto'; taskMode = 'auto' }
541-
palette = [pscustomobject]@{}
542560
}
543561
}
544562
$imageName = New-DreamSkinThemeImageName -Extension $extension
@@ -564,15 +582,7 @@ function Set-DreamSkinActiveTheme {
564582
Assert-DreamSkinImageFile -Path $target
565583
$Theme | Add-Member -NotePropertyName image -NotePropertyValue $imageName -Force
566584
if ($Name) { $Theme | Add-Member -NotePropertyName name -NotePropertyValue $Name -Force }
567-
if (-not $Theme.id) { $Theme | Add-Member -NotePropertyName id -NotePropertyValue 'custom' -Force }
568-
if (-not $Theme.appearance) { $Theme | Add-Member -NotePropertyName appearance -NotePropertyValue 'auto' -Force }
569-
if (-not $Theme.art) {
570-
$Theme | Add-Member -NotePropertyName art -NotePropertyValue `
571-
([pscustomobject]@{ focusX = $null; focusY = $null; safeArea = 'auto'; taskMode = 'auto' }) -Force
572-
}
573-
if (-not $Theme.palette) {
574-
$Theme | Add-Member -NotePropertyName palette -NotePropertyValue ([pscustomobject]@{}) -Force
575-
}
585+
$Theme = Normalize-DreamSkinThemeContract -Theme $Theme
576586
$activeCss = Join-Path $paths.Active 'theme.css'
577587
Assert-DreamSkinNoReparseComponents -Path $activeCss
578588
if ($temporaryCss) {
@@ -715,19 +725,7 @@ function Get-DreamSkinThemeRuntimeContentFingerprint {
715725
$loaded = Read-DreamSkinTheme -ThemeDirectory $ThemeDirectory -SkipImageMetadata
716726
$runtimeTheme = $loaded.Theme | ConvertTo-Json -Depth 8 | ConvertFrom-Json
717727
$runtimeTheme.image = '<runtime-image>'
718-
if (-not $runtimeTheme.id) {
719-
$runtimeTheme | Add-Member -NotePropertyName id -NotePropertyValue 'custom' -Force
720-
}
721-
if (-not $runtimeTheme.appearance) {
722-
$runtimeTheme | Add-Member -NotePropertyName appearance -NotePropertyValue 'auto' -Force
723-
}
724-
if (-not $runtimeTheme.art) {
725-
$runtimeTheme | Add-Member -NotePropertyName art -NotePropertyValue `
726-
([pscustomobject]@{ focusX = $null; focusY = $null; safeArea = 'auto'; taskMode = 'auto' }) -Force
727-
}
728-
if (-not $runtimeTheme.palette) {
729-
$runtimeTheme | Add-Member -NotePropertyName palette -NotePropertyValue ([pscustomobject]@{}) -Force
730-
}
728+
$runtimeTheme = Normalize-DreamSkinThemeContract -Theme $runtimeTheme
731729
$canonicalTheme = ConvertTo-DreamSkinCanonicalJsonValue -Value $runtimeTheme
732730
$themeBytes = [System.Text.Encoding]::UTF8.GetBytes(
733731
($canonicalTheme | ConvertTo-Json -Depth 8 -Compress)

windows/tests/run-tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ try {
10181018
$updatedTheme.Theme.id -cne 'custom' -or
10191019
$updatedTheme.Theme.art.safeArea -cne 'auto' -or
10201020
$updatedTheme.Theme.art.taskMode -cne 'auto' -or
1021+
$updatedTheme.Theme.PSObject.Properties['palette'] -or
10211022
-not (Test-DreamSkinThemePathWithin -Path $updatedTheme.ImagePath -Root $themePaths.Active)) {
10221023
throw 'Imported image did not reset to the generic adaptive contract inside the managed directory.'
10231024
}

windows/tests/theme-zip-import.tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,19 @@ try {
250250
$roundtripPaths = Initialize-DreamSkinThemeStore -SkillRoot $Root `
251251
-StateRoot $roundtripStateRoot
252252
$officialSaved = Read-DreamSkinTheme -ThemeDirectory $official.Path
253+
if (-not $officialSaved.Theme.PSObject.Properties['colors'] -or
254+
$officialSaved.Theme.PSObject.Properties['palette']) {
255+
throw 'Studio colors-only theme was not preserved as the current community theme contract.'
256+
}
253257
$officialTheme = $officialSaved.Theme | ConvertTo-Json -Depth 8 | ConvertFrom-Json
254258
$null = Set-DreamSkinActiveTheme -ImagePath $officialSaved.ImagePath `
255259
-Theme $officialTheme -SafeCssPath (Join-Path $official.Path 'theme.css') `
256260
-StateRoot $roundtripStateRoot
261+
$roundtripActive = Read-DreamSkinTheme -ThemeDirectory $roundtripPaths.Active
262+
if (-not $roundtripActive.Theme.PSObject.Properties['colors'] -or
263+
$roundtripActive.Theme.PSObject.Properties['palette']) {
264+
throw 'Applying a Studio colors-only theme added a legacy palette field.'
265+
}
257266
$roundtripFingerprint = Get-DreamSkinThemeRuntimeContentFingerprint `
258267
-ThemeDirectory $roundtripPaths.Active
259268
if ($roundtripFingerprint -cne $official.ContentFingerprint) {

0 commit comments

Comments
 (0)