Skip to content

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

feat: implement exclusive wallpaper clients and layer-owned local operations

zohayrslileh3d6b3c30b0c4
diff --git a/source/client/view/components/desktop-host/local-window.ts b/source/client/view/components/desktop-host/local-window.ts
index ecf7827..b077fb3 100644
--- a/source/client/view/components/desktop-host/local-window.ts
+++ b/source/client/view/components/desktop-host/local-window.ts
@@ -96,6 +96,7 @@ export function parseLocalWindowTransaction(value: unknown): AppearanceTransacti
export function requireLocalSurfaceLayer(layer: WindowLayer) {
if (layer === "window") throw new Error("A standard Window already owns its host Surface")
+ if (layer === "wallpaper") throw new Error("The wallpaper layer does not allow a local Surface")
}
function easing(value: unknown): Easing {
diff --git a/source/client/view/components/desktop-host/system-access.ts b/source/client/view/components/desktop-host/system-access.ts
index 86bbe71..0c8db06 100644
--- a/source/client/view/components/desktop-host/system-access.ts
+++ b/source/client/view/components/desktop-host/system-access.ts
@@ -100,6 +100,7 @@ export default class SystemAccess {
private async clientLayer(launch: ClientLaunch) {
if (launch.layer === "under" || launch.layer === "over") await this.require("layers", [launch.layer])
+ if (launch.layer === "wallpaper") await this.require("wallpaper", [])
}
public async requireNetwork(scope: string) {
diff --git a/source/client/view/components/window-manager/layer-policy.ts b/source/client/view/components/window-manager/layer-policy.ts
new file mode 100644
index 0000000..466fdf0
--- /dev/null
+++ b/source/client/view/components/window-manager/layer-policy.ts
@@ -0,0 +1,30 @@
+import type { WindowLayer } from "@phreshos/core"
+import type { LocalWindowState } from "../desktop-host/local-window"
+
+type PresentationProperty = "title" | "position" | "size" | "minimized" | "maximized" | "depth" | "surface"
+
+/** Properties owned by Desktop for each local Window role. */
+const properties: Readonly<Record<WindowLayer, readonly PresentationProperty[]>> = {
+ window: ["title", "position", "size", "minimized", "maximized", "depth"],
+ under: ["position", "size", "minimized", "maximized", "depth", "surface"],
+ over: ["position", "size", "minimized", "maximized", "depth", "surface"],
+ wallpaper: []
+}
+
+export function requireLocalProperty(layer: WindowLayer, property: PresentationProperty) {
+ if (!properties[layer].includes(property)) {
+ throw new Error(`The ${layer} layer does not allow local ${property} changes`)
+ }
+}
+
+/** A target contributes only properties allowed by the receiving role. */
+export function followedState(current: LocalWindowState, target: LocalWindowState, previous?: LocalWindowState) {
+ const changes: Partial<LocalWindowState> = {}
+ for (const property of properties[current.layer]) {
+ if (property === "surface") continue
+ if (!previous || JSON.stringify(previous[property]) !== JSON.stringify(target[property])) {
+ Object.assign(changes, { [property]: target[property] })
+ }
+ }
+ return changes
+}
diff --git a/source/client/view/components/window-manager/local-windows.ts b/source/client/view/components/window-manager/local-windows.ts
index 58c96b5..8fdb1ef 100644
--- a/source/client/view/components/window-manager/local-windows.ts
+++ b/source/client/view/components/window-manager/local-windows.ts
@@ -1,3 +1,4 @@
+import { followedState, requireLocalProperty } from "./layer-policy"
import ClientState from "@client/core/link-manager/auth-manager/process-manager/client-state"
import {
type AppearanceTransaction,
@@ -36,7 +37,7 @@ export default class LocalWindows implements LocalWindowHost {
this.changed = changed
}
- /** Following projects authoritative property changes, independent of Desktop layer. */
+ /** Following projects the authoritative properties owned by the receiving layer. */
public reconcile(current: ReadonlyMap<string, LocalWindowEntry>) {
for (const [process, identity] of this.live) {
if (current.get(process)?.identity === identity) continue
@@ -51,11 +52,11 @@ export default class LocalWindows implements LocalWindowHost {
const next = new Map(this.windows)
for (const [process, { identity, client }] of current) {
this.live.set(process, identity)
- const snapshot = localState(client)
+ const snapshot = authoritativeState(client)
if (!this.authoritative.has(identity) && client.window.layer === "window") {
this.following.set(identity, { target: identity, snapshot })
}
- if (!next.has(identity)) next.set(identity, snapshot)
+ if (!next.has(identity)) next.set(identity, localState(client))
this.authoritative.set(identity, snapshot)
}
@@ -68,10 +69,7 @@ export default class LocalWindows implements LocalWindowHost {
const state = next.get(identity)!
const target = this.authoritative.get(relation.target)!
const previous = relation.snapshot
- const changes: { -readonly [Key in keyof LocalWindowState]?: LocalWindowState[Key] } = {}
- for (const key of ["title", "position", "size", "minimized", "maximized", "depth"] as const) {
- if (JSON.stringify(previous[key]) !== JSON.stringify(target[key])) Object.assign(changes, { [key]: target[key] })
- }
+ const changes = { ...followedState(state, target, previous) }
const maximized = changes.maximized ?? state.maximized
const minimized = changes.minimized ?? state.minimized
const geometryChanged = ("position" in changes && JSON.stringify(state.position) !== JSON.stringify(changes.position))
@@ -131,29 +129,34 @@ export default class LocalWindows implements LocalWindowHost {
public move(process: string, position: WindowState["position"], transaction?: RequestedTransaction) {
const { identity, state } = this.existing(process)
+ requireLocalProperty(state.layer, "position")
return this.changeGeometry(identity, { position, size: state.size }, transaction)
}
public resize(process: string, size: WindowState["size"], transaction?: RequestedTransaction) {
const { identity, state } = this.existing(process)
+ requireLocalProperty(state.layer, "size")
return this.changeGeometry(identity, { position: state.position, size }, transaction)
}
public geometry(process: string, value: WindowGeometry, transaction?: RequestedTransaction) {
- const { identity } = this.existing(process)
+ const { identity, state } = this.existing(process)
+ requireLocalProperty(state.layer, "position")
return this.changeGeometry(identity, value, transaction)
}
public minimize(process: string, minimized: boolean, transaction?: RequestedTransaction) {
- const { identity } = this.existing(process)
+ const { identity, state } = this.existing(process)
+ requireLocalProperty(state.layer, "minimized")
return this.changeMinimized(identity, minimized, transaction)
}
public maximize(process: string, maximized: boolean, transaction?: RequestedTransaction) {
const { identity, state } = this.existing(process)
+ requireLocalProperty(state.layer, "maximized")
if (state.maximized === maximized) return Promise.resolve()
this.cancel(identity, "geometry")
const animation = transaction && !state.minimized ? localAnimation(++this.revision, transaction) : null
@@ -167,20 +170,15 @@ export default class LocalWindows implements LocalWindowHost {
const snapshot = this.authoritative.get(target.identity)!
this.following.set(identity, { target: target.identity, snapshot })
const current = this.windows.get(identity)!
- const geometryChanged = JSON.stringify([current.position, current.size, current.maximized]) !== JSON.stringify([snapshot.position, snapshot.size, snapshot.maximized])
- const visibilityChanged = current.minimized !== snapshot.minimized
+ const projected = { ...current, ...followedState(current, snapshot) }
+ const geometryChanged = JSON.stringify([current.position, current.size, current.maximized]) !== JSON.stringify([projected.position, projected.size, projected.maximized])
+ const visibilityChanged = current.minimized !== projected.minimized
this.cancel(identity, "geometry")
this.cancel(identity, "minimize")
- const geometryAnimation = geometryChanged && !snapshot.minimized && transaction ? localAnimation(++this.revision, transaction) : null
+ const geometryAnimation = geometryChanged && !projected.minimized && transaction ? localAnimation(++this.revision, transaction) : null
const minimizeAnimation = visibilityChanged && transaction ? localAnimation(++this.revision, transaction) : null
this.replace(identity, {
- ...current,
- title: snapshot.title,
- position: snapshot.position,
- size: snapshot.size,
- minimized: snapshot.minimized,
- maximized: snapshot.maximized,
- depth: snapshot.depth,
+ ...projected,
geometryAnimation,
minimizeAnimation
})
@@ -199,12 +197,14 @@ export default class LocalWindows implements LocalWindowHost {
public title(process: string, title: string) {
const { identity, state } = this.existing(process)
+ requireLocalProperty(state.layer, "title")
this.replace(identity, { ...state, title })
}
public raise(process: string) {
const { identity, state } = this.existing(process)
+ requireLocalProperty(state.layer, "depth")
if (frontmost(this.windows, state.layer) === identity) return
const depth = [...this.windows.values()].reduce((highest, other) => other.layer === state.layer ? Math.max(highest, other.depth) : highest, 0)
this.replace(identity, { ...state, depth: depth + 1 })
@@ -213,6 +213,7 @@ export default class LocalWindows implements LocalWindowHost {
public addSurface(process: string, transaction?: RequestedTransaction) {
const { identity, state } = this.existing(process)
+ requireLocalProperty(state.layer, "surface")
if (state.surface?.visible) return Promise.resolve()
this.cancel(identity, "surface")
@@ -224,6 +225,7 @@ export default class LocalWindows implements LocalWindowHost {
public removeSurface(process: string, transaction?: RequestedTransaction) {
const { identity, state } = this.existing(process)
+ requireLocalProperty(state.layer, "surface")
if (!state.surface || !state.surface.visible) return Promise.resolve()
this.cancel(identity, "surface")
@@ -268,9 +270,9 @@ export default class LocalWindows implements LocalWindowHost {
const client = this.client(process)
if (!client) return
- this.authoritative.set(identity, localState(client))
+ this.authoritative.set(identity, authoritativeState(client))
this.following.delete(identity)
- if (client.window.layer === "window") this.following.set(identity, { target: identity, snapshot: localState(client) })
+ if (client.window.layer === "window") this.following.set(identity, { target: identity, snapshot: authoritativeState(client) })
this.replace(identity, localState(client))
}
@@ -375,6 +377,19 @@ function localAnimation(revision: number, transaction: RequestedTransaction) {
function localState(client: ClientState): LocalWindowState {
+ const window = client.window
+ return {
+ ...authoritativeState(client),
+ title: window.layer === "window" ? window.title : "",
+ position: window.layer === "wallpaper" ? { x: 0, y: 0 } : window.position,
+ size: window.layer === "wallpaper" ? { width: "100%", height: "100%" } : window.size,
+ minimized: window.layer === "wallpaper" ? false : window.minimized,
+ maximized: window.layer === "wallpaper" ? true : window.maximized,
+ depth: window.layer === "wallpaper" ? 0 : window.depth,
+ }
+}
+
+function authoritativeState(client: ClientState): LocalWindowState {
const window = client.window
return {
title: window.title,
diff --git a/source/client/view/components/window-manager/window-manager.ts b/source/client/view/components/window-manager/window-manager.ts
index a2eef3c..39d060d 100644
--- a/source/client/view/components/window-manager/window-manager.ts
+++ b/source/client/view/components/window-manager/window-manager.ts
@@ -13,7 +13,7 @@ import LocalWindows from "./local-windows"
* whether it is shown — nothing else is consulted.
*
* The local representation and authoritative counterpart are distinct.
- * Following starts enabled for ordinary windows and disabled for under/over.
+ * Following starts enabled for ordinary windows and disabled for the other layers.
* Each Client can subsequently follow an authoritative Window or detach.
*
* Departure is representation. The truth drops a stopped client and its
@@ -112,11 +112,17 @@ export default function useWindows(authManager: AuthManager) {
const gone = [...previousClients.current.values()].filter(previous => currentClients.get(previous.record.identity)?.client !== previous.client)
- if (gone.length) setLeaving(function (current) {
+ const departed = new Set(gone.filter(({ client }) => client.window.layer === "wallpaper").map(({ identity }) => identity))
+
+ for (const identity of departed) localWindow.remove(identity)
+
+ const animated = gone.filter(({ identity }) => !departed.has(identity))
+
+ if (animated.length) setLeaving(function (current) {
const retained = new Set(current.map(({ identity }) => identity))
- return [...current, ...gone.filter(({ identity }) => !retained.has(identity))]
+ return [...current, ...animated.filter(({ identity }) => !retained.has(identity))]
})
setOrder(function (current) {
@@ -125,7 +131,7 @@ export default function useWindows(authManager: AuthManager) {
const added = [...currentClients.values()].filter(({ identity }) => !retained.has(identity)).map(({ identity }) => identity)
- return added.length ? [...current, ...added] : current
+ return added.length || departed.size ? [...current.filter(identity => !departed.has(identity)), ...added] : current
})
previousClients.current = currentClients
@@ -150,9 +156,8 @@ export default function useWindows(authManager: AuthManager) {
// does not push a window's number up.
const summit = useCallback((layer: Layer) => [...peer.processes.values()].reduce((highest, process) => process.client?.window.layer === layer ? Math.max(highest, process.client.window.depth) : highest, 0), [peer])
- // The front window of each layer, resolved together. Three separate
- // reductions walked every process three times on every window event.
- const fronts: Record<Layer, Process | null> = { under: null, window: null, over: null }
+ // Resolve the front window of every layer in one pass.
+ const fronts: Record<Layer, Process | null> = { wallpaper: null, under: null, window: null, over: null }
for (const process of records) {
@@ -323,7 +328,7 @@ export default function useWindows(authManager: AuthManager) {
.sort((one, other) => (rank.get(one.identity) ?? Number.MAX_SAFE_INTEGER) - (rank.get(other.identity) ?? Number.MAX_SAFE_INTEGER))
- const panesByLayer: Record<Layer, typeof panes> = { under: [], window: [], over: [] }
+ const panesByLayer: Record<Layer, typeof panes> = { wallpaper: [], under: [], window: [], over: [] }
for (const pane of panes) {
@@ -362,11 +367,7 @@ export default function useWindows(authManager: AuthManager) {
// nothing about the pairing.
show,
- // Filling the surface, and coming back from it. Not a state the
- // system holds: there is no `maximized` any more, only a size —
- // so the memory of where a window was before it filled the
- // surface is kept here, in the interface that offers the button.
- // Whoever offers an undo owns what it undoes.
+ // Toggle authoritative maximization and its local presentation.
fill,
move,
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsx
index 6f8ccf4..757e5cb 100644
--- a/source/client/view/structure/desktop/desktop.tsx
+++ b/source/client/view/structure/desktop/desktop.tsx
@@ -45,7 +45,8 @@ export default function Workspace() {
const [fileWallpaperReady, setFileWallpaperReady] = useState(false)
- const wallpaperReady = fileWallpaperReady
+ const hasWallpaperClient = windows.records.some(record => record.client?.window.layer === "wallpaper")
+ const wallpaperReady = hasWallpaperClient || fileWallpaperReady
const desktop = useRef<HTMLDivElement>(null)
@@ -155,7 +156,7 @@ export default function Workspace() {
stopping={stopping}
- entering={entering}
+ entering={layer === "wallpaper" ? false : entering}
door={application.doors.program}
@@ -231,7 +232,9 @@ export default function Workspace() {
</Taskbar>
- const wallpaper = <WallpaperBackground file={desktopWallpaper} onReady={fileWallpaperLoaded} />
+ const wallpaper = hasWallpaperClient
+ ? renderWindows("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" style={{ color: foreground }}>
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 ffd9ac6..65a6ef8 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
@@ -907,6 +907,15 @@ export default class ProcessManager extends TheLink {
return new Window(shown, shape.position, shape.size, ++this.highest, shape.minimize, shape.maximize)
}
+ /** Checks and claims the wallpaper role in one synchronous activation. */
+ private activateClient(process: Process, window: Window, service: boolean) {
+ if (window.layer === "wallpaper" && [...this.processes.values()].some(
+ current => current.client?.window.layer === "wallpaper"
+ )) throw new Error("A Client Endpoint is already running in the wallpaper layer")
+
+ process.startClient(window, service)
+ }
+
public async register(identity: string, name: string | null, program: Program, options: Options, launch: ProcessLaunch, runtime: ServerRuntime | null, client: boolean, shape: Shape | null, parent: Process | null, registration?: ProcessRegistration) {
if (this.processes.has(identity)) {
@@ -925,7 +934,7 @@ export default class ProcessManager extends TheLink {
// Who had focus before this one opened, in the layer it is
// opening into. A window is born on top of its own layer and
- // takes focus from whoever held it there; the other two layers
+ // takes focus from whoever held it there; the other layers
// do not hear about it.
const front = shape && this.front(shape.layer)
@@ -965,7 +974,7 @@ export default class ProcessManager extends TheLink {
// order: Process creation, endpoint start, endpoint stop, Process exit.
await this.transition(process, async () => {
- if (client && window) process.startClient(window, launch.client?.service ?? false)
+ if (client && window) this.activateClient(process, window, launch.client?.service ?? false)
if (runtime) this.activateServer(process, runtime, launch.server?.service ?? false)
@@ -1188,7 +1197,7 @@ export default class ProcessManager extends TheLink {
const before = this.front(window.layer)
- process.startClient(window, launch.service ?? process.program.client.service)
+ this.activateClient(process, window, launch.service ?? process.program.client.service)
try {
diff --git a/source/server/core/permissions.ts b/source/server/core/permissions.ts
index f5415fb..6676685 100644
--- a/source/server/core/permissions.ts
+++ b/source/server/core/permissions.ts
@@ -291,6 +291,11 @@ export const permissionCatalog = new PermissionCatalog({
title: "Window layers",
description: "Select the under and over layers in Client Endpoint launches."
},
+ wallpaper: {
+ default: [],
+ title: "Wallpaper",
+ description: "Select the wallpaper layer in Client Endpoint launches."
+ },
network: {
default: [],
title: "Network",
diff --git a/tests/client-layer-permissions.test.ts b/tests/client-layer-permissions.test.ts
index 7129b62..b2ca1ee 100644
--- a/tests/client-layer-permissions.test.ts
+++ b/tests/client-layer-permissions.test.ts
@@ -32,7 +32,7 @@ function fixture() {
}
}
-test.each(["under", "over"] as const)("Client launch routes check %s before delegation", async layer => {
+test.each(["under", "over", "wallpaper"] as const)("Client launch routes check %s before delegation", async layer => {
const f = fixture()
const program = { identity: f.program.identity, reference: f.program.reference }
const process = { identity: f.process.identity, reference: f.process.reference }
@@ -44,13 +44,19 @@ test.each(["under", "over"] as const)("Client launch routes check %s before dele
["launch", program, "set", launch],
["start-endpoint", process, "client", { layer }]
] as const
- for (const denied of [{}, { programs: [] }, { layers: [layer === "under" ? "over" : "under"] }, { all: [], layers: false }] satisfies Permissions[]) {
+ const deniedPermissions: Permissions[] = layer === "wallpaper"
+ ? [{}, { programs: [] }, { layers: [] }, { all: [], wallpaper: false }]
+ : [{}, { programs: [] }, { layers: [layer === "under" ? "over" : "under"] }, { all: [], layers: false }, { wallpaper: [] }]
+ for (const denied of deniedPermissions) {
f.permissions(denied)
for (const [operation, ...args] of operations) await expect(f.answer(operation, ...args)).rejects.toThrow("Execution is not permitted")
}
const delegates = [f.createProcess, f.findOrCreateProcess, f.startup, f.savedLaunch, f.startEndpoint]
for (const delegate of delegates) expect(delegate).not.toHaveBeenCalled()
- for (const granted of [{ layers: [layer] }, { layers: [] }, { all: [] }] satisfies Permissions[]) {
+ const grantedPermissions: Permissions[] = layer === "wallpaper"
+ ? [{ wallpaper: [] }, { wallpaper: [], layers: false }, { all: [] }]
+ : [{ layers: [layer] }, { layers: [] }, { all: [] }]
+ for (const granted of grantedPermissions) {
f.permissions(granted)
for (const [operation, ...args] of operations) await f.answer(operation, ...args)
}
@@ -73,7 +79,7 @@ test("Client layer authorization validates explicit choices without reinterpreti
expect(f.createProcess).toHaveBeenCalledOnce()
})
-test.each(["under", "over"] as const)("Client run streams authorize %s before creating an iterator", async layer => {
+test.each(["under", "over", "wallpaper"] as const)("Client run streams authorize %s before creating an iterator", async layer => {
const f = fixture()
const boundary = new ClientProcessBoundary(f.process.identity, { contentWindow: null } as HTMLIFrameElement, f.auth,
() => ({ size: { width: 100, height: 100 } }), {} as never, { release: vi.fn() } as never)
@@ -85,7 +91,7 @@ test.each(["under", "over"] as const)("Client run streams authorize %s before cr
boundary.receive(["end-host", "stream", "denied", "run", program, launch])
await vi.waitFor(() => expect(deliver).toHaveBeenCalledWith("host-end", "stream", "denied", "answer", { success: false, error: "Execution is not permitted" }))
expect(f.command).not.toHaveBeenCalled()
- f.permissions({ layers: [layer] })
+ f.permissions(layer === "wallpaper" ? { wallpaper: [] } : { layers: [layer] })
boundary.receive(["boundary", "expect", "allowed"])
boundary.receive(["end-host", "stream", "allowed", "run", program, launch])
await vi.waitFor(() => expect(deliver).toHaveBeenCalledWith("host-end", "stream", "allowed", "answer", { success: true, result: undefined }))
diff --git a/tests/client-surface.test.ts b/tests/client-surface.test.ts
index c6f169e..abf0941 100644
--- a/tests/client-surface.test.ts
+++ b/tests/client-surface.test.ts
@@ -130,7 +130,8 @@ test("client surface contract", async () => {
await first.move("bare", { x: 125, y: 135 })
ordinary.window.title = "Renamed"
first.reconcile(clients)
- assert.equal(first.state("bare").title, "Renamed")
+ assert.equal(first.state("bare").title, "")
+ assert.throws(() => first.title("bare", "Local title"), /does not allow local title/)
assert.deepEqual(first.state("bare").position, { x: 125, y: 135 })
ordinary.window.position = { x: 230, y: 240 }
first.reconcile(clients)
diff --git a/tests/desktop-wallpaper.test.tsx b/tests/desktop-wallpaper.test.tsx
new file mode 100644
index 0000000..f589bb6
--- /dev/null
+++ b/tests/desktop-wallpaper.test.tsx
@@ -0,0 +1,63 @@
+import { expect, test, vi } from "vitest"
+import { renderToStaticMarkup } from "react-dom/server"
+import { AppearanceProvider } from "@phreshos/react-ui"
+import type Process from "@client/core/link-manager/auth-manager/process-manager/process"
+import Workspace from "@client/view/structure/desktop/desktop"
+
+const fixture = vi.hoisted(() => ({
+ processes: new Map<string, Process>(),
+ pane: vi.fn(), fallback: vi.fn()
+}))
+
+vi.mock("@client/view/contexts", () => ({
+ ApplicationContext: { useValue: () => ({ doors: { program: "/program" } }) },
+ AuthManagerContext: { useValue: () => ({
+ processManager: { processes: fixture.processes },
+ programManager: { programs: new Map([["wallpaper-program", { assetId: "wallpaper-assets" }]]) }
+ }) }
+}))
+vi.mock("@the-link/react", () => ({ ReactTunnel: { useFactory: () => ({ useSubscribe() {} }) } }))
+vi.mock("@client/view/components/desktop-host/client-host", () => ({ default: () => ({}) }))
+vi.mock("@client/view/components/program-access", () => ({ default: () => null }))
+vi.mock("@libs/readiness", () => ({ useRequirement: () => () => {} }))
+vi.mock("@client/view/structure/desktop/taskbar/taskbar", () => ({ default: () => null }))
+vi.mock("@client/view/structure/desktop/wallpaper/wallpaper", () => ({
+ WallpaperBackground: (props: unknown) => { fixture.fallback(props); return <div data-default-wallpaper /> },
+ ReadyWallpaper: () => null
+}))
+vi.mock("@client/view/structure/desktop/windows/process-window", () => ({
+ default: (props: unknown) => { fixture.pane(props); return <iframe title="Wallpaper Client" /> }
+}))
+
+test("Desktop replaces its default wallpaper with the running Client and restores the fallback after stop", () => {
+ const render = () => renderToStaticMarkup(<AppearanceProvider theme="light"><Workspace /></AppearanceProvider>)
+ fixture.processes.clear()
+ fixture.pane.mockClear()
+ fixture.fallback.mockClear()
+ expect(render()).toContain("data-default-wallpaper")
+ expect(fixture.fallback).toHaveBeenCalledOnce()
+
+ const record = {
+ identity: "wallpaper-process", program: "wallpaper-program",
+ client: { window: {
+ layer: "wallpaper", title: "Internal", position: { x: 200, y: 300 },
+ size: { width: 100, height: 100 }, minimized: true, maximized: false, depth: 20
+ } }
+ } as unknown as Process
+ fixture.processes.set(record.identity, record)
+ fixture.fallback.mockClear()
+ const running = render()
+ expect(running).toContain('title="Wallpaper Client"')
+ expect(running).not.toContain("data-default-wallpaper")
+ expect(fixture.fallback).not.toHaveBeenCalled()
+ expect(fixture.pane.mock.lastCall?.[0]).toMatchObject({
+ bare: true, minimized: false, maximized: true, entering: false, localSurface: null,
+ position: { x: 0, y: 0 }, size: { width: "100%", height: "100%" }, depth: 0
+ })
+
+ record.client = null
+ fixture.pane.mockClear()
+ expect(render()).toContain("data-default-wallpaper")
+ expect(fixture.pane).not.toHaveBeenCalled()
+ expect(fixture.fallback).toHaveBeenCalledOnce()
+})
diff --git a/tests/local-window-layers.test.ts b/tests/local-window-layers.test.ts
new file mode 100644
index 0000000..067e2d5
--- /dev/null
+++ b/tests/local-window-layers.test.ts
@@ -0,0 +1,69 @@
+import { expect, test } from "vitest"
+import type { WindowLayer } from "@phreshos/core"
+import LocalWindows, { type LocalWindowEntry } from "@client/view/components/window-manager/local-windows"
+
+function fixture(layer: WindowLayer) {
+ const client = (layer: WindowLayer) => ({ window: {
+ layer, title: "Original", position: { x: 20, y: 30 }, size: { width: 320, height: 240 },
+ minimized: true, maximized: false, depth: 5
+ } })
+ const own = client(layer)
+ const target = client("window")
+ const entries = new Map([
+ ["own", { identity: "own:0", client: own }],
+ ["target", { identity: "target:0", client: target }]
+ ]) as unknown as ReadonlyMap<string, LocalWindowEntry>
+ const windows = new LocalWindows(entries, process => entries.get(process)?.client ?? null)
+ return { own, target, entries, windows }
+}
+
+test("wallpaper local geometry and visibility belong to Desktop, not authoritative state", async () => {
+ const { own, target, entries, windows } = fixture("wallpaper")
+ const initial = windows.projection("own")
+ expect(initial).toMatchObject({ title: "", position: { x: 0, y: 0 }, size: { width: "100%", height: "100%" }, minimized: false, maximized: true, depth: 0, surface: null })
+ const operations = [
+ () => windows.move("own", { x: 1, y: 2 }),
+ () => windows.resize("own", { width: 1, height: 2 }),
+ () => windows.geometry("own", { position: { x: 1, y: 2 }, size: { width: 1, height: 2 } }),
+ () => windows.minimize("own", true), () => windows.maximize("own", false),
+ () => windows.title("own", "Local"), () => windows.raise("own"),
+ () => windows.addSurface("own"), () => windows.removeSurface("own")
+ ]
+ for (const operation of operations) expect(operation).toThrow(/wallpaper layer does not allow/)
+ own.window.position = { x: 500, y: 600 }
+ windows.reconcile(entries)
+ expect(windows.projection("own")).toEqual(initial)
+ await windows.follow("own", "target", { duration: 100, easing: "linear", wait: true })
+ target.window.title = "Changed"
+ target.window.position = { x: 100, y: 200 }
+ target.window.size = { width: 400, height: 500 }
+ target.window.minimized = false
+ target.window.maximized = true
+ target.window.depth = 100
+ windows.reconcile(entries)
+ expect(windows.projection("own")).toEqual(initial)
+ await windows.unfollow("own")
+ expect(own.window.title).toBe("Original")
+ expect(own.window.position).toEqual({ x: 500, y: 600 })
+})
+
+test.each(["under", "over"] as const)("%s follows allowed properties without copying the title", async layer => {
+ const { own, target, entries, windows } = fixture(layer)
+ expect(() => windows.title("own", "Local")).toThrow(/local title/)
+ await windows.follow("own", "target")
+ target.window.title = "Changed"
+ target.window.position = { x: 100, y: 200 }
+ windows.reconcile(entries)
+ expect(windows.projection("own").title).toBe("")
+ expect(windows.projection("own").position).toEqual({ x: 100, y: 200 })
+ expect(own.window.title).toBe("Original")
+ await windows.unfollow("own")
+ target.window.position = { x: 900, y: 900 }
+ windows.reconcile(entries)
+ expect(windows.projection("own").position).toEqual({ x: 100, y: 200 })
+ // The receiving layer defines projection, even when the target is bare.
+ await windows.follow("target", "own")
+ expect(windows.projection("target").title).toBe("Original")
+ windows.title("target", "Local title")
+ expect(windows.projection("target").title).toBe("Local title")
+})
diff --git a/tests/permissions.test.ts b/tests/permissions.test.ts
index 593e4a5..d763227 100644
--- a/tests/permissions.test.ts
+++ b/tests/permissions.test.ts
@@ -25,6 +25,11 @@ test("permissions contract", async () => {
title: "Window layers",
description: "Select the under and over layers in Client Endpoint launches."
},
+ wallpaper: {
+ default: [],
+ title: "Wallpaper",
+ description: "Select the wallpaper layer in Client Endpoint launches."
+ },
network: {
default: [],
title: "Network",
diff --git a/tests/wallpaper-lifecycle.test.ts b/tests/wallpaper-lifecycle.test.ts
new file mode 100644
index 0000000..9ec6ea1
--- /dev/null
+++ b/tests/wallpaper-lifecycle.test.ts
@@ -0,0 +1,84 @@
+import { expect, test, vi } from "vitest"
+import { TheLink } from "@the-link/core"
+import type { ClientLaunch, Layer } from "@phreshos/core"
+import type AuthManager from "@server/core/link-manager/auth-manager/auth-manager"
+import Program from "@server/core/link-manager/auth-manager/program-manager/program"
+import ProcessManager from "@server/core/link-manager/auth-manager/process-manager/process-manager"
+
+function fixture() {
+ const auth = new TheLink() as unknown as AuthManager
+ const manager = new ProcessManager(auth)
+ const program = new Program({ identity: "wallpaper-test", client: { location: "https://example.test/" } })
+ vi.spyOn(program, "validate").mockResolvedValue()
+ const shape = (layer: Layer = "wallpaper") => ({
+ title: "Wallpaper", position: { x: 20, y: 30 }, size: { width: 320, height: 240 },
+ layer, minimize: false, maximize: false
+ })
+ Object.assign(auth, {
+ programManager: {
+ permission() { return null },
+ clientShape(_program: Program, launch: ClientLaunch) { return shape(launch.layer) }
+ }
+ })
+ const register = (identity: string, layer: Layer | null = "wallpaper") => manager.register(
+ identity, null, program, {}, { server: null, client: null, options: {} },
+ null, layer !== null, layer === null ? null : shape(layer), null
+ )
+ return { manager, register }
+}
+
+test("concurrent wallpaper launches have one winner without stopping the incumbent", async () => {
+ const { manager, register } = fixture()
+ const results = await Promise.allSettled([register("first"), register("second")])
+ expect(results.map(result => result.status).sort()).toEqual(["fulfilled", "rejected"])
+ const failure = results.find(result => result.status === "rejected") as PromiseRejectedResult
+ expect(failure.reason.message).toMatch(/already running in the wallpaper layer/)
+ expect(manager.processes.size).toBe(1)
+ const incumbent = [...manager.processes.values()][0]!
+ expect(incumbent.client?.window.layer).toBe("wallpaper")
+ incumbent.client!.window.minimized = true
+ await expect(register("third")).rejects.toThrow(/already running/)
+ expect(incumbent.client).not.toBeNull()
+ await register("ordinary", "window")
+ await register("overlay", "over")
+ await manager.remove(incumbent.identity)
+ expect((await register("replacement")).client?.window.layer).toBe("wallpaper")
+})
+
+test("starting an existing Client and creating a Process share the wallpaper claim", async () => {
+ const { manager, register } = fixture()
+ await register("existing", null)
+ const results = await Promise.allSettled([
+ manager.startClient("existing", { layer: "wallpaper" }), register("new")
+ ])
+ expect(results.filter(result => result.status === "fulfilled")).toHaveLength(1)
+ expect([...manager.processes.values()].filter(process => process.client?.window.layer === "wallpaper")).toHaveLength(1)
+ const incumbent = [...manager.processes.values()].find(process => process.client)!
+ if (incumbent.identity === "existing") {
+ await register("waiting", null)
+ await expect(manager.startClient("waiting", { layer: "wallpaper" })).rejects.toThrow(/already running/)
+ expect(manager.processes.get("waiting")!.client).toBeNull()
+ } else {
+ expect(manager.processes.get("existing")!.client).toBeNull()
+ }
+ await manager.remove(incumbent.identity)
+ const waiting = [...manager.processes.values()].find(process => !process.client)!
+ await manager.startClient(waiting.identity, { layer: "wallpaper" })
+ expect(waiting.client?.window.layer).toBe("wallpaper")
+})
+
+test("failed activation releases the wallpaper claim", async () => {
+ const { manager, register } = fixture()
+ let fail = true
+ manager.$outbound.subscribe("/client-start", () => {
+ if (fail) throw new Error("publication failed")
+ })
+ await expect(register("failed")).rejects.toThrow("publication failed")
+ expect(manager.processes.has("failed")).toBe(false)
+ await register("existing", null)
+ await expect(manager.startClient("existing", { layer: "wallpaper" })).rejects.toThrow("publication failed")
+ expect(manager.processes.get("existing")!.client).toBeNull()
+ fail = false
+ await manager.startClient("existing", { layer: "wallpaper" })
+ expect(manager.processes.get("existing")!.client?.window.layer).toBe("wallpaper")
+})