@adea-ai/app-framework 0.36.1 → 0.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +2 -0
  2. package/dist/appearance/appearance-host.js +2 -1
  3. package/dist/appearance/custom-theme-import.js +3 -1
  4. package/dist/appearance/custom-theme-library.d.ts +6 -185
  5. package/dist/appearance/custom-theme-library.js +3 -621
  6. package/dist/appearance/theme-library-mutation.d.ts +42 -0
  7. package/dist/appearance/theme-library-mutation.js +172 -0
  8. package/dist/appearance/theme-library-schema.d.ts +108 -0
  9. package/dist/appearance/theme-library-schema.js +189 -0
  10. package/dist/appearance/theme-library-store.d.ts +61 -0
  11. package/dist/appearance/theme-library-store.js +268 -0
  12. package/dist/appearance/theme-record-adapter.js +3 -1
  13. package/dist/appearance/theme-registry.js +2 -1
  14. package/dist/appearance/window-surface.d.ts +19 -0
  15. package/dist/appearance/window-surface.js +68 -1
  16. package/dist/cli/update-helper-cli.js +1 -1
  17. package/dist/cli/windows-installer-build-cli.d.ts +2 -0
  18. package/dist/cli/windows-installer-build-cli.js +14 -0
  19. package/dist/desktop/desktop-client.d.ts +1 -1
  20. package/dist/framework-source.json +1 -1
  21. package/dist/installer/installed-payload.js +2 -2
  22. package/dist/installer/{installer-archive.js → installer-archive-members.js} +2 -2
  23. package/dist/installer/installer-extraction.js +2 -2
  24. package/dist/installer/installer-fetch-guard.d.ts +1 -1
  25. package/dist/installer/installer-identity.js +2 -2
  26. package/dist/installer/installer-observation.d.ts +1 -1
  27. package/dist/installer/installer-observation.js +2 -2
  28. package/dist/installer/installer-upgrade-command.d.ts +2 -2
  29. package/dist/installer/installer-upgrade-command.js +5 -5
  30. package/dist/installer/linux-process-group.js +1 -1
  31. package/dist/installer/upgrade-asset-download.d.ts +1 -1
  32. package/dist/installer/upgrade-asset-download.js +2 -2
  33. package/dist/native/installer-archive.d.ts +42 -0
  34. package/dist/native/installer-archive.js +172 -0
  35. package/dist/native/posix-tree-removal.d.ts +1 -1
  36. package/dist/native/window-surface-store.d.ts +16 -0
  37. package/dist/native/window-surface-store.js +69 -0
  38. package/dist/native/windows-extractor-build.d.ts +95 -0
  39. package/dist/native/windows-extractor-build.js +326 -0
  40. package/dist/release/feed-release-cut.d.ts +1 -1
  41. package/dist/release/feed-state.d.ts +2 -2
  42. package/dist/release/feed-state.js +3 -3
  43. package/dist/release/github-release-cut.js +1 -1
  44. package/dist/release/github-release-promotion.js +1 -1
  45. package/dist/release/github-release-publisher.js +1 -1
  46. package/dist/release/github-release-qualification.js +1 -1
  47. package/dist/release/local-release.d.ts +2 -2
  48. package/dist/release/local-release.js +3 -3
  49. package/dist/release/release-artifact.d.ts +1 -1
  50. package/dist/release/release-artifact.js +2 -2
  51. package/dist/release/release-assets-plan.js +1 -1
  52. package/dist/release/release-config.d.ts +1 -1
  53. package/dist/release/release-config.js +1 -1
  54. package/dist/release/release-descriptor-staging.js +3 -3
  55. package/dist/release/release-finalize.js +1 -1
  56. package/dist/release/release-promotion.js +1 -1
  57. package/dist/release/release-publication.d.ts +1 -1
  58. package/dist/release/release-publication.js +2 -2
  59. package/dist/release/release-publish-command.js +2 -2
  60. package/dist/update-helper.bundle.js +18 -18
  61. package/dist/updates/channel-update-manager.d.ts +3 -3
  62. package/dist/updates/channel-update-manager.js +2 -2
  63. package/dist/updates/desktop-updater.d.ts +10 -83
  64. package/dist/updates/desktop-updater.js +14 -217
  65. package/dist/updates/{packaged-release-config.js → feed/packaged-release-config.js} +5 -5
  66. package/dist/updates/{release-feed.js → feed/release-feed.js} +2 -2
  67. package/dist/updates/{release-location.js → feed/release-location.js} +2 -2
  68. package/dist/updates/{release-version.js → feed/release-version.js} +1 -1
  69. package/dist/updates/{signed-release.js → feed/signed-release.js} +2 -2
  70. package/dist/updates/{update-discovery.js → feed/update-discovery.js} +1 -1
  71. package/dist/updates/helper/launch-gate-recovery.d.ts +8 -0
  72. package/dist/updates/{update-resume.js → helper/launch-gate-recovery.js} +13 -423
  73. package/dist/updates/helper/resume-staging.d.ts +22 -0
  74. package/dist/updates/helper/resume-staging.js +180 -0
  75. package/dist/updates/{update-helper.d.ts → helper/update-helper.d.ts} +1 -1
  76. package/dist/updates/{update-helper.js → helper/update-helper.js} +9 -9
  77. package/dist/updates/{update-resume.d.ts → helper/update-resume.d.ts} +4 -10
  78. package/dist/updates/helper/update-resume.js +252 -0
  79. package/dist/updates/{update-shutdown.js → helper/update-shutdown.js} +2 -2
  80. package/dist/updates/{update-arm.d.ts → install/update-arm.d.ts} +2 -2
  81. package/dist/updates/{update-arm.js → install/update-arm.js} +9 -9
  82. package/dist/updates/{update-download-cleanup.d.ts → install/update-download-cleanup.d.ts} +1 -1
  83. package/dist/updates/{update-download-cleanup.js → install/update-download-cleanup.js} +3 -3
  84. package/dist/updates/{update-download.d.ts → install/update-download.d.ts} +2 -2
  85. package/dist/updates/{update-download.js → install/update-download.js} +3 -3
  86. package/dist/updates/{update-extraction.d.ts → install/update-extraction.d.ts} +2 -2
  87. package/dist/updates/{update-extraction.js → install/update-extraction.js} +6 -6
  88. package/dist/updates/{update-handoff-plan.d.ts → install/update-handoff-plan.d.ts} +2 -2
  89. package/dist/updates/{update-handoff-plan.js → install/update-handoff-plan.js} +5 -5
  90. package/dist/updates/{update-marker.js → install/update-marker.js} +2 -2
  91. package/dist/updates/{update-swap-stage.d.ts → install/update-swap-stage.d.ts} +2 -2
  92. package/dist/updates/{update-swap-stage.js → install/update-swap-stage.js} +7 -6
  93. package/dist/updates/{update-swap.d.ts → install/update-swap.d.ts} +1 -1
  94. package/dist/updates/{update-swap.js → install/update-swap.js} +5 -5
  95. package/dist/updates/install-target.d.ts +8 -0
  96. package/dist/updates/install-target.js +27 -0
  97. package/dist/updates/{launch-environment.js → launch/launch-environment.js} +1 -1
  98. package/dist/updates/{packaged-launch-admission.js → launch/packaged-launch-admission.js} +4 -4
  99. package/dist/updates/{packaged-update-startup.d.ts → launch/packaged-update-startup.d.ts} +3 -3
  100. package/dist/updates/{packaged-update-startup.js → launch/packaged-update-startup.js} +10 -7
  101. package/dist/updates/{update-launch-gate.d.ts → launch/update-launch-gate.d.ts} +1 -1
  102. package/dist/updates/{update-launch-gate.js → launch/update-launch-gate.js} +9 -9
  103. package/dist/updates/{update-launch.d.ts → launch/update-launch.d.ts} +1 -1
  104. package/dist/updates/{update-launch.js → launch/update-launch.js} +2 -2
  105. package/dist/updates/{linux-process-state.js → locks/linux-process-state.js} +1 -1
  106. package/dist/updates/{native-file-lock.js → locks/native-file-lock.js} +1 -1
  107. package/dist/updates/{stable-file.js → locks/stable-file.js} +2 -2
  108. package/dist/updates/{update-download-lock.js → locks/update-download-lock.js} +1 -1
  109. package/dist/updates/{update-generation-lease.js → locks/update-generation-lease.js} +3 -3
  110. package/dist/updates/{update-inherited-launch-lease.d.ts → locks/update-inherited-launch-lease.d.ts} +1 -1
  111. package/dist/updates/{update-inherited-launch-lease.js → locks/update-inherited-launch-lease.js} +2 -2
  112. package/dist/updates/{update-instance-lease.js → locks/update-instance-lease.js} +2 -2
  113. package/dist/updates/{update-lock.js → locks/update-lock.js} +2 -2
  114. package/dist/updates/{update-process-fence.js → locks/update-process-fence.js} +3 -3
  115. package/dist/updates/{update-process-liveness.js → locks/update-process-liveness.js} +2 -2
  116. package/dist/updates/retained-client-assets.d.ts +60 -0
  117. package/dist/updates/retained-client-assets.js +116 -0
  118. package/dist/updates/retention/retention-cleanup.d.ts +103 -0
  119. package/dist/updates/retention/retention-cleanup.js +439 -0
  120. package/dist/updates/retention/retention-prune-progress.d.ts +27 -0
  121. package/dist/updates/retention/retention-prune-progress.js +203 -0
  122. package/dist/updates/retention/retirement-inventory.d.ts +93 -0
  123. package/dist/updates/retention/retirement-inventory.js +373 -0
  124. package/dist/updates/retention/retirement-records.d.ts +75 -0
  125. package/dist/updates/retention/retirement-records.js +309 -0
  126. package/dist/updates/{update-retention-marker.d.ts → retention/update-retention-marker.d.ts} +1 -1
  127. package/dist/updates/{update-retention-marker.js → retention/update-retention-marker.js} +3 -3
  128. package/dist/updates/{update-retention-plan.d.ts → retention/update-retention-plan.d.ts} +1 -1
  129. package/dist/updates/{update-retention-plan.js → retention/update-retention-plan.js} +2 -2
  130. package/dist/updates/{update-retention-sync.d.ts → retention/update-retention-sync.d.ts} +1 -1
  131. package/dist/updates/{update-retention-sync.js → retention/update-retention-sync.js} +2 -2
  132. package/dist/updates/retention/update-retirement.d.ts +26 -0
  133. package/dist/updates/retention/update-retirement.js +205 -0
  134. package/dist/updates/update-adapter.js +1 -1
  135. package/dist/updates/update-channel-store.d.ts +1 -1
  136. package/dist/updates/update-channel-store.js +2 -2
  137. package/dist/updates/update-manager.d.ts +4 -4
  138. package/dist/updates/update-manager.js +5 -5
  139. package/dist/updates/update-services.d.ts +15 -0
  140. package/dist/updates/update-services.js +77 -0
  141. package/dist/updates/update-state-store.d.ts +2 -2
  142. package/dist/updates/update-state-store.js +2 -2
  143. package/dist/views/appearance-surface.js +3 -1
  144. package/package.json +42 -29
  145. package/src/appearance/custom-theme-library.ts +42 -956
  146. package/src/appearance/theme-library-mutation.ts +288 -0
  147. package/src/appearance/theme-library-schema.ts +347 -0
  148. package/src/appearance/theme-library-store.ts +379 -0
  149. package/src/appearance/window-surface.ts +91 -5
  150. package/src/updates/update-adapter.ts +1 -1
  151. package/templates/application/src/bun/index.ts +15 -0
  152. package/templates/application/src/web/main.tsx +13 -1
  153. package/dist/updates/update-retirement.d.ts +0 -205
  154. package/dist/updates/update-retirement.js +0 -1485
  155. /package/dist/installer/{installer-archive.d.ts → installer-archive-members.d.ts} +0 -0
  156. /package/dist/updates/{packaged-release-config.d.ts → feed/packaged-release-config.d.ts} +0 -0
  157. /package/dist/updates/{release-feed.d.ts → feed/release-feed.d.ts} +0 -0
  158. /package/dist/updates/{release-location.d.ts → feed/release-location.d.ts} +0 -0
  159. /package/dist/updates/{release-version.d.ts → feed/release-version.d.ts} +0 -0
  160. /package/dist/updates/{signed-release.d.ts → feed/signed-release.d.ts} +0 -0
  161. /package/dist/updates/{update-discovery.d.ts → feed/update-discovery.d.ts} +0 -0
  162. /package/dist/updates/{update-shutdown.d.ts → helper/update-shutdown.d.ts} +0 -0
  163. /package/dist/updates/{update-marker.d.ts → install/update-marker.d.ts} +0 -0
  164. /package/dist/updates/{launch-environment.d.ts → launch/launch-environment.d.ts} +0 -0
  165. /package/dist/updates/{packaged-launch-admission.d.ts → launch/packaged-launch-admission.d.ts} +0 -0
  166. /package/dist/updates/{linux-process-state.d.ts → locks/linux-process-state.d.ts} +0 -0
  167. /package/dist/updates/{native-file-lock.d.ts → locks/native-file-lock.d.ts} +0 -0
  168. /package/dist/updates/{stable-file.d.ts → locks/stable-file.d.ts} +0 -0
  169. /package/dist/updates/{update-download-lock.d.ts → locks/update-download-lock.d.ts} +0 -0
  170. /package/dist/updates/{update-generation-lease.d.ts → locks/update-generation-lease.d.ts} +0 -0
  171. /package/dist/updates/{update-instance-lease.d.ts → locks/update-instance-lease.d.ts} +0 -0
  172. /package/dist/updates/{update-lock.d.ts → locks/update-lock.d.ts} +0 -0
  173. /package/dist/updates/{update-process-fence.d.ts → locks/update-process-fence.d.ts} +0 -0
  174. /package/dist/updates/{update-process-liveness.d.ts → locks/update-process-liveness.d.ts} +0 -0
  175. /package/src/updates/{release-version.ts → feed/release-version.ts} +0 -0
@@ -0,0 +1,379 @@
1
+ /*
2
+ * Copyright (c) 2026 Wing
3
+ * Licensed under the MIT License.
4
+ *
5
+ * The custom theme library keeps the registry-validation rules of Adea's accepted
6
+ * port of Zeron's theme registry (https://github.com/zeronsh/zeron). The library is
7
+ * Adea's own product schema (declared-license imports, a stored `variant` per
8
+ * theme); the shared ThemeProvider receives it as extra variants. See NOTICE and
9
+ * the repository history for source and behavior provenance.
10
+ */
11
+ import { defaultPreferenceStorage, quarantineRecord } from '@adea-ai/ui/lib/preference-store'
12
+ import type { ThemeVariant as UiThemeVariant } from '@adea-ai/ui/lib/themes'
13
+ import {
14
+ type CustomThemeStored,
15
+ type StoredThemeVariant,
16
+ toUiVariant,
17
+ } from './theme-library-schema'
18
+
19
+ export type AppearanceStorage = Pick<Storage, 'getItem' | 'setItem'>
20
+
21
+ export const CUSTOM_THEME_LIBRARY_STORAGE_KEY = 'appearance.library'
22
+
23
+ /**
24
+ * Where an unreadable library is quarantined. It is its own key: the library and
25
+ * the appearance preference used to share `appearance.recovery`, so one could
26
+ * overwrite the other's capture.
27
+ */
28
+ export const CUSTOM_THEME_LIBRARY_RECOVERY_KEY = 'appearance.library.recovery'
29
+
30
+ export const CUSTOM_THEME_LIBRARY_VERSION = 1
31
+
32
+ const CUSTOM_THEME_ID_PREFIX = 'custom-'
33
+
34
+ /*
35
+ * The in-memory library.
36
+ *
37
+ * It lives on the host object, not in module state: the dev graph (and any consumer
38
+ * graph) can legitimately load this module twice (a relative import and the
39
+ * components subpath are distinct module records), and a singleton array would fork
40
+ * the registry. The listeners live there too, so a change made through one instance
41
+ * reaches a subscriber registered through the other.
42
+ */
43
+ type LibraryState = {
44
+ themes: readonly CustomThemeStored[]
45
+ /** Derived from `themes`; rebuilt on first read after each change. */
46
+ uiVariants?: readonly UiThemeVariant[]
47
+ listeners: Set<() => void>
48
+ /** Blocks legacy synchronous writes while a coordinated mutation is committing. */
49
+ atomicMutationDepth?: number
50
+ /** One storage observer per shared host, even if source and package graphs load twice. */
51
+ storageEventTarget?: Window
52
+ storageEventListener?: (event: StorageEvent) => void
53
+ }
54
+
55
+ type LibraryHost = typeof globalThis & { __ADEA_THEME_LIBRARY__?: Partial<LibraryState> }
56
+
57
+ const libraryHost = globalThis as LibraryHost
58
+
59
+ export function library(): LibraryState {
60
+ const existing = libraryHost.__ADEA_THEME_LIBRARY__
61
+ if (existing && Array.isArray(existing.themes) && existing.listeners) {
62
+ return existing as LibraryState
63
+ }
64
+ // A host object written by an older module instance has another shape.
65
+ const created: LibraryState = {
66
+ themes: [],
67
+ listeners: existing?.listeners ?? new Set(),
68
+ atomicMutationDepth: 0,
69
+ }
70
+ libraryHost.__ADEA_THEME_LIBRARY__ = created
71
+ return created
72
+ }
73
+
74
+ export function replaceThemes(themes: readonly CustomThemeStored[]): void {
75
+ const state = library()
76
+ state.themes = Object.freeze([...themes])
77
+ state.uiVariants = undefined
78
+ }
79
+
80
+ /** The imported themes' stored variants, in import order. */
81
+ export function customThemeVariants(): readonly StoredThemeVariant[] {
82
+ return library().themes.map((theme) => theme.variant)
83
+ }
84
+
85
+ /** Find one stored variant without projecting the rest of the imported library. */
86
+ export function customThemeVariantById(id: string): StoredThemeVariant | undefined {
87
+ return library().themes.find((theme) => theme.variant.id === id)?.variant
88
+ }
89
+
90
+ /** The imported themes as shared-provider variants: what the provider's `themes` takes. */
91
+ export function customUiVariants(): readonly UiThemeVariant[] {
92
+ const state = library()
93
+ state.uiVariants ??= Object.freeze(state.themes.map(toUiVariant))
94
+ return state.uiVariants
95
+ }
96
+
97
+ function handlePersistentLibraryChange(event: StorageEvent): void {
98
+ if (event.key !== CUSTOM_THEME_LIBRARY_STORAGE_KEY && event.key !== null) return
99
+ // This library uses the same localStorage returned by the preference store.
100
+ // Ignore sessionStorage events and events from any other Storage object.
101
+ const storage = defaultPreferenceStorage()
102
+ if (!storage || event.storageArea !== storage) return
103
+ readCustomThemeLibrary(storage)
104
+ }
105
+
106
+ function observePersistentLibraryChanges(): void {
107
+ const state = library()
108
+ if (state.storageEventTarget || typeof window === 'undefined') return
109
+ const target = window
110
+ const listener = handlePersistentLibraryChange
111
+ state.storageEventTarget = target
112
+ state.storageEventListener = listener
113
+ target.addEventListener('storage', listener)
114
+ }
115
+
116
+ export function subscribeCustomThemes(listener: () => void): () => void {
117
+ observePersistentLibraryChanges()
118
+ const { listeners } = library()
119
+ listeners.add(listener)
120
+ return () => listeners.delete(listener)
121
+ }
122
+
123
+ export function notifyCustomThemes(): void {
124
+ const { listeners } = library()
125
+ // Visit each start-of-notification listener at most once. Skip listeners no
126
+ // longer subscribed at their turn; newly added functions wait until next time.
127
+ // oxlint-disable-next-line unicorn/no-useless-spread
128
+ for (const listener of [...listeners]) {
129
+ if (!listeners.has(listener)) continue
130
+ try {
131
+ // Listeners are observers of an already committed library. A broken
132
+ // observer must not turn a successful write into an import failure or
133
+ // keep later observers from seeing it. There is no diagnostics sink here.
134
+ void Promise.resolve(listener()).catch(() => {})
135
+ } catch {
136
+ // The committed library remains authoritative when a listener throws.
137
+ }
138
+ }
139
+ }
140
+
141
+ function isCustomThemeId(id: string): boolean {
142
+ return id.startsWith(CUSTOM_THEME_ID_PREFIX)
143
+ }
144
+
145
+ /**
146
+ * Replace the in-memory imported-theme set and tell subscribers. Durable mutations
147
+ * must use `mutateCustomThemeLibrary`; this deprecated synchronous API fails closed
148
+ * when a storage adapter is supplied because it cannot acquire the shared lock.
149
+ *
150
+ * @deprecated Use `mutateCustomThemeLibrary` for persisted read/modify/write operations.
151
+ */
152
+ export function setCustomThemes(
153
+ themes: readonly CustomThemeStored[],
154
+ storage: AppearanceStorage | undefined
155
+ ): boolean {
156
+ const state = library()
157
+ // This synchronous compatibility API cannot acquire the shared lock. Reject it
158
+ // during a coordinated write as well as for any durable storage, before it can
159
+ // mutate the shared cache or overwrite a newer v1 record.
160
+ if ((state.atomicMutationDepth ?? 0) > 0) return false
161
+ if (storage) return false
162
+ const safe = namespaceCustomThemes(themes)
163
+ replaceThemes(safe)
164
+ notifyCustomThemes()
165
+ return true
166
+ }
167
+
168
+ export function namespaceCustomThemes(themes: readonly CustomThemeStored[]): CustomThemeStored[] {
169
+ return themes.map((theme) => {
170
+ if (isCustomThemeId(theme.id)) return theme
171
+ const id = `${CUSTOM_THEME_ID_PREFIX}${theme.id}`
172
+ return { ...theme, id, variant: { ...theme.variant, id } }
173
+ })
174
+ }
175
+
176
+ const object = (value: unknown): value is Record<string, unknown> =>
177
+ typeof value === 'object' && value !== null && !Array.isArray(value)
178
+
179
+ const fields = (value: unknown, names: readonly string[]) =>
180
+ object(value) && names.every((name) => typeof value[name] === 'string')
181
+
182
+ function isStoredTheme(entry: unknown): entry is CustomThemeStored {
183
+ if (!object(entry) || !object(entry.variant)) return false
184
+ const theme = entry
185
+ const variant = entry.variant
186
+ return (
187
+ typeof theme.id === 'string' &&
188
+ typeof theme.name === 'string' &&
189
+ (theme.appearance === 'light' || theme.appearance === 'dark') &&
190
+ typeof theme.importedAt === 'string' &&
191
+ fields(variant, ['id', 'familyId', 'familyName', 'name']) &&
192
+ (variant.appearance === 'light' || variant.appearance === 'dark') &&
193
+ fields(variant.colors, [
194
+ 'background',
195
+ 'foreground',
196
+ 'card',
197
+ 'cardForeground',
198
+ 'popover',
199
+ 'popoverForeground',
200
+ 'primary',
201
+ 'primaryForeground',
202
+ 'secondary',
203
+ 'secondaryForeground',
204
+ 'muted',
205
+ 'mutedForeground',
206
+ 'accent',
207
+ 'accentForeground',
208
+ 'destructive',
209
+ 'destructiveAction',
210
+ 'destructiveActionForeground',
211
+ 'success',
212
+ 'border',
213
+ 'input',
214
+ 'ring',
215
+ ]) &&
216
+ fields(variant.terminal, ['background', 'foreground', 'cursor', 'selection']) &&
217
+ object(variant.terminal) &&
218
+ Array.isArray(variant.terminal.ansi) &&
219
+ variant.terminal.ansi.length === 16 &&
220
+ variant.terminal.ansi.every((color) => typeof color === 'string') &&
221
+ fields(variant.editor, [
222
+ 'keyword',
223
+ 'string',
224
+ 'number',
225
+ 'comment',
226
+ 'function',
227
+ 'variable',
228
+ 'type',
229
+ 'tag',
230
+ 'attribute',
231
+ 'operator',
232
+ 'heading',
233
+ 'link',
234
+ 'diffAdd',
235
+ 'diffDelete',
236
+ 'diffHunk',
237
+ 'searchMatch',
238
+ ]) &&
239
+ fields(variant.charts, ['chart1', 'chart2', 'chart3', 'chart4', 'chart5', 'chart6']) &&
240
+ object(theme.flatTokens) &&
241
+ Object.values(theme.flatTokens).every((value) => typeof value === 'string') &&
242
+ Array.isArray(theme.notes) &&
243
+ theme.notes.every((note) => typeof note === 'string')
244
+ )
245
+ }
246
+
247
+ export function parseLibrary(raw: string): {
248
+ themes: CustomThemeStored[]
249
+ reason?: 'corrupt_json' | 'unsupported_record'
250
+ } {
251
+ let value: unknown
252
+ try {
253
+ value = JSON.parse(raw)
254
+ } catch {
255
+ return { themes: [], reason: 'corrupt_json' }
256
+ }
257
+ if (
258
+ !object(value) ||
259
+ value.version !== CUSTOM_THEME_LIBRARY_VERSION ||
260
+ !Array.isArray(value.themes)
261
+ )
262
+ return { themes: [], reason: 'unsupported_record' }
263
+ const themes = value.themes.filter(isStoredTheme)
264
+ return themes.length === value.themes.length
265
+ ? { themes }
266
+ : { themes, reason: 'unsupported_record' }
267
+ }
268
+
269
+ export function preserveLibrary(
270
+ storage: AppearanceStorage,
271
+ raw: string,
272
+ reason: 'corrupt_json' | 'unsupported_record'
273
+ ): boolean {
274
+ const existing = storage.getItem(CUSTOM_THEME_LIBRARY_RECOVERY_KEY)
275
+ if (!existing) quarantineRecord(storage, CUSTOM_THEME_LIBRARY_RECOVERY_KEY, raw, reason)
276
+ const saved = storage.getItem(CUSTOM_THEME_LIBRARY_RECOVERY_KEY)
277
+ try {
278
+ const capture: unknown = saved && JSON.parse(saved)
279
+ return object(capture) && capture.schemaVersion === 1 && capture.raw === raw
280
+ } catch {
281
+ return false
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Read the stored library. A malformed document starts an empty library and
287
+ * quarantines the raw bytes into the library's own recovery key, mirroring the
288
+ * appearance-preference recovery contract; individual invalid records are dropped,
289
+ * not fatal.
290
+ */
291
+ export function readCustomThemeLibrary(
292
+ storage: AppearanceStorage | undefined
293
+ ): readonly CustomThemeStored[] {
294
+ if (!storage) return []
295
+ const result = tryReadCustomThemeLibrary(storage)
296
+ if (result?.changed) notifyCustomThemes()
297
+ return result?.themes ?? []
298
+ }
299
+
300
+ // Theme records are JSON data. Compare values without allocating serialized
301
+ // copies or treating a different object-key order as a theme change.
302
+ function sameThemeValue(left: unknown, right: unknown): boolean {
303
+ if (Object.is(left, right)) return true
304
+ if (!left || !right || typeof left !== 'object' || typeof right !== 'object') return false
305
+ if (Array.isArray(left) || Array.isArray(right)) {
306
+ if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false
307
+ if (Object.getPrototypeOf(left) !== Array.prototype) return false
308
+ if (Reflect.ownKeys(left).length !== left.length + 1) return false
309
+ for (let index = 0; index < left.length; index++) {
310
+ const entry = Object.getOwnPropertyDescriptor(left, index)
311
+ if (!entry || !entry.enumerable || !('value' in entry)) return false
312
+ if (!sameThemeValue(entry.value, right[index])) return false
313
+ }
314
+ return true
315
+ }
316
+ if (Object.getPrototypeOf(left) !== Object.prototype) return false
317
+ const leftKeys = Object.keys(left)
318
+ const rightKeys = Object.keys(right)
319
+ if (leftKeys.length !== rightKeys.length || Reflect.ownKeys(left).length !== leftKeys.length)
320
+ return false
321
+ const rightRecord = right as Record<string, unknown>
322
+ return leftKeys.every((key) => {
323
+ const entry = Object.getOwnPropertyDescriptor(left, key)
324
+ return (
325
+ !!entry &&
326
+ 'value' in entry &&
327
+ Object.hasOwn(rightRecord, key) &&
328
+ sameThemeValue(entry.value, rightRecord[key])
329
+ )
330
+ })
331
+ }
332
+
333
+ /** A failed read must not be confused with a successfully read empty library. */
334
+ function tryReadCustomThemeLibrary(
335
+ storage: AppearanceStorage
336
+ ): { themes: readonly CustomThemeStored[]; changed: boolean } | undefined {
337
+ const state = library()
338
+ const previousThemes = state.themes
339
+ try {
340
+ // An empty value is no library, not a corrupt one.
341
+ const raw = storage.getItem(CUSTOM_THEME_LIBRARY_STORAGE_KEY)
342
+ const { themes, reason } = raw ? parseLibrary(raw) : { themes: [] }
343
+ if (raw && reason) preserveLibrary(storage, raw, reason)
344
+ let changed = true
345
+ try {
346
+ changed = !sameThemeValue(previousThemes, themes)
347
+ } catch {
348
+ // Legacy in-memory values can be unserializable. Publish and notify
349
+ // conservatively after checking that this read is still current.
350
+ }
351
+ // Detect storage or shared-cache changes observed during this read before
352
+ // publishing its snapshot. This is not an atomic cross-context write.
353
+ if (
354
+ storage.getItem(CUSTOM_THEME_LIBRARY_STORAGE_KEY) !== raw ||
355
+ library() !== state ||
356
+ state.themes !== previousThemes
357
+ )
358
+ return undefined
359
+ if (changed) replaceThemes(themes)
360
+ return { themes: changed ? themes : previousThemes, changed }
361
+ } catch {
362
+ return undefined
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Synchronous legacy removal for the in-memory library. Passing storage fails closed;
368
+ * use `removeCustomThemeAtomically` for persisted removals.
369
+ *
370
+ * @deprecated Use `removeCustomThemeAtomically` for persisted removals.
371
+ */
372
+ export function removeCustomTheme(id: string, storage: AppearanceStorage | undefined): boolean {
373
+ if (storage) return false
374
+ const themes = library().themes
375
+ return setCustomThemes(
376
+ themes.filter((theme) => theme.id !== id),
377
+ storage
378
+ )
379
+ }
@@ -1,8 +1,7 @@
1
- // The desktop mirror for the glass appearance setting. The appearance editor
2
- // persists its surface to localStorage (device-local), but the native window
3
- // is the shell's: it reads the mirrored value from the persisted workspace
4
- // preferences at boot. The host (apps/web, desktop only) registers the
5
- // transport — dev-view stays platform-agnostic and calls the seam.
1
+ // The desktop mirror for the glass appearance setting. The appearance editor persists its
2
+ // surface device-locally, but the native window belongs to the host, which reads the
3
+ // mirrored value at startup (window-surface-store). The web side registers the transport:
4
+ // `registerWindowSurfaceMirror(createWindowSurfaceMirror(desktopWindowSurfaceUpdate(invoke)))`.
6
5
  export type WindowSurface = 'theme' | 'frosted' | 'opaque'
7
6
 
8
7
  type WindowSurfaceMirror = (surface: WindowSurface) => void
@@ -16,3 +15,90 @@ export function registerWindowSurfaceMirror(next: WindowSurfaceMirror): void {
16
15
  export function mirrorWindowSurface(surface: WindowSurface): void {
17
16
  mirror?.(surface)
18
17
  }
18
+
19
+ /**
20
+ * A mirror that retries a failed update once after `retryDelayMs`, never replaying a choice a
21
+ * newer one superseded. `whenSettled` runs before a retry (for example, until an uncertain
22
+ * write is fenced); `onFailure` hears about a mirror that still failed and may retry it later.
23
+ */
24
+ export function createWindowSurfaceMirror(
25
+ update: (surface: WindowSurface) => Promise<void>,
26
+ options: {
27
+ retryDelayMs?: number
28
+ whenSettled?: () => Promise<void>
29
+ onFailure?: (surface: WindowSurface, retry: () => void) => void
30
+ } = {}
31
+ ): WindowSurfaceMirror {
32
+ const retryDelayMs = options.retryDelayMs ?? 500
33
+ const whenSettled = options.whenSettled ?? (() => Promise.resolve())
34
+ if (!Number.isSafeInteger(retryDelayMs) || retryDelayMs < 0 || retryDelayMs > 2_147_483_647)
35
+ throw new Error('Invalid window surface retry delay')
36
+ let generation = 0
37
+ let retryTimer: ReturnType<typeof setTimeout> | undefined
38
+ return (surface) => {
39
+ const mine = ++generation
40
+ if (retryTimer !== undefined) clearTimeout(retryTimer)
41
+ retryTimer = undefined
42
+ const afterSettled = (retry: boolean) =>
43
+ void Promise.resolve()
44
+ .then(whenSettled)
45
+ .then(() => {
46
+ if (mine === generation) attempt(retry)
47
+ })
48
+ .catch(reportFailure)
49
+ const reportFailure = () => {
50
+ if (mine !== generation) return
51
+ let used = false
52
+ try {
53
+ options.onFailure?.(surface, () => {
54
+ if (used || mine !== generation) return
55
+ used = true
56
+ afterSettled(true)
57
+ })
58
+ } catch {
59
+ // A notification failure must not become an unhandled rejection.
60
+ }
61
+ }
62
+ const attempt = (retry: boolean) => {
63
+ let result: Promise<void>
64
+ try {
65
+ // Invoke at once so the latest intent is recorded before another write is queued.
66
+ result = update(surface)
67
+ } catch (error) {
68
+ result = Promise.reject(error)
69
+ }
70
+ void result.catch(() => {
71
+ if (mine !== generation) return
72
+ if (!retry) return reportFailure()
73
+ retryTimer = setTimeout(() => {
74
+ retryTimer = undefined
75
+ afterSettled(false)
76
+ }, retryDelayMs)
77
+ })
78
+ }
79
+ attempt(true)
80
+ }
81
+ }
82
+
83
+ /**
84
+ * The update `createWindowSurfaceMirror` needs, through the framework `shell.window-surface`
85
+ * service. The host persists every request it receives, so requests go out one at a time: a
86
+ * newer choice waits for the request in flight, and a choice superseded while it waits is never
87
+ * sent. The last write to reach the store is always the latest choice.
88
+ */
89
+ export function desktopWindowSurfaceUpdate(
90
+ invoke: (name: string, input: unknown) => Promise<{ ok: boolean }>
91
+ ): (surface: WindowSurface) => Promise<void> {
92
+ let latest = 0
93
+ let previous: Promise<unknown> = Promise.resolve()
94
+ return (surface) => {
95
+ const mine = ++latest
96
+ const request = previous.then(async () => {
97
+ if (mine !== latest) return
98
+ const result = await invoke('shell.window-surface', { surface })
99
+ if (!result.ok) throw new Error('Unable to save the window surface')
100
+ })
101
+ previous = request.catch(() => undefined)
102
+ return request
103
+ }
104
+ }
@@ -3,7 +3,7 @@ import type {
3
3
  UpdateChannel,
4
4
  UpdateState,
5
5
  } from '@adea-ai/ui/components/composites/update-dialog'
6
- import { isUpdateChannel } from './release-version'
6
+ import { isUpdateChannel } from './feed/release-version'
7
7
  import { toUpdateState, type NativeUpdateSnapshotOf, type NativeUpdateState } from './update-state'
8
8
 
9
9
  export type { UpdateAdapter, UpdateChannel, UpdateState }
@@ -33,6 +33,11 @@ import {
33
33
  electrobunFileDialogs,
34
34
  registerNativeUtilities,
35
35
  } from '@adea-ai/app-framework/native-utilities'
36
+ import {
37
+ readWindowSurface,
38
+ registerWindowSurfaceService,
39
+ windowSurfaceTransparent,
40
+ } from '@adea-ai/app-framework/window-surface-store'
36
41
  import { appConfig } from '../app-config'
37
42
 
38
43
  const HOST_DRAIN_TIMEOUT_MS = 5000
@@ -90,6 +95,15 @@ registerNativeUtilities({
90
95
  openExternal: (url) => Utils.openExternal(url),
91
96
  ...electrobunFileDialogs(Utils),
92
97
  })
98
+ // The appearance editor's glass choice: persisted here, applied when the window is created.
99
+ const windowSurfaceFile = join(dataDirectory, 'window-surface.json')
100
+ const windowSurface = readWindowSurface(windowSurfaceFile)
101
+ registerWindowSurfaceService({
102
+ services,
103
+ stateFile: windowSurfaceFile,
104
+ current: windowSurface,
105
+ authorize: (principal) => principal === 'app-window',
106
+ })
93
107
  services.register('app.hello', {
94
108
  parse: (value) => value,
95
109
  authorize: (principal) => principal === 'app-window',
@@ -194,6 +208,7 @@ try {
194
208
  portFile: join(dataDirectory, 'desktop-origin-port'),
195
209
  initialPort: appConfig.initialPort ?? undefined,
196
210
  title: appConfig.name,
211
+ transparent: windowSurfaceTransparent(windowSurface, process.platform),
197
212
  renderer: appConfig.renderer,
198
213
  platform: process.platform,
199
214
  principal: 'app-window',
@@ -4,7 +4,12 @@ import { House } from 'lucide-solid'
4
4
  import { Application, defineApplication } from '@adea-ai/app-framework/application'
5
5
  import { ThemeProvider } from '@adea-ai/app-framework/appearance-host'
6
6
  import { connectApplicationCommands } from '@adea-ai/app-framework/application-command-client'
7
- import { createDesktopClient } from '@adea-ai/app-framework/desktop-client'
7
+ import { createDesktopClient, isFrameworkDesktop } from '@adea-ai/app-framework/desktop-client'
8
+ import {
9
+ createWindowSurfaceMirror,
10
+ desktopWindowSurfaceUpdate,
11
+ registerWindowSurfaceMirror,
12
+ } from '@adea-ai/app-framework/window-surface'
8
13
  import { Button } from '@adea-ai/ui/components/ui/button'
9
14
  import { appConfig } from '../app-config'
10
15
  import './style.css'
@@ -12,6 +17,13 @@ import './style.css'
12
17
  declare const __APP_VERSION__: string
13
18
 
14
19
  const client = createDesktopClient()
20
+ // Persist the appearance editor's glass choice for the next window the host creates.
21
+ if (isFrameworkDesktop())
22
+ registerWindowSurfaceMirror(
23
+ createWindowSurfaceMirror(
24
+ desktopWindowSurfaceUpdate((name, input) => client.invoke(name, input))
25
+ )
26
+ )
15
27
  const openExternal = async (url: string) => {
16
28
  const result = await client.invoke('shell.open-external', { url })
17
29
  if (