Skip to content

An open-source, self-hosted system for apps built with web technologies.

Release System 0.1.33

zohayrslileh2c78cb95c09d
diff --git a/bun.lock b/bun.lock
index 219f9cf..b23c721 100644
--- a/bun.lock
+++ b/bun.lock
@@ -29,8 +29,8 @@
"devDependencies": {
"@babel/core": "^7.29.7",
"@babel/plugin-proposal-decorators": "^7.29.7",
- "@phreshos/core": "^0.1.16",
- "@phreshos/react-ui": "^0.1.8",
+ "@phreshos/core": "^0.1.17",
+ "@phreshos/react-ui": "^0.1.9",
"@rolldown/plugin-babel": "^0.2.3",
"@tailwindcss/vite": "^4.3.3",
"@types/adm-zip": "^0.5.8",
@@ -249,9 +249,9 @@
"@oxc-project/types": ["@oxc-project/[email protected]", "", {}, "sha512-nuhZIOLuI6TFQ32I/WnUx+SCPY7SdSKwgnFHydAuoS1+Z4BRcaP+RRJmGzl9lw+0OFF7UmaESf7KQRXaNLHypg=="],
- "@phreshos/core": ["@phreshos/[email protected]", "", {}, "sha512-FT7wDVYZiTA352V2oHxuAuj7C+5CeBeb07KN2eqI46RTq1X27DlcSkJF1iUKhxfy+WSwvghxbjnO9KiKmPHZJQ=="],
+ "@phreshos/core": ["@phreshos/[email protected]", "", {}, "sha512-QZQ7Vq1DuuaylJh0kNeIRY7wsnR6aBLxN90RWsPS57Ecs3dU0k6P9zwfR90ZxTKk4EOZ3lzrmZn96oE5Jl9tZw=="],
- "@phreshos/react-ui": ["@phreshos/[email protected]", "", { "dependencies": { "react-aria-components": "^1.20.0" }, "peerDependencies": { "@phreshos/core": "^0.1.16", "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-0Xc1kP72m4M7IDY7Qlp0Nu2BITttz9xGl9KXFKufF0aw/m6U7wJ6YsBdtSnYZPS0Kb/RYUPBUlmGHKDkG35ejg=="],
+ "@phreshos/react-ui": ["@phreshos/[email protected]", "", { "dependencies": { "react-aria-components": "^1.20.0" }, "peerDependencies": { "@phreshos/core": "^0.1.17", "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-WWRvi9xpTTczCJdNOL5goVtNcmZPj/mPMR/DjxhnZOgpkAgdVnR2iwK8zV47xi0/lUsbt8lKRv2R6LTIPyP8ow=="],
"@react-aria/i18n": ["@react-aria/[email protected]", "", { "dependencies": { "@internationalized/date": "^3.12.1", "@internationalized/message": "^3.1.9", "@internationalized/string": "^3.2.8", "@swc/helpers": "^0.5.0", "react-aria": "^3.48.0" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1", "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" } }, "sha512-z56ZYcbfpNmMyiGLhyEjytpmEfoTlBaksk84q4kds3HvNkf7QWKj+DJVfVDrJX+c1LyuBsszLSX7yxJRiHsYKQ=="],
diff --git a/package.json b/package.json
index 18090a2..619f1dd 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "phreshos",
"displayName": "PhreshOS",
- "version": "0.1.32",
+ "version": "0.1.33",
"description": "The PhreshOS server, desktop, and authoritative system runtime.",
"type": "module",
"private": true,
@@ -30,7 +30,7 @@
"build": "vite-node scripts/build.ts",
"start": "node --run build && node dist/server/main.js",
"pack": "node --run build && vite-node scripts/pack.ts",
- "verify:contracts": "vite-node scripts/verify-client-launch.mjs && vite-node scripts/verify-process-find-or-create.mjs && vite-node scripts/verify-client-surface.mjs && vite-node scripts/verify-window-geometry.mjs && vite-node scripts/verify-readiness.mjs && vite-node scripts/verify-storage.mjs && vite-node scripts/verify-endpoint-services.mjs && vite-node scripts/verify-program-install.mjs && vite-node scripts/verify-host-traffic.mjs && vite-node scripts/verify-intake-address.mjs && vite-node scripts/verify-theme.mjs",
+ "verify:contracts": "vite-node scripts/verify-client-launch.mjs && vite-node scripts/verify-process-find-or-create.mjs && vite-node scripts/verify-client-surface.mjs && vite-node scripts/verify-window-geometry.mjs && vite-node scripts/verify-readiness.mjs && vite-node scripts/verify-storage.mjs && vite-node scripts/verify-endpoint-services.mjs && vite-node scripts/verify-program-install.mjs && vite-node scripts/verify-host-traffic.mjs && vite-node scripts/verify-intake-address.mjs && vite-node scripts/verify-appearance.mjs",
"verify:distribution": "node scripts/verify-distribution.mjs",
"verify": "node --run check && node --run verify:contracts && node --run verify:distribution"
},
@@ -59,8 +59,8 @@
"devDependencies": {
"@babel/core": "^7.29.7",
"@babel/plugin-proposal-decorators": "^7.29.7",
- "@phreshos/core": "^0.1.16",
- "@phreshos/react-ui": "^0.1.8",
+ "@phreshos/core": "^0.1.17",
+ "@phreshos/react-ui": "^0.1.9",
"@rolldown/plugin-babel": "^0.2.3",
"@tailwindcss/vite": "^4.3.3",
"@types/adm-zip": "^0.5.8",
diff --git a/scripts/verify-appearance.mjs b/scripts/verify-appearance.mjs
new file mode 100644
index 0000000..79bbb7c
--- /dev/null
+++ b/scripts/verify-appearance.mjs
@@ -0,0 +1,32 @@
+import assert from "node:assert/strict"
+import Keyv from "keyv"
+import { standardAppearance } from "@phreshos/core"
+import AppearanceManager, { appearanceSchema } from "../source/server/core/appearance-manager.ts"
+
+assert.deepEqual(appearanceSchema.parse(standardAppearance), standardAppearance)
+assert.throws(() => appearanceSchema.parse({}))
+assert.throws(() => appearanceSchema.parse({ ...standardAppearance, spacing: { light: 12, dark: 12 } }))
+assert.throws(() => appearanceSchema.parse({
+ ...standardAppearance,
+ surface: {
+ ...standardAppearance.surface,
+ dark: { ...standardAppearance.surface.dark, grain: 1.01 }
+ }
+}))
+
+const store = new Keyv()
+const manager = await AppearanceManager.open(store, { describe() {} })
+
+assert.deepEqual(manager.value, standardAppearance)
+assert(Object.isFrozen(manager.value))
+
+const updated = {
+ ...standardAppearance,
+ background: { light: "white", dark: "black" }
+}
+
+await manager.update(updated)
+
+assert.deepEqual(manager.value.background, updated.background)
+assert.deepEqual(await store.get("appearance:background"), updated.background)
+assert.equal(await store.get("appearance:theme"), undefined)
diff --git a/scripts/verify-process-find-or-create.mjs b/scripts/verify-process-find-or-create.mjs
index f6449f4..4b60f76 100644
--- a/scripts/verify-process-find-or-create.mjs
+++ b/scripts/verify-process-find-or-create.mjs
@@ -26,7 +26,7 @@ const manager = Object.assign(Object.create(ProgramManager.prototype), {
reach: identity => identity === program.identity ? program : null
})
-manager.start = async (owner, launch, _watching, _parent, _transition, _wallpaper, prepared) => {
+manager.start = async (owner, launch, _watching, _parent, _transition, prepared) => {
await Promise.resolve()
const existing = [...processes.values()].find(process => process.program === owner && process.name === launch.name)
diff --git a/scripts/verify-theme.mjs b/scripts/verify-theme.mjs
deleted file mode 100644
index a17f275..0000000
--- a/scripts/verify-theme.mjs
+++ /dev/null
@@ -1,71 +0,0 @@
-import assert from "node:assert/strict"
-import Keyv from "keyv"
-import ThemeManager, { themeSchema } from "../source/server/core/theme-manager.ts"
-
-const expected = {
- background: "#fffff5",
- foreground: "#183447",
- accent: "#4c9cff",
- spacing: 12,
- radius: 10,
- surface: {
- grain: 0,
- grainAmount: 0,
- backdrop: 0,
- opacity: 1,
- distortion: 0,
- waves: 0,
- ripples: 0,
- saturation: 1,
- brightness: 1
- }
-}
-
-assert.deepEqual(themeSchema.parse({}), expected)
-const configured = themeSchema.parse({
- background: "black",
- surface: {
- grain: 0.9,
- grainAmount: 0.5,
- backdrop: 24,
- opacity: 0,
- distortion: 140,
- waves: 40,
- ripples: 40,
- saturation: 2.6,
- brightness: 1.12
- }
-})
-assert.equal(configured.background, "black")
-assert.deepEqual(configured.surface, {
- grain: 0.9,
- grainAmount: 0.5,
- backdrop: 24,
- opacity: 0,
- distortion: 140,
- waves: 40,
- ripples: 40,
- saturation: 2.6,
- brightness: 1.12
-})
-assert.throws(() => themeSchema.parse({ surface: { color: "black" } }))
-assert.throws(() => themeSchema.parse({ glass: {} }))
-assert.throws(() => themeSchema.parse({ surface: { grain: 1.01 } }))
-assert.throws(() => themeSchema.parse({ surface: { grainAmount: -0.01 } }))
-assert.throws(() => themeSchema.parse({ surface: { animation: 1 } }))
-assert.throws(() => themeSchema.parse({ surface: { backdrop: 25 } }))
-assert.throws(() => themeSchema.parse({ surface: { distortion: 141 } }))
-assert.throws(() => themeSchema.parse({ surface: { waves: 41 } }))
-assert.throws(() => themeSchema.parse({ surface: { ripples: 41 } }))
-assert.throws(() => themeSchema.parse({ surface: { saturation: 0.99 } }))
-assert.throws(() => themeSchema.parse({ surface: { brightness: 1.13 } }))
-
-const store = new Keyv()
-const manager = await ThemeManager.open(store)
-
-assert.deepEqual(manager.value, expected)
-assert(Object.isFrozen(manager.value))
-
-await manager.update({ ...expected, background: "black" })
-assert.equal(manager.value.background, "black")
-assert.equal((await store.get("appearance:theme")).background, "black")
diff --git a/source/client/core/link-manager/auth-manager/auth-manager.ts b/source/client/core/link-manager/auth-manager/auth-manager.ts
index e38eaf4..51a6620 100644
--- a/source/client/core/link-manager/auth-manager/auth-manager.ts
+++ b/source/client/core/link-manager/auth-manager/auth-manager.ts
@@ -5,7 +5,7 @@ import ProgramManager from "./program-manager/program-manager"
import DialogManager from "./dialog-manager"
import TheLink from "@libs/the-link/the-link"
import LinkManager from "../link-manager"
-import { type PermissionDecision, type PermissionName, type ThemeProperties } from "@phreshos/core"
+import { type PermissionDecision, type PermissionName } from "@phreshos/core"
export default class AuthManager extends TheLink {
@@ -48,12 +48,6 @@ export default class AuthManager extends TheLink {
this.linkManager.emitToSession(`/auth${event}`, this.authorization, ...values)
}
- /** Replace the authoritative system Theme. */
- public async updateTheme(theme: ThemeProperties) {
-
- await this.$outbound.publish("/theme", theme)
- }
-
/** Reads one effective permission for the structurally identified Process. */
public async permissionGranted(process: string, permission: PermissionName): Promise<PermissionDecision> {
diff --git a/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts
index 2e1bdad..8b8d4d6 100644
--- a/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts
+++ b/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts
@@ -60,7 +60,7 @@ export default class ProcessManager extends TheLink {
const window = process.client?.window
- if (!window || window.layer === "wallpaper" || window.minimized || window.layer !== layer || window.depth <= depth) continue
+ if (!window || window.minimized || window.layer !== layer || window.depth <= depth) continue
best = identity
diff --git a/source/client/core/link-manager/auth-manager/process-manager/process-scope.ts b/source/client/core/link-manager/auth-manager/process-manager/process-scope.ts
index ab9660c..bb3f0a7 100644
--- a/source/client/core/link-manager/auth-manager/process-manager/process-scope.ts
+++ b/source/client/core/link-manager/auth-manager/process-manager/process-scope.ts
@@ -53,8 +53,6 @@ export default class ProcessScope {
const found = this.window(named)
- if (found.layer === "wallpaper") throw new Error("A wallpaper Window is managed by the system")
-
return found
}
@@ -64,8 +62,6 @@ export default class ProcessScope {
if (!found.client) throw new Error("This process has no live client endpoint")
- if (found.client.window.layer === "wallpaper") throw new Error("A wallpaper Window is managed by the system")
-
return found
}
diff --git a/source/client/core/link-manager/auth-manager/process-manager/window.ts b/source/client/core/link-manager/auth-manager/process-manager/window.ts
index f61c82b..43bf4e1 100644
--- a/source/client/core/link-manager/auth-manager/process-manager/window.ts
+++ b/source/client/core/link-manager/auth-manager/process-manager/window.ts
@@ -33,7 +33,7 @@ export default class Window {
public url: string | null
- // The authoritative runtime layer, including the system-only wallpaper.
+ // The authoritative Desktop layer.
public layer: WindowLayer
// Which of the half's own pages the frame opens on.
diff --git a/source/client/core/link-manager/link-manager.ts b/source/client/core/link-manager/link-manager.ts
index 406dfb0..41122df 100644
--- a/source/client/core/link-manager/link-manager.ts
+++ b/source/client/core/link-manager/link-manager.ts
@@ -2,7 +2,7 @@ import { TransmittedAuthManager } from "@server/core/link-manager/auth-manager/a
import { TransmittedLinkManager } from "@server/core/link-manager/link-manager"
import { type AuthenticationState } from "@server/core/authentication/authentication"
import { type RegistrationResponse } from "@server/core/link-manager/link-manager"
-import { type ThemeProperties } from "@phreshos/core"
+import { type Appearance, type Theme, type ThemePreference } from "@phreshos/core"
import { Forward } from "@libs/the-link/decorators/escript"
import TheLink from "@libs/the-link/the-link"
import Property from "@libs/the-link/property"
@@ -18,14 +18,14 @@ export default class LinkManager extends TheLink {
public readonly connectionIdentity: string
- /** Immediate public Theme value and its future synchronized updates. */
- public readonly theme: Property<ThemeProperties>
+ /** Immediate unresolved System Appearance and future authoritative updates. */
+ public readonly appearance: Property<Appearance>
- /** Immediate public sign-in wallpaper filename and future updates. */
- public readonly signInWallpaper: Property<string | null>
+ /** Effective local Desktop Theme and its future updates. */
+ public readonly theme: Property<Theme>
- /** Immediate public desktop file wallpaper and future updates. */
- public readonly desktopWallpaper: Property<string | null>
+ private themePreference: ThemePreference = "default"
+ private readonly nativeTheme = matchMedia("(prefers-color-scheme: dark)")
public constructor(application: Application, sourceLink: TheLink, payload: TransmittedLinkManager, connectionIdentity: string) {
@@ -39,11 +39,30 @@ export default class LinkManager extends TheLink {
this.subscribeTo(this.sourceLink)
- this.theme = Property.consumer(this, payload.theme.key, payload.theme.value)
+ this.appearance = Property.consumer(this, payload.appearance.key, payload.appearance.value)
- this.signInWallpaper = Property.consumer(this, payload.signInWallpaper.key, payload.signInWallpaper.value)
+ this.theme = Property.private(this, this.effectiveTheme())
- this.desktopWallpaper = Property.consumer(this, payload.desktopWallpaper.key, payload.desktopWallpaper.value)
+ this.nativeTheme.addEventListener("change", this.nativeThemeChanged)
+ }
+
+ public async updateTheme(preference: ThemePreference) {
+ this.themePreference = preference
+ await this.theme.update(this.effectiveTheme())
+ }
+
+ private effectiveTheme(): Theme {
+ return this.themePreference === "default"
+ ? this.nativeTheme.matches ? "dark" : "light"
+ : this.themePreference
+ }
+
+ private readonly nativeThemeChanged = () => {
+ if (this.themePreference === "default") void this.theme.update(this.effectiveTheme())
+ }
+
+ public dispose() {
+ this.nativeTheme.removeEventListener("change", this.nativeThemeChanged)
}
@Forward("outbound")
diff --git a/source/client/view/appearance/appearance.tsx b/source/client/view/appearance/appearance.tsx
index e65b911..4ac30d7 100644
--- a/source/client/view/appearance/appearance.tsx
+++ b/source/client/view/appearance/appearance.tsx
@@ -1,5 +1,5 @@
import ReducedMotion from "@libs/react-motion"
-import { standardTheme } from "@phreshos/core"
+import { standardAppearance } from "@phreshos/core"
import { ReactNode } from "react"
import "./appearance.css"
@@ -7,7 +7,7 @@ export default function ({ children, reducedMotion }: AppearanceProps) {
return <ReducedMotion reduced={reducedMotion}>
- <div className="relative isolate grid h-dvh overflow-hidden font-roboto" style={{ backgroundColor: standardTheme.background }}>
+ <div className="relative isolate grid h-dvh overflow-hidden font-roboto" style={{ backgroundColor: standardAppearance.background.light }}>
{children}
diff --git a/source/client/view/components/desktop-host/client-process-boundary.ts b/source/client/view/components/desktop-host/client-process-boundary.ts
index 041501b..4a64a58 100644
--- a/source/client/view/components/desktop-host/client-process-boundary.ts
+++ b/source/client/view/components/desktop-host/client-process-boundary.ts
@@ -42,6 +42,10 @@ export default class ClientProcessBoundary extends TheLink {
private stopTheme: (() => void) | null = null
+ private readonly appearanceSubscriptions = new Set<string>()
+
+ private stopAppearance: (() => void) | null = null
+
private readonly trafficDeliveries = new WeakSet<object>()
// A document can begin executing before its iframe load event gives the
@@ -378,7 +382,7 @@ export default class ClientProcessBoundary extends TheLink {
this.subscriptions.set(subscription, description)
- if (!themeSubscription(description)) this.addTraffic(kind, route, event)
+ if (!localPropertySubscription(description)) this.addTraffic(kind, route, event)
if (this.owner && directSubscription(description)) this.authManager.processManager.subscribeFrame(this.pane, this.owner, subscription, kind, event).catch(() => undefined)
@@ -393,6 +397,17 @@ export default class ClientProcessBoundary extends TheLink {
}
+ if (appearanceSubscription(description)) {
+
+ this.appearanceSubscriptions.add(subscription)
+
+ if (!this.stopAppearance) this.stopAppearance = this.authManager.linkManager.appearance.tunnel.subscribe("change", (appearance: unknown) => {
+
+ this.deliver("host-appearance", "change", appearance).catch(() => undefined)
+ })
+
+ }
+
if (kind === "ask") this.releaseWaiting(route, event)
this.updatePointer()
@@ -705,6 +720,13 @@ export default class ClientProcessBoundary extends TheLink {
this.stopTheme = null
}
+ if (this.appearanceSubscriptions.delete(subscription) && this.appearanceSubscriptions.size === 0) {
+
+ this.stopAppearance?.()
+
+ this.stopAppearance = null
+ }
+
const key = JSON.stringify([existing.kind, existing.route, existing.event])
const traffic = this.trafficSubscriptions.get(key)
@@ -839,10 +861,16 @@ export default class ClientProcessBoundary extends TheLink {
this.themeSubscriptions.clear()
+ this.appearanceSubscriptions.clear()
+
this.stopTheme?.()
this.stopTheme = null
+ this.stopAppearance?.()
+
+ this.stopAppearance = null
+
for (const { stop } of this.trafficSubscriptions.values()) stop()
this.trafficSubscriptions.clear()
@@ -978,6 +1006,16 @@ function themeSubscription(subscription: EndpointSubscription) {
return subscription.kind === "publish" && subscription.route === "host-theme" && (subscription.event === null || subscription.event === "change")
}
+function appearanceSubscription(subscription: EndpointSubscription) {
+
+ return subscription.kind === "publish" && subscription.route === "host-appearance" && (subscription.event === null || subscription.event === "change")
+}
+
+function localPropertySubscription(subscription: EndpointSubscription) {
+
+ return themeSubscription(subscription) || appearanceSubscription(subscription)
+}
+
function directSubscription(subscription: EndpointSubscription) {
return subscription.route === "end-end" && subscription.kind === "publish"
diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.ts
index 60a27cf..54556e2 100644
--- a/source/client/view/components/desktop-host/host.ts
+++ b/source/client/view/components/desktop-host/host.ts
@@ -87,8 +87,19 @@ export default function host(authManager: AuthManager, pane: string, desktop: ()
// only because it was added on the other.
if (word === "current-process") return [record(process())]
+ if (word === "appearance") return [authManager.linkManager.appearance.value]
+
if (word === "theme") return [authManager.linkManager.theme.value]
+ if (word === "update-theme") {
+
+ if (args[0] !== "light" && args[0] !== "dark" && args[0] !== "default") throw new Error("A Theme is light, dark, or default")
+
+ await authManager.linkManager.updateTheme(args[0])
+
+ return []
+ }
+
if (word === "exists") {
const target = args[1] === undefined ? process() : scope.sibling(args[1])
diff --git a/source/client/view/components/desktop-host/local-window.ts b/source/client/view/components/desktop-host/local-window.ts
index 87ecf2d..1d43eb7 100644
--- a/source/client/view/components/desktop-host/local-window.ts
+++ b/source/client/view/components/desktop-host/local-window.ts
@@ -100,7 +100,6 @@ export function visibilityTransition(value: unknown): VisibilityTransition {
export function layerAllowsSurface(layer: WindowLayer) {
if (layer === "window") throw new Error("A window-layer representation cannot own a Surface")
- if (layer === "wallpaper") throw new Error("A wallpaper-layer representation cannot own a Surface")
}
function easing(value: unknown): Easing {
diff --git a/source/client/view/components/window-manager/local-windows.ts b/source/client/view/components/window-manager/local-windows.ts
index 2e0bbbc..fa77b70 100644
--- a/source/client/view/components/window-manager/local-windows.ts
+++ b/source/client/view/components/window-manager/local-windows.ts
@@ -194,7 +194,7 @@ export default class LocalWindows implements LocalWindowHost {
this.cancel(identity, "surface", "The local Window representation was removed")
const client = this.client(process)
- if (!client || client.window.layer === "wallpaper") return
+ if (!client) return
this.authoritative.set(identity, authoritativeSignature(client))
this.replace(identity, localState(client))
}
diff --git a/source/client/view/components/window-manager/window-manager.ts b/source/client/view/components/window-manager/window-manager.ts
index 80d703e..d9d43b3 100644
--- a/source/client/view/components/window-manager/window-manager.ts
+++ b/source/client/view/components/window-manager/window-manager.ts
@@ -51,7 +51,7 @@ export default function useWindows(authManager: AuthManager) {
const initialIncarnations = useRef<Map<string, WindowIncarnation> | null>(null)
- if (!initialIncarnations.current) initialIncarnations.current = new Map(processes.flatMap(record => record.client && record.client.window.layer !== "wallpaper" ? [[record.identity, incarnation(record, record.client)] as const] : []))
+ if (!initialIncarnations.current) initialIncarnations.current = new Map(processes.flatMap(record => record.client ? [[record.identity, incarnation(record, record.client)] as const] : []))
const initialClients = initialIncarnations.current
@@ -103,7 +103,7 @@ export default function useWindows(authManager: AuthManager) {
const present = new Set(list.map(process => process.identity))
- const currentClients = new Map(list.flatMap(record => record.client && record.client.window.layer !== "wallpaper" ? [[record.identity, incarnation(record, record.client)] as const] : []))
+ const currentClients = new Map(list.flatMap(record => record.client ? [[record.identity, incarnation(record, record.client)] as const] : []))
localWindow.reconcile(currentClients)
@@ -146,9 +146,7 @@ export default function useWindows(authManager: AuthManager) {
inbound.useSubscribe("/processes", subscriber)
- const records = processes.filter(process => process.client && process.client.window.layer !== "wallpaper")
-
- const wallpaper = processes.find(process => process.client?.window.layer === "wallpaper") ?? null
+ const records = processes.filter(process => process.client)
// Everything that is shown, in the layer it is shown in — and the
// taskbar's list, which is the `window` layer and nothing else. The
@@ -172,7 +170,7 @@ export default function useWindows(authManager: AuthManager) {
const window = localWindows.get(live.identity)
- if (!window || window.layer === "wallpaper" || window.minimized) continue
+ if (!window || window.minimized) continue
const best = fronts[window.layer]
@@ -360,17 +358,13 @@ export default function useWindows(authManager: AuthManager) {
for (const pane of panes) {
- const layer = pane.local.layer
-
- if (layer !== "wallpaper") panesByLayer[layer].push(pane)
+ panesByLayer[pane.local.layer].push(pane)
}
return {
records,
- wallpaper,
-
listed,
panesByLayer,
diff --git a/source/client/view/structure/authentication/authentication.tsx b/source/client/view/structure/authentication/authentication.tsx
index 2c0087c..61b2894 100644
--- a/source/client/view/structure/authentication/authentication.tsx
+++ b/source/client/view/structure/authentication/authentication.tsx
@@ -9,9 +9,9 @@ import SignIn from "./sign-in"
import Register from "./register"
import { useState, type ReactNode } from "react"
import { type AuthenticationState } from "@server/core/authentication/authentication"
-import useProperty from "@libs/the-link/plugins/react-helper/property-hook"
import { WallpaperStage } from "../desktop/wallpaper/wallpaper"
import { useReady } from "@libs/readiness/main"
+import { useAppearance, useResolveTheme } from "@phreshos/react-ui"
export default function () {
@@ -19,7 +19,7 @@ export default function () {
const linkManager = LinkManagerContext.useValue()
- const signInWallpaper = useProperty(linkManager.signInWallpaper)
+ const signInWallpaper = useResolveTheme(useAppearance().signInWallpaper)
const [revision, setRevision] = useState(0)
diff --git a/source/client/view/structure/authentication/credentials-form.tsx b/source/client/view/structure/authentication/credentials-form.tsx
index a2c4c7e..3ff5f80 100644
--- a/source/client/view/structure/authentication/credentials-form.tsx
+++ b/source/client/view/structure/authentication/credentials-form.tsx
@@ -1,7 +1,7 @@
import { type AuthenticationState } from "@server/core/authentication/authentication"
import { enterSurface, prepareSurfaceEntrance, restSurface } from "../../appearance/surface-presence"
import { useReducedMotion } from "@libs/react-motion"
-import { Surface, useScale, useTheme } from "@phreshos/react-ui"
+import { Surface, useAppearance, useResolveTheme, useScale } from "@phreshos/react-ui"
import { obscuredBackground } from "../../components/loading"
import Alert from "../../components/alert"
import { type SyntheticEvent, useLayoutEffect, useRef } from "react"
@@ -13,7 +13,7 @@ export default function CredentialsForm({ title, description, submitLabel, passw
const reducedMotion = useReducedMotion()
- const radius = useScale(useTheme().radius)
+ const radius = useScale(useResolveTheme(useAppearance().radius))
const outerRadius = radius.large
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsx
index 89f1dd0..1abf3ad 100644
--- a/source/client/view/structure/desktop/desktop.tsx
+++ b/source/client/view/structure/desktop/desktop.tsx
@@ -1,5 +1,5 @@
import { type Layer } from "@server/core/link-manager/auth-manager/program-manager/config"
-import { type SyntheticEvent, useCallback, useEffect, useRef, useState } from "react"
+import { useCallback, useEffect, useRef, useState } from "react"
import { ApplicationContext, AuthManagerContext } from "../../contexts"
import useClientHost from "../../components/desktop-host/client-host"
import DesktopDisplay from "./desktop-display"
@@ -14,11 +14,10 @@ import Taskbar from "./taskbar/taskbar"
import WindowTaskbarItem from "./taskbar/programs/window-taskbar-item"
import ProcessWindow from "./windows/process-window"
import useWindows from "../../components/window-manager/window-manager"
-import useProperty from "@libs/the-link/plugins/react-helper/property-hook"
import { ReadyWallpaper, WallpaperBackground } from "./wallpaper/wallpaper"
-import ProgramFrame from "../../components/program-frame"
import Loading from "../../components/loading"
import { useRequirement } from "@libs/readiness/main"
+import { useAppearance, useResolveTheme } from "@phreshos/react-ui"
export default function Workspace() {
@@ -26,7 +25,7 @@ export default function Workspace() {
const authManager = AuthManagerContext.useValue()
- const desktopWallpaper = useProperty(authManager.linkManager.desktopWallpaper)
+ const desktopWallpaper = useResolveTheme(useAppearance().desktopWallpaper)
const windows = useWindows(authManager)
@@ -38,15 +37,9 @@ export default function Workspace() {
const [readyPrograms, setReadyPrograms] = useState<ReadonlySet<string>>(() => new Set())
- const wallpaperIdentity = windows.wallpaper?.identity ?? null
-
- const [readyWallpaper, setReadyWallpaper] = useState<string | null>(null)
-
const [fileWallpaperReady, setFileWallpaperReady] = useState(false)
- const programWallpaperReady = wallpaperIdentity !== null && readyWallpaper === wallpaperIdentity
-
- const wallpaperReady = windows.wallpaper ? programWallpaperReady : fileWallpaperReady
+ const wallpaperReady = fileWallpaperReady
const desktop = useRef<HTMLDivElement>(null)
@@ -68,19 +61,6 @@ export default function Workspace() {
const { windowSurfaceRef, windowSurfaceSize, frame, frameLoaded } = useClientHost(authManager, desktop, sources.current, windows.localWindow)
- const wallpaperLoaded = useCallback((event: SyntheticEvent<HTMLIFrameElement>) => {
-
- const wallpaper = windows.wallpaper
-
- if (wallpaper) {
-
- frameLoaded(wallpaper.identity, event.currentTarget)
-
- setReadyWallpaper(wallpaper.identity)
- }
-
- }, [frameLoaded, windows.wallpaper])
-
const fileWallpaperLoaded = useCallback(() => {
setFileWallpaperReady(true)
@@ -228,39 +208,7 @@ export default function Workspace() {
</Taskbar>
- const wallpaper = <>
-
- <WallpaperBackground
-
- file={windows.wallpaper ? undefined : desktopWallpaper}
-
- visible={!programWallpaperReady}
-
- onReady={fileWallpaperLoaded}
-
- />
-
- {windows.wallpaper?.client && programAccess !== "checking" && <ProgramFrame
-
- record={windows.wallpaper}
-
- client={windows.wallpaper.client}
-
- title={windows.wallpaper.client.window.title}
-
- door={application.doors.program}
-
- access={programAccess}
-
- className={`absolute inset-0 size-full border-0 ${programWallpaperReady ? "" : "pointer-events-none opacity-0"}`}
-
- onFrame={frame}
-
- onLoad={wallpaperLoaded}
-
- />}
-
- </>
+ const wallpaper = <WallpaperBackground file={desktopWallpaper} onReady={fileWallpaperLoaded} />
return <div ref={desktop} tabIndex={-1} aria-label="Desktop" onFocusCapture={focus.remember} className="relative isolate grid min-h-0 grid-cols-1 grid-rows-1 outline-none">
diff --git a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx
index 23d9e11..e543568 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx
@@ -1,7 +1,7 @@
import { ComponentProps, ReactNode, useCallback, useEffect, useId, useRef, useState } from "react"
import { enterSurface, prepareSurfaceEntrance, restSurface } from "../../../../appearance/surface-presence"
import { useReducedMotion } from "@libs/react-motion"
-import { useScale, useTheme } from "@phreshos/react-ui"
+import { useAppearance, useResolveTheme, useScale } from "@phreshos/react-ui"
import TaskbarSurface, { taskbarSurfaceClassName } from "../taskbar-surface"
import TaskbarButton from "../taskbar-button"
@@ -17,7 +17,7 @@ export default function ({ label, trigger, children, className, style, ...props
const reducedMotion = useReducedMotion()
- const radius = useScale(useTheme().radius).large
+ const radius = useScale(useResolveTheme(useAppearance().radius)).large
const [open, setOpen] = useState(false)
diff --git a/source/client/view/structure/desktop/taskbar/system/system-dialogs.tsx b/source/client/view/structure/desktop/taskbar/system/system-dialogs.tsx
index 7449bac..7378c22 100644
--- a/source/client/view/structure/desktop/taskbar/system/system-dialogs.tsx
+++ b/source/client/view/structure/desktop/taskbar/system/system-dialogs.tsx
@@ -2,7 +2,7 @@ import { type PermissionChoice, type PermissionDialog, type ServerCrashDialog }
import ReactTunnel from "@libs/the-link/plugins/react-helper/react-tunnel"
import { enterSurface, prepareSurfaceEntrance, restSurface } from "../../../../appearance/surface-presence"
import { useReducedMotion } from "@libs/react-motion"
-import { useScale, useTheme } from "@phreshos/react-ui"
+import { useAppearance, useResolveTheme, useScale } from "@phreshos/react-ui"
import { useEffect, useId, useRef } from "react"
import { AuthManagerContext } from "../../../../contexts"
import TaskbarSurface, { taskbarSurfaceClassName } from "../taskbar-surface"
@@ -33,7 +33,7 @@ export default function SystemDialogs() {
const reducedMotion = useReducedMotion()
- const radius = useScale(useTheme().radius).large
+ const radius = useScale(useResolveTheme(useAppearance().radius)).large
useEffect(function () {
diff --git a/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx b/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx
index d3ac8a7..000e603 100644
--- a/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx
+++ b/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx
@@ -1,12 +1,12 @@
import { ReactNode } from "react"
-import { Surface, useScale, useTheme } from "@phreshos/react-ui"
+import { Surface, useAppearance, useResolveTheme, useScale } from "@phreshos/react-ui"
/** The window-material shell shared by surfaces opened from the taskbar. */
export const taskbarSurfaceClassName = "m-0 isolate overflow-hidden border-0 bg-transparent p-0 shadow-window-active outline-none"
export default function TaskbarSurface({ label, labelId, children }: TaskbarSurfaceProps) {
- const contentRadius = useScale(useTheme().radius).medium
+ const contentRadius = useScale(useResolveTheme(useAppearance().radius)).medium
return <Surface className="grid min-h-0 max-h-[inherit] grid-rows-[auto_minmax(0,1fr)] overflow-hidden rounded-[inherit]">
diff --git a/source/client/view/structure/desktop/taskbar/taskbar.tsx b/source/client/view/structure/desktop/taskbar/taskbar.tsx
index f795cac..034ada9 100644
--- a/source/client/view/structure/desktop/taskbar/taskbar.tsx
+++ b/source/client/view/structure/desktop/taskbar/taskbar.tsx
@@ -1,5 +1,5 @@
import { ReactNode } from "react"
-import { Surface, useScale, useTheme, type SurfaceProps } from "@phreshos/react-ui"
+import { Surface, useAppearance, useResolveTheme, useScale, type SurfaceProps } from "@phreshos/react-ui"
import TaskbarSeparator from "./taskbar-separator"
/**
@@ -8,7 +8,7 @@ import TaskbarSeparator from "./taskbar-separator"
*/
export default function Taskbar({ leading, trailing, dialogs, className, style, children, ...props }: TaskbarProps) {
- const radius = useScale(useTheme().radius).large
+ const radius = useScale(useResolveTheme(useAppearance().radius)).large
return <Surface
diff --git a/source/client/view/structure/desktop/wallpaper/wallpaper.tsx b/source/client/view/structure/desktop/wallpaper/wallpaper.tsx
index 16e6f5a..7237188 100644
--- a/source/client/view/structure/desktop/wallpaper/wallpaper.tsx
+++ b/source/client/view/structure/desktop/wallpaper/wallpaper.tsx
@@ -1,55 +1,69 @@
import bundledWallpaper from "@/assets/bundled/wallpaper.jpg"
import { ApplicationContext } from "../../../contexts"
-import { useMemo, useState, type ReactNode } from "react"
+import { useEffect, useMemo, useRef, useState, type ReactNode } from "react"
import Loading from "../../../components/loading"
import { useReady } from "@libs/readiness/main"
type WallpaperSource = Readonly<{
key: string
source: string
- html: boolean
}>
/**
* Displays only a completely loaded wallpaper source.
*
- * A filename asks for a new served wallpaper, `null` explicitly selects the
- * bundled wallpaper, and `undefined` retains the displayed source while a
- * different wallpaper owner prepares its representation.
+ * A filename asks for a served image and `null` selects the Desktop fallback.
+ * The previous loaded source stays visible until its replacement is ready.
*/
-export function WallpaperBackground({ file, visible = true, onReady }: WallpaperBackgroundProps) {
+export function WallpaperBackground({ file, onReady }: WallpaperBackgroundProps) {
const application = ApplicationContext.useValue()
- const desired = useMemo<WallpaperSource | null>(() => {
-
- if (file === undefined) return null
-
+ const desired = useMemo<WallpaperSource>(() => {
return file === null
- ? { key: "bundled", source: bundledWallpaper, html: false }
+ ? { key: "bundled", source: bundledWallpaper }
: {
key: `file:${file}`,
- source: `${application.doors.uploads}/${encodeURIComponent(file)}`,
- html: /\.html?$/i.test(file)
+ source: `${application.doors.uploads}/${encodeURIComponent(file)}`
}
}, [application.doors.uploads, file])
- const [displayed, setDisplayed] = useState<WallpaperSource | null>(null)
-
- const sources = desired && desired.key !== displayed?.key
+ const fallback = useMemo<WallpaperSource>(() => ({ key: "bundled", source: bundledWallpaper }), [])
+ const [displayed, setDisplayed] = useState<WallpaperSource>(fallback)
+ const [previous, setPrevious] = useState<WallpaperSource | null>(null)
+ const transition = useRef<number | null>(null)
- ? displayed ? [displayed, desired] : [desired]
+ useEffect(() => () => {
+ if (transition.current !== null) clearTimeout(transition.current)
+ }, [])
- : displayed ? [displayed] : desired ? [desired] : []
+ const sources = desired.key === displayed.key
+ ? previous ? [previous, displayed] : [displayed]
+ : previous ? [previous, displayed, desired] : [displayed, desired]
function loaded(source: WallpaperSource) {
+ if (source.key !== desired.key) return
- if (source.key !== desired?.key) return
+ if (source.key === displayed.key) {
+ onReady?.()
+ return
+ }
- setDisplayed(source)
+ if (transition.current !== null) clearTimeout(transition.current)
+ setPrevious(displayed)
+ setDisplayed(source)
onReady?.()
+
+ transition.current = window.setTimeout(() => {
+ setPrevious(null)
+ transition.current = null
+ }, 700)
+ }
+
+ function failed(source: WallpaperSource) {
+ if (source.key === desired.key) onReady?.()
}
return <>{sources.map(source => <WallpaperLayer
@@ -58,42 +72,29 @@ export function WallpaperBackground({ file, visible = true, onReady }: Wallpaper
source={source}
- visible={visible && source.key === displayed?.key}
+ visible={source.key === displayed.key}
onLoad={() => loaded(source)}
+ onError={() => failed(source)}
+
/>)}</>
}
-function WallpaperLayer({ source, visible, onLoad }: { source: WallpaperSource, visible: boolean, onLoad: () => void }) {
-
- if (source.html) return <iframe
-
- src={source.source}
-
- title="Wallpaper"
-
- sandbox="allow-scripts"
-
- className={`absolute inset-0 size-full border-0 ${visible ? "" : "pointer-events-none opacity-0"}`}
-
- onLoad={onLoad}
-
- />
-
+function WallpaperLayer({ source, visible, onLoad, onError }: { source: WallpaperSource, visible: boolean, onLoad: () => void, onError: () => void }) {
return <>
<div
aria-hidden="true"
- className={`pointer-events-none absolute inset-0 bg-cover bg-center bg-no-repeat ${visible ? "" : "opacity-0"}`}
+ className={`pointer-events-none absolute inset-0 bg-cover bg-center bg-no-repeat transition-opacity duration-700 ease-out ${visible ? "opacity-100" : "opacity-0"}`}
style={{ backgroundImage: `url(${source.source})` }}
/>
- {!visible && <img
+ <img
src={source.source}
@@ -103,7 +104,9 @@ function WallpaperLayer({ source, visible, onLoad }: { source: WallpaperSource,
onLoad={onLoad}
- />}
+ onError={onError}
+
+ />
</>
}
@@ -151,9 +154,7 @@ interface WallpaperStageProps {
interface WallpaperBackgroundProps {
- file: string | null | undefined
-
- visible?: boolean
+ file: string | null
onReady?: () => void
}
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index 3cba70b..62593a2 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -1,7 +1,7 @@
import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useLayoutEffect, useRef, useState } from "react"
import { useReducedMotion } from "@libs/react-motion"
import { enterSurface, prepareSurfaceEntrance, restSurface } from "../../../appearance/surface-presence"
-import { Surface, useScale, useTheme } from "@phreshos/react-ui"
+import { Surface, useAppearance, useResolveTheme, useScale } from "@phreshos/react-ui"
import { absoluteWindowGeometry, resolveWindowGeometry, resolveWindowValue, wholeWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "../../../components/window-manager/window-geometry"
import { type Position, type Size, type WindowGeometry } from "@phreshos/core"
import WindowHeader from "./window-header"
@@ -54,9 +54,11 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
const reducedMotion = useReducedMotion()
- const theme = useTheme()
+ const appearance = useAppearance()
- const radius = useScale(theme.radius)
+ const radius = useScale(useResolveTheme(appearance.radius))
+
+ const foreground = useResolveTheme(appearance.foreground)
const outerRadius = radius.large
@@ -725,7 +727,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
Bare, there is no difference: the frame fills the box, so
the window is exactly as large as it asked to be and its
boundaries are the ones its own content draws. */}
- <div data-window-container ref={surfaceElement} style={bare ? undefined : { ...paintedInsets, borderRadius: outerRadius, color: theme.foreground }} className={`absolute isolate grid ${bare ? "inset-0 grid-rows-1" : `overflow-hidden grid-rows-[auto_minmax(0,1fr)] ${surface}`}`}>
+ <div data-window-container ref={surfaceElement} style={bare ? undefined : { ...paintedInsets, borderRadius: outerRadius, color: foreground }} className={`absolute isolate grid ${bare ? "inset-0 grid-rows-1" : `overflow-hidden grid-rows-[auto_minmax(0,1fr)] ${surface}`}`}>
{/* Material is paint, not the interaction container. Keeping
it as a sibling behind the window contents prevents plain
diff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsx
index d873e44..e8ca99e 100644
--- a/source/client/view/structure/structure.tsx
+++ b/source/client/view/structure/structure.tsx
@@ -3,7 +3,7 @@ import useProperty from "@libs/the-link/plugins/react-helper/property-hook"
import { TransmittedLinkManager } from "@server/core/link-manager/link-manager"
import SocketLink from "@libs/the-link/plugins/client-link/socket-link"
import LinkManager from "@client/core/link-manager/link-manager"
-import { ThemeProvider } from "@phreshos/react-ui"
+import { AppearanceProvider, useResolveTheme } from "@phreshos/react-ui"
import Loading from "../components/loading"
import Alert from "../components/alert"
import { ApplicationContext, LinkManagerContext } from "../contexts"
@@ -11,7 +11,7 @@ import usePromise from "@libs/react-promise"
import Authentication from "./authentication/authentication"
import { useCallback, useState } from "react"
import Readiness, { useReady } from "@libs/readiness/main"
-import { standardTheme } from "@phreshos/core"
+import { standardAppearance } from "@phreshos/core"
const startupRequirements = ["connection", "session", "wallpaper"] as const
@@ -29,7 +29,7 @@ export default function () {
className={`transition-opacity duration-200 ease-out ${pending.length ? "" : "pointer-events-none opacity-0"}`}
- style={{ backgroundColor: standardTheme.background }}
+ style={{ backgroundColor: standardAppearance.background.light }}
/>}
@@ -50,11 +50,18 @@ function Desktop() {
internal.useSubscribe("subscribe", useCallback(function (socketLink: SocketLink<[TransmittedLinkManager, string]>) {
- socketLink.$internal.subscribeOnce("unsubscribe", () => setLinkManager(null))
-
const [payload, connectionIdentity] = socketLink.payload
- setLinkManager(new LinkManager(application, socketLink, payload, connectionIdentity))
+ const manager = new LinkManager(application, socketLink, payload, connectionIdentity)
+
+ socketLink.$internal.subscribeOnce("unsubscribe", () => {
+
+ manager.dispose()
+
+ setLinkManager(current => current === manager ? null : current)
+ })
+
+ setLinkManager(manager)
}, [application]))
const connection = usePromise(async () => application.clientLink.subscribe(), [application, connectionRevision])
@@ -93,19 +100,28 @@ function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {
useReady("connection")
+ const appearance = useProperty(linkManager.appearance)
+
const theme = useProperty(linkManager.theme)
return <LinkManagerContext.Provider value={linkManager}>
- <ThemeProvider theme={theme}>
+ <AppearanceProvider appearance={appearance} theme={theme}>
- <div className="grid min-h-0" style={{ backgroundColor: theme.background }}>
+ <ConnectedAppearance>
<Authentication />
- </div>
+ </ConnectedAppearance>
- </ThemeProvider>
+ </AppearanceProvider>
</LinkManagerContext.Provider>
}
+
+function ConnectedAppearance({ children }: { children: React.ReactNode }) {
+
+ const background = useResolveTheme(LinkManagerContext.useValue().appearance.value.background)
+
+ return <div className="grid min-h-0" style={{ backgroundColor: background }}>{children}</div>
+}
diff --git a/source/server/core/appearance-manager.ts b/source/server/core/appearance-manager.ts
new file mode 100644
index 0000000..dba40de
--- /dev/null
+++ b/source/server/core/appearance-manager.ts
@@ -0,0 +1,106 @@
+import { extname } from "node:path"
+import Keyv from "keyv"
+import { z } from "zod"
+import {
+ appearanceLimits,
+ createAppearanceSnapshot,
+ standardAppearance,
+ type Appearance,
+ type AppearanceRange
+} from "@phreshos/core"
+import ServedFileManager from "./served-file-manager"
+
+const servedFileSchema = z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.[a-z0-9]+$/)
+const wallpaperSchema = servedFileSchema.nullable()
+const wallpaperExtensions = new Set(["avif", "bmp", "gif", "jpeg", "jpg", "png", "svg", "webp"])
+
+const surfaceSchema = z.strictObject({
+ grain: bounded(appearanceLimits.surface.grain),
+ grainAmount: bounded(appearanceLimits.surface.grainAmount),
+ backdrop: bounded(appearanceLimits.surface.backdrop),
+ opacity: bounded(appearanceLimits.surface.opacity),
+ distortion: bounded(appearanceLimits.surface.distortion),
+ waves: bounded(appearanceLimits.surface.waves),
+ ripples: bounded(appearanceLimits.surface.ripples),
+ saturation: bounded(appearanceLimits.surface.saturation),
+ brightness: bounded(appearanceLimits.surface.brightness)
+})
+
+/** The sole schema for authoritative System Appearance state. */
+export const appearanceSchema: z.ZodType<Appearance> = z.strictObject({
+ background: themed(z.string().min(1)),
+ foreground: themed(z.string().min(1)),
+ accent: themed(z.string().min(1)),
+ spacing: shared(bounded(appearanceLimits.spacing)),
+ radius: shared(bounded(appearanceLimits.radius)),
+ surface: themed(surfaceSchema),
+ signInWallpaper: themed(wallpaperSchema),
+ desktopWallpaper: themed(wallpaperSchema)
+})
+
+const properties = Object.keys(standardAppearance) as (keyof Appearance)[]
+
+/** Durable, complete Appearance state owned by Server Core. */
+export default class AppearanceManager {
+ private constructor(
+ private readonly store: Keyv,
+ private readonly servedFiles: ServedFileManager,
+ private current: Appearance
+ ) { }
+
+ public static async open(store: Keyv, servedFiles: ServedFileManager) {
+ const entries = await Promise.all(properties.map(async property => ({
+ property,
+ value: await store.get(`appearance:${property}`)
+ })))
+ const stored = Object.fromEntries(entries.map(({ property, value }) => [
+ property,
+ value === undefined ? standardAppearance[property] : value
+ ]))
+ const appearance = createAppearanceSnapshot(appearanceSchema.parse(stored))
+
+ await Promise.all(entries
+ .filter(({ value }) => value === undefined)
+ .map(({ property }) => store.set(`appearance:${property}`, appearance[property])))
+
+ return new AppearanceManager(store, servedFiles, appearance)
+ }
+
+ public get value() { return this.current }
+
+ public async update(value: unknown) {
+ const appearance = createAppearanceSnapshot(appearanceSchema.parse(value))
+
+ this.validateWallpaper(appearance.signInWallpaper.light)
+ this.validateWallpaper(appearance.signInWallpaper.dark)
+ this.validateWallpaper(appearance.desktopWallpaper.light)
+ this.validateWallpaper(appearance.desktopWallpaper.dark)
+
+ await Promise.all(properties.map(property => storeProperty(this.store, property, appearance[property])))
+ this.current = appearance
+
+ return appearance
+ }
+
+ private validateWallpaper(file: string | null) {
+ if (file === null) return
+ if (!wallpaperExtensions.has(extname(file).slice(1))) throw new Error("A wallpaper must be an image file")
+ this.servedFiles.describe(file)
+ }
+}
+
+function shared<Schema extends z.ZodType>(schema: Schema) {
+ return z.strictObject({ light: schema })
+}
+
+function themed<Schema extends z.ZodType>(schema: Schema) {
+ return z.strictObject({ light: schema, dark: schema })
+}
+
+function bounded(range: AppearanceRange) {
+ return z.number().min(range.minimum).max(range.maximum)
+}
+
+function storeProperty(store: Keyv, property: keyof Appearance, value: Appearance[keyof Appearance]) {
+ return store.set(`appearance:${property}`, value)
+}
diff --git a/source/server/core/application.ts b/source/server/core/application.ts
index cc5329e..66c2667 100644
--- a/source/server/core/application.ts
+++ b/source/server/core/application.ts
@@ -4,8 +4,7 @@ import FileManager from "@libs/file-manager"
import Encryptor from "@libs/encryptor"
import ServedFileManager from "./served-file-manager"
import DialogManager from "./dialog-manager"
-import ThemeManager from "./theme-manager"
-import WallpaperManager from "./wallpaper-manager"
+import AppearanceManager from "./appearance-manager"
import openStore from "./open-store"
import Keyv from "keyv"
import FileArea from "@libs/file-area"
@@ -39,9 +38,7 @@ export default class Application {
public readonly dialogManager: DialogManager
- public readonly themeManager: ThemeManager
-
- public readonly wallpaperManager: WallpaperManager
+ public readonly appearanceManager: AppearanceManager
public readonly linkManager: LinkManager
@@ -67,12 +64,10 @@ export default class Application {
this.authentication = payload.authentication
- this.themeManager = payload.themeManager
-
- this.wallpaperManager = payload.wallpaperManager
-
this.servedFiles = payload.servedFiles
+ this.appearanceManager = payload.appearanceManager
+
this.dialogManager = new DialogManager()
this.linkManager = new LinkManager(this)
@@ -92,18 +87,14 @@ export default class Application {
const authentication = await Authentication.open(storage.join("credentials.json"), store)
- const themeManager = await ThemeManager.open(store)
-
const servedFiles = new ServedFileManager(storage.navigateTo("uploads"))
- const wallpaperManager = await WallpaperManager.open(store, servedFiles)
+ const appearanceManager = await AppearanceManager.open(store, servedFiles)
- const application = new Application({ name, displayName, version, defaultProgramIcon, storage, home, store, encryptor, authentication, themeManager, wallpaperManager, servedFiles })
+ const application = new Application({ name, displayName, version, defaultProgramIcon, storage, home, store, encryptor, authentication, appearanceManager, servedFiles })
await application.linkManager.authManager.programManager.initialize()
- await application.wallpaperManager.initialize(application.linkManager.authManager.programManager)
-
return application
}
}
@@ -128,9 +119,7 @@ interface ApplicationPayload {
authentication: Authentication
- themeManager: ThemeManager
-
- wallpaperManager: WallpaperManager
+ appearanceManager: AppearanceManager
servedFiles: ServedFileManager
}
diff --git a/source/server/core/link-manager/auth-manager/auth-manager.ts b/source/server/core/link-manager/auth-manager/auth-manager.ts
index 4da2a51..7b37e8c 100644
--- a/source/server/core/link-manager/auth-manager/auth-manager.ts
+++ b/source/server/core/link-manager/auth-manager/auth-manager.ts
@@ -84,11 +84,10 @@ export default class AuthManager extends TheLink {
return this.programManager.streamArea(identity, area, path)
}
- /** Replace the system Theme through the authenticated boundary. */
- @Subscribe("/theme")
- public async updateTheme(value: unknown) {
+ /** Replace System Appearance through the authenticated boundary. */
+ public async updateAppearance(value: unknown) {
- return await this.linkManager.updateTheme(value)
+ return await this.linkManager.updateAppearance(value)
}
@Connect("/permission/granted")
diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
index 59c8fa1..4828b08 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
@@ -155,8 +155,6 @@ export default class ProcessManager extends TheLink {
const window = this.windowOf(identity)
- if (window.layer === "wallpaper") throw new Error("A wallpaper Window is managed by the system")
-
return window
}
@@ -728,7 +726,7 @@ export default class ProcessManager extends TheLink {
(values, reason) => this.rejectQuestion(values, reason),
- this.authManager.linkManager.theme.tunnel
+ this.authManager.linkManager.appearance.tunnel
)
this.bindServer(process, server)
@@ -973,8 +971,6 @@ export default class ProcessManager extends TheLink {
if (!process.client) throw new Error("The client endpoint is already stopped")
- if (process.client.window.layer === "wallpaper") throw new Error("A wallpaper Client cannot be stopped; exit the Process instead")
-
if (!process.server) throw new Error("The final live endpoint cannot be stopped; exit the Process instead")
await this.deactivateClient(process)
@@ -1442,44 +1438,13 @@ export default class ProcessManager extends TheLink {
return [programManager.find(created.identity)]
}
- if (word === "theme") return [this.authManager.linkManager.theme.value]
-
- if (word === "update-theme") return [await this.authManager.updateTheme(rest[0])]
-
- if (word === "wallpaper") {
-
- const surface = rest[0]
-
- const operation = rest[1]
-
- const link = this.authManager.linkManager
-
- if (surface === "sign-in") {
-
- if (operation === "set") return [await link.setSignInWallpaper(rest[2])]
-
- if (operation === "remove") return [await link.removeSignInWallpaper()]
-
- throw new Error(`The host does not know the sign-in wallpaper operation "${String(operation)}"`)
- }
-
- if (surface === "desktop") {
-
- if (operation === "set") return [await link.setDesktopWallpaper(rest[2])]
-
- if (operation === "remove") return [await link.removeDesktopWallpaper()]
-
- if (operation === "set-program") {
-
- const program = this.heldProgram(rest[2])
+ if (word === "appearance") return [this.authManager.linkManager.appearance.value]
- return [await link.setDesktopWallpaperProgram(program, rest[3] as import("@phreshos/core").WallpaperLaunch)]
- }
+ if (word === "update-appearance") {
- throw new Error(`The host does not know the desktop wallpaper operation "${String(operation)}"`)
- }
+ await this.authManager.updateAppearance(rest[0])
- throw new Error(`The host does not know the wallpaper surface "${String(surface)}"`)
+ return []
}
if (word === "fork") {
@@ -2366,7 +2331,7 @@ export default class ProcessManager extends TheLink {
const window = process.client?.window
- if (!process.client || !window || window.layer === "wallpaper" || window.minimized || window.layer !== layer) continue
+ if (!process.client || !window || window.minimized || window.layer !== layer) continue
if (window.depth <= depth) continue
@@ -2462,12 +2427,7 @@ export interface StandardShape extends ShapeBase {
layer: Layer
}
-export interface WallpaperShape extends ShapeBase {
-
- layer: "wallpaper"
-}
-
-export type Shape = StandardShape | WallpaperShape
+export type Shape = StandardShape
type EndpointEvent = "endpointStart" | "endpointStop"
diff --git a/source/server/core/link-manager/auth-manager/process-manager/process.ts b/source/server/core/link-manager/auth-manager/process-manager/process.ts
index 1a781fb..1f3d528 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/process.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/process.ts
@@ -112,13 +112,13 @@ export default class Process {
this.hostTraffic = hostTraffic
}
- public startServer(child: ChildProcess, ended: (boundary: ServerProcessBoundary, code: number | null, signal: NodeJS.Signals | null) => Promise<void> | void, unanswered: (values: unknown[], reason: string) => void, theme: Tunnel) {
+ public startServer(child: ChildProcess, ended: (boundary: ServerProcessBoundary, code: number | null, signal: NodeJS.Signals | null) => Promise<void> | void, unanswered: (values: unknown[], reason: string) => void, appearance: Tunnel) {
if (this.server) return this.server
let boundary!: ServerProcessBoundary
- boundary = new ServerProcessBoundary(child, this.program.client !== null, (code, signal) => ended(boundary, code, signal), unanswered, this.hostTraffic, theme)
+ boundary = new ServerProcessBoundary(child, this.program.client !== null, (code, signal) => ended(boundary, code, signal), unanswered, this.hostTraffic, appearance)
this.server = boundary
diff --git a/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts b/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts
index ff560bb..2b80f22 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts
@@ -43,9 +43,9 @@ export default class ServerProcessBoundary extends ProcessLink {
private readonly hostSubscriptions = new Map<string, () => void>()
- private readonly themeSubscriptions = new Set<string>()
+ private readonly appearanceSubscriptions = new Set<string>()
- private stopTheme: (() => void) | null = null
+ private stopAppearance: (() => void) | null = null
private readonly child: ChildProcess
@@ -53,13 +53,13 @@ export default class ServerProcessBoundary extends ProcessLink {
private readonly hostTraffic: HostTraffic
- private readonly theme: Tunnel
+ private readonly appearance: Tunnel
private readonly unanswered: (values: unknown[], reason: string) => void
public readonly finished: Promise<{ code: number | null, signal: NodeJS.Signals | null }>
- public constructor(child: ChildProcess, clientDeclared: boolean, ended: Ending, unanswered: (values: unknown[], reason: string) => void, hostTraffic: HostTraffic, theme: Tunnel) {
+ public constructor(child: ChildProcess, clientDeclared: boolean, ended: Ending, unanswered: (values: unknown[], reason: string) => void, hostTraffic: HostTraffic, appearance: Tunnel) {
super(child, messagepack.serialize, messagepack.deserialize)
@@ -80,7 +80,7 @@ export default class ServerProcessBoundary extends ProcessLink {
this.hostTraffic = hostTraffic
- this.theme = theme
+ this.appearance = appearance
this.unanswered = unanswered
@@ -266,11 +266,11 @@ export default class ServerProcessBoundary extends ProcessLink {
this.hostSubscriptions.clear()
- this.themeSubscriptions.clear()
+ this.appearanceSubscriptions.clear()
- this.stopTheme?.()
+ this.stopAppearance?.()
- this.stopTheme = null
+ this.stopAppearance = null
this.subscriptions.clear()
@@ -335,13 +335,13 @@ export default class ServerProcessBoundary extends ProcessLink {
this.subscriptions.set(subscription, description)
- if (themeSubscription(description)) {
+ if (appearanceSubscription(description)) {
- this.themeSubscriptions.add(subscription)
+ this.appearanceSubscriptions.add(subscription)
- if (!this.stopTheme) this.stopTheme = this.theme.subscribe("change", theme => {
+ if (!this.stopAppearance) this.stopAppearance = this.appearance.subscribe("change", appearance => {
- this.deliver("host-theme", "change", theme).catch(() => undefined)
+ this.deliver("host-appearance", "change", appearance).catch(() => undefined)
})
}
@@ -421,11 +421,11 @@ export default class ServerProcessBoundary extends ProcessLink {
this.hostSubscriptions.delete(subscription)
- if (this.themeSubscriptions.delete(subscription) && this.themeSubscriptions.size === 0) {
+ if (this.appearanceSubscriptions.delete(subscription) && this.appearanceSubscriptions.size === 0) {
- this.stopTheme?.()
+ this.stopAppearance?.()
- this.stopTheme = null
+ this.stopAppearance = null
}
}
@@ -480,9 +480,9 @@ interface EndpointSubscription {
subject: string | null
}
-function themeSubscription(subscription: EndpointSubscription) {
+function appearanceSubscription(subscription: EndpointSubscription) {
- return subscription.kind === "publish" && subscription.route === "host-theme" && (subscription.event === null || subscription.event === "change")
+ return subscription.kind === "publish" && subscription.route === "host-appearance" && (subscription.event === null || subscription.event === "change")
}
function isTrafficKind(value: unknown): value is TrafficKind {
diff --git a/source/server/core/link-manager/auth-manager/process-manager/window.ts b/source/server/core/link-manager/auth-manager/process-manager/window.ts
index 36ab6f8..ae991dd 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/window.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/window.ts
@@ -49,9 +49,7 @@ export interface Shown {
url: string | null
- // Which runtime layer this Window occupies. Ordinary clients are confined
- // to the three authorable layers; the system assigns its wallpaper Window
- // the dedicated fourth value.
+ // Which structurally isolated Desktop layer this Window occupies.
layer: WindowLayer
// Which page of the client half to open, beneath its declared root.
@@ -81,8 +79,7 @@ export default class Window {
// lets a program under development be shown from its own dev server.
public readonly url: string | null
- // The Window's authoritative runtime layer. `wallpaper` can only be
- // assigned by the system's dedicated wallpaper launch path.
+ // The Window's authoritative Desktop layer.
public readonly layer: WindowLayer
// Which of the half's own pages the frame opens on.
diff --git a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
index d9be08a..62b0a81 100644
--- a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
+++ b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
@@ -13,9 +13,9 @@ import { dirname, isAbsolute, join } from "node:path"
import { isDeepStrictEqual } from "node:util"
import Logs, { type LogSource } from "./logs"
import { isValue, layers, type Layer, type Position, type ProgramConfig, type Size } from "./config"
-import { type PermissionName, type ProgramCommandChunk, type WallpaperLaunch } from "@phreshos/core"
+import { type PermissionName, type ProgramCommandChunk } from "@phreshos/core"
import { type default as Process, type ProcessLaunch, type Stream } from "../process-manager/process"
-import { type StandardShape, type WallpaperShape } from "../process-manager/process-manager"
+import { type StandardShape } from "../process-manager/process-manager"
import Program, { type CommandOutput, type InstallOutput } from "./program"
import Entry, { type HostedEntry } from "./entry"
import Keyv from "keyv"
@@ -1038,7 +1038,7 @@ export default class ProgramManager extends TheLink {
if (typeof parent === "string" && !creator) throw new Error("The system does not know the parent process")
- return await this.start(program, launch, undefined, creator ?? null, false, false, resolved)
+ return await this.start(program, launch, undefined, creator ?? null, false, resolved)
})
}
@@ -1187,7 +1187,7 @@ export default class ProgramManager extends TheLink {
return { options, server, client, shape, intent }
}
- private async start(program: Program, launch: Launch = {}, watching?: Watching, parent: Process | null = null, transitionOwnsIdentity = false, wallpaper = false, prepared?: ReturnType<ProgramManager["resolveLaunch"]>) {
+ private async start(program: Program, launch: Launch = {}, watching?: Watching, parent: Process | null = null, transitionOwnsIdentity = false, prepared?: ReturnType<ProgramManager["resolveLaunch"]>) {
if (!transitionOwnsIdentity && this.changing.has(program.identity)) throw new Error("This program is changing and cannot create a process")
@@ -1200,7 +1200,7 @@ export default class ProgramManager extends TheLink {
const { options, server, client } = resolved
- const shape = client ? wallpaper ? this.wallpaperShape(resolved.shape!) : resolved.shape : null
+ const shape = client ? resolved.shape : null
// Recheck the program-local name immediately before registration,
// then create and register without yielding so concurrent launches
@@ -1256,14 +1256,6 @@ export default class ProgramManager extends TheLink {
return identity
}
- /** Creates the one protected Process representation used as desktop wallpaper. */
- public async startWallpaper(program: Program, launch: WallpaperLaunch = {}) {
-
- if (!program.client) throw new Error("A desktop wallpaper Program must declare a Client")
-
- return await this.start(program, { ...launch, client: launch.client ?? true }, undefined, null, false, true)
- }
-
/** Starts one fresh server endpoint incarnation for a Process. */
public spawnServer(program: Program) {
@@ -1361,22 +1353,6 @@ export default class ProgramManager extends TheLink {
}
}
- private wallpaperShape(shape: StandardShape): WallpaperShape {
-
- return {
-
- ...shape,
-
- position: { x: "0/1", y: "0/1" },
-
- size: { width: "1/1", height: "1/1" },
-
- layer: "wallpaper",
-
- minimize: false
- }
- }
-
public toJSON() {
return {
diff --git a/source/server/core/link-manager/link-manager.ts b/source/server/core/link-manager/link-manager.ts
index 2fd09ab..4557727 100644
--- a/source/server/core/link-manager/link-manager.ts
+++ b/source/server/core/link-manager/link-manager.ts
@@ -4,8 +4,7 @@ import TheLink from "@libs/the-link/the-link"
import Property from "@libs/the-link/property"
import { Transmitted } from "@libs/messagepack"
import Application from "../application"
-import { type ThemeProperties, type WallpaperLaunch } from "@phreshos/core"
-import { type default as Program } from "./auth-manager/program-manager/program"
+import { type Appearance } from "@phreshos/core"
import { type AuthenticationState, type RegistrationError } from "../authentication/authentication"
export default class LinkManager extends TheLink {
@@ -17,16 +16,10 @@ export default class LinkManager extends TheLink {
public readonly authManager: AuthManager
- /** Public, read-only representation of the authoritative system Theme. */
- public readonly theme: Property<ThemeProperties>
+ /** Public, unresolved representation of authoritative System Appearance. */
+ public readonly appearance: Property<Appearance>
- /** Public sign-in wallpaper filename, or `null` for the bundled asset. */
- public readonly signInWallpaper: Property<string | null>
-
- /** Public desktop file wallpaper, or `null` when bundled or Program-backed. */
- public readonly desktopWallpaper: Property<string | null>
-
- private updatingTheme: Promise<void> = Promise.resolve()
+ private updatingAppearance: Promise<void> = Promise.resolve()
public constructor(application: Application) {
@@ -34,11 +27,7 @@ export default class LinkManager extends TheLink {
this.application = application
- this.theme = Property.private(this, this.application.themeManager.value)
-
- this.signInWallpaper = Property.private(this, this.application.wallpaperManager.signIn)
-
- this.desktopWallpaper = Property.private(this, this.application.wallpaperManager.desktopFile)
+ this.appearance = Property.private(this, this.application.appearanceManager.value)
this.authManager = new AuthManager(this)
}
@@ -183,58 +172,23 @@ export default class LinkManager extends TheLink {
if (!this.connected(session)) await this.application.authentication.disconnectSession(session)
}
- /** Persist and publish one authorized Theme replacement in call order. */
- public updateTheme(value: unknown) {
+ /** Persist and publish one authorized Appearance replacement in call order. */
+ public updateAppearance(value: unknown) {
- const update = this.updatingTheme.then(async () => {
+ const update = this.updatingAppearance.then(async () => {
- const theme = await this.application.themeManager.update(value)
+ const appearance = await this.application.appearanceManager.update(value)
- await this.theme.update(theme)
+ await this.appearance.update(appearance)
- return theme
+ return appearance
})
- this.updatingTheme = update.then(() => undefined, () => undefined)
+ this.updatingAppearance = update.then(() => undefined, () => undefined)
return update
}
- public async setSignInWallpaper(file: unknown) {
-
- const selected = await this.application.wallpaperManager.setSignIn(file)
-
- await this.signInWallpaper.update(selected)
- }
-
- public async removeSignInWallpaper() {
-
- await this.application.wallpaperManager.removeSignIn()
-
- await this.signInWallpaper.update(null)
- }
-
- public async setDesktopWallpaper(file: unknown) {
-
- const selected = await this.application.wallpaperManager.setDesktopFile(file, this.authManager.programManager)
-
- await this.desktopWallpaper.update(selected)
- }
-
- public async setDesktopWallpaperProgram(program: Program, launch: WallpaperLaunch) {
-
- await this.application.wallpaperManager.setDesktopProgram(program, launch, this.authManager.programManager)
-
- await this.desktopWallpaper.update(null)
- }
-
- public async removeDesktopWallpaper() {
-
- await this.application.wallpaperManager.removeDesktop(this.authManager.programManager)
-
- await this.desktopWallpaper.update(null)
- }
-
// Nothing about the link itself crosses. The declaration stays, so
// what a session is born with is stated rather than inferred from
// whatever the object happens to hold.
@@ -242,11 +196,7 @@ export default class LinkManager extends TheLink {
return {
- theme: this.theme,
-
- signInWallpaper: this.signInWallpaper,
-
- desktopWallpaper: this.desktopWallpaper
+ appearance: this.appearance
}
}
}
diff --git a/source/server/core/theme-manager.ts b/source/server/core/theme-manager.ts
deleted file mode 100644
index f5bd074..0000000
--- a/source/server/core/theme-manager.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import Keyv from "keyv"
-import { z } from "zod"
-import { createThemeSnapshot, standardTheme, themeLimits, type ThemeProperties, type ThemeRange } from "@phreshos/core"
-
-const storageKey = "appearance:theme"
-
-/** The authoritative schema for the system Theme. */
-export const themeSchema: z.ZodType<ThemeProperties> = z.strictObject({
- background: z.string().min(1).default(standardTheme.background),
- foreground: z.string().min(1).default(standardTheme.foreground),
- accent: z.string().min(1).default(standardTheme.accent),
- spacing: bounded(themeLimits.spacing).default(standardTheme.spacing),
- radius: bounded(themeLimits.radius).default(standardTheme.radius),
- surface: z.strictObject({
- grain: bounded(themeLimits.surface.grain).default(standardTheme.surface.grain),
- grainAmount: bounded(themeLimits.surface.grainAmount).default(standardTheme.surface.grainAmount),
- backdrop: bounded(themeLimits.surface.backdrop).default(standardTheme.surface.backdrop),
- opacity: bounded(themeLimits.surface.opacity).default(standardTheme.surface.opacity),
- distortion: bounded(themeLimits.surface.distortion).default(standardTheme.surface.distortion),
- waves: bounded(themeLimits.surface.waves).default(standardTheme.surface.waves),
- ripples: bounded(themeLimits.surface.ripples).default(standardTheme.surface.ripples),
- saturation: bounded(themeLimits.surface.saturation).default(standardTheme.surface.saturation),
- brightness: bounded(themeLimits.surface.brightness).default(standardTheme.surface.brightness)
- }).default(standardTheme.surface)
-})
-
-/** Durable, authoritative Theme state owned by the server core. */
-export default class ThemeManager {
-
- private current: ThemeProperties
-
- private constructor(private readonly store: Keyv, theme: ThemeProperties) {
-
- this.current = theme
- }
-
- /** Opens and validates the persisted Theme, or starts from the default. */
- public static async open(store: Keyv) {
-
- const stored = await store.get(storageKey)
-
- const theme = createThemeSnapshot(themeSchema.parse(stored ?? standardTheme))
-
- if (stored === undefined) await store.set(storageKey, theme)
-
- return new ThemeManager(store, theme)
- }
-
- /** The complete immutable Theme snapshot. */
- public get value() {
-
- return this.current
- }
-
- /** Validates and durably replaces the authoritative Theme. */
- public async update(value: unknown) {
-
- const theme = createThemeSnapshot(themeSchema.parse(value))
-
- await this.store.set(storageKey, theme)
-
- this.current = theme
-
- return theme
- }
-}
-
-function bounded(range: ThemeRange) {
-
- return z.number().min(range.minimum).max(range.maximum)
-}
diff --git a/source/server/core/wallpaper-manager.ts b/source/server/core/wallpaper-manager.ts
deleted file mode 100644
index e6ff876..0000000
--- a/source/server/core/wallpaper-manager.ts
+++ /dev/null
@@ -1,198 +0,0 @@
-import { extname } from "node:path"
-import Keyv from "keyv"
-import { z } from "zod"
-import { type WallpaperLaunch } from "@phreshos/core"
-import ServedFileManager from "./served-file-manager"
-import { type default as Program } from "./link-manager/auth-manager/program-manager/program"
-import { type default as ProgramManager } from "./link-manager/auth-manager/program-manager/program-manager"
-
-const signInKey = "appearance:signInWallpaper"
-const desktopKey = "appearance:desktopWallpaper"
-
-const servedFileSchema = z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.[a-z0-9]+$/)
-
-const launchSchema: z.ZodType<WallpaperLaunch> = z.strictObject({
- name: z.string().min(1).optional(),
- server: z.boolean().optional(),
- client: z.strictObject({ location: z.string().optional() }).optional(),
- options: z.record(z.string(), z.string()).optional()
-})
-
-const desktopSchema = z.discriminatedUnion("type", [
-
- z.strictObject({ type: z.literal("file"), file: servedFileSchema }),
-
- z.strictObject({
- type: z.literal("program"),
- program: z.string().min(1),
- launch: launchSchema
- })
-]).nullable()
-
-const signInSchema = servedFileSchema.nullable()
-
-const wallpaperExtensions = new Set(["avif", "bmp", "gif", "htm", "html", "jpeg", "jpg", "png", "svg", "webp"])
-
-export type DesktopWallpaperState = z.infer<typeof desktopSchema>
-
-/** Durable appearance choices and the lifecycle of the optional wallpaper Program. */
-export default class WallpaperManager {
-
- private changing: Promise<void> = Promise.resolve()
-
- private constructor(
- private readonly store: Keyv,
- private readonly servedFiles: ServedFileManager,
- private signInValue: string | null,
- private desktopValue: DesktopWallpaperState
- ) { }
-
- /** Opens and validates only the current appearance keys. */
- public static async open(store: Keyv, servedFiles: ServedFileManager) {
-
- const storedSignIn = await store.get(signInKey)
-
- const storedDesktop = await store.get(desktopKey)
-
- const signIn = signInSchema.parse(storedSignIn ?? null)
-
- const desktop = desktopSchema.parse(storedDesktop ?? null)
-
- if (storedSignIn === undefined) await store.set(signInKey, signIn)
-
- if (storedDesktop === undefined) await store.set(desktopKey, desktop)
-
- return new WallpaperManager(store, servedFiles, signIn, desktop)
- }
-
- /** File selected for sign-in, or `null` for the bundled wallpaper. */
- public get signIn() { return this.signInValue }
-
- /** File selected for the desktop, or `null` when bundled or Program-backed. */
- public get desktopFile() { return this.desktopValue?.type === "file" ? this.desktopValue.file : null }
-
- /** Restores the persisted Program wallpaper after the Program registry exists. */
- public async initialize(programs: ProgramManager) {
-
- const selected = this.desktopValue
-
- if (selected?.type !== "program") return
-
- const program = programs.reach(selected.program)
-
- if (!program) return
-
- try { await programs.startWallpaper(program, selected.launch) }
-
- catch (exception) {
-
- console.log(`wallpaper: ${selected.program} did not start — ${exception instanceof Error ? exception.message : "unavailable"}`)
- }
- }
-
- public setSignIn(file: unknown) {
-
- return this.change(async () => {
-
- const selected = this.file(file)
-
- await this.store.set(signInKey, selected)
-
- this.signInValue = selected
-
- return selected
- })
- }
-
- public removeSignIn() {
-
- return this.change(async () => {
-
- await this.store.set(signInKey, null)
-
- this.signInValue = null
-
- return null
- })
- }
-
- public setDesktopFile(file: unknown, programs: ProgramManager) {
-
- return this.change(async () => {
-
- const selected = this.file(file)
-
- await this.exitProgram(programs)
-
- this.desktopValue = { type: "file", file: selected }
-
- await this.store.set(desktopKey, this.desktopValue)
-
- return selected
- })
- }
-
- public removeDesktop(programs: ProgramManager) {
-
- return this.change(async () => {
-
- await this.exitProgram(programs)
-
- this.desktopValue = null
-
- await this.store.set(desktopKey, null)
-
- return null
- })
- }
-
- public setDesktopProgram(program: Program, value: unknown, programs: ProgramManager) {
-
- return this.change(async () => {
-
- if (!program.client) throw new Error("A desktop wallpaper Program must declare a Client")
-
- const launch = launchSchema.parse(value ?? {})
-
- await this.exitProgram(programs)
-
- this.desktopValue = { type: "program", program: program.identity, launch }
-
- await this.store.set(desktopKey, this.desktopValue)
-
- await programs.startWallpaper(program, launch)
-
- return program.identity
- })
- }
-
- private file(value: unknown) {
-
- const file = servedFileSchema.parse(value)
-
- if (!wallpaperExtensions.has(extname(file).slice(1))) throw new Error("A wallpaper must be an image or HTML file")
-
- this.servedFiles.describe(file)
-
- return file
- }
-
- private async exitProgram(programs: ProgramManager) {
-
- for (const process of [...programs.authManager.processManager.processes.values()]) {
-
- if (process.client?.window.layer !== "wallpaper") continue
-
- await process.exit()
- }
- }
-
- private change<Result>(operation: () => Promise<Result>) {
-
- const changing = this.changing.then(operation)
-
- this.changing = changing.then(() => undefined, () => undefined)
-
- return changing
- }
-}