An open-source, self-hosted system for apps built with web technologies.
Synchronize Window presentation lifecycle
zohayrslileh79e4219f7881
diff --git a/package.json b/package.jsonindex b3b1187..7bc22e6 100644--- a/package.json+++ b/package.json@@ -1,7 +1,7 @@{"name": "phreshos","displayName": "PhreshOS",- "version": "0.1.79",+ "version": "0.1.80","description": "The PhreshOS server, desktop, and authoritative system runtime.","type": "module","private": true,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.tsindex 4b5a9f9..ef92db8 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@@ -334,6 +334,13 @@ export default class ProcessManager extends TheLink {return this.followed(payload)}+ @Subscribe("/set-geometry")+ @Publish("/processes", "inbound")+ protected async setGeometryHandle(payload: { identity: string, window: WindowSnapshot } | null) {++ return this.followed(payload)+ }+@Subscribe("/raise")@Publish("/processes", "inbound")protected async raiseHandle(payload: { identity: string, window: WindowSnapshot } | null) {diff --git a/source/client/view/components/desktop-host/client-process-boundary.ts b/source/client/view/components/desktop-host/client-process-boundary.tsindex aa25297..e9033ab 100644--- a/source/client/view/components/desktop-host/client-process-boundary.ts+++ b/source/client/view/components/desktop-host/client-process-boundary.ts@@ -94,7 +94,7 @@ export default class ClientProcessBoundary extends TheLink {// envelopes only after the new server-host lease exists.const pending = this.pending.splice(0)- if (this.leased) this.presentation.release(this.pane)+ this.presentation.begin(this.pane)this.resetEndpoint()@@ -128,8 +128,6 @@ export default class ClientProcessBoundary extends TheLink {public async release() {- this.presentation.release(this.pane)-const owner = this.leasedthis.owner = nulldiff --git a/source/client/view/components/desktop-host/window-presentation.ts b/source/client/view/components/desktop-host/window-presentation.tsindex 854ec36..cbba678 100644--- a/source/client/view/components/desktop-host/window-presentation.ts+++ b/source/client/view/components/desktop-host/window-presentation.ts@@ -31,6 +31,8 @@ export type PresentationTransactionRequest = Readonly<{/** The only interface through which an iframe changes or observes its Desktop presentation. */export interface WindowPresentationHost {+ /** Begins a new iframe presentation from the authoritative Window state. */+ begin(identity: string): voidread(identity: string, property: WindowPresentationProperty): unknownmove(identity: string, position: Position, transaction?: PresentationTransactionRequest): Promise<void>resize(identity: string, size: Size, transaction?: PresentationTransactionRequest): Promise<void>@@ -45,7 +47,6 @@ export interface WindowPresentationHost {raise(identity: string): voidobserve(identity: string, event: string | null, listener: (event: string, value: unknown) => void): () => voidcomplete(identity: string, kind: "geometry" | "minimize" | "frame", revision: number): void- release(identity: string): void}export function presentationPosition(value: unknown): Position {diff --git a/source/client/view/components/loading.tsx b/source/client/view/components/loading.tsxindex 061dbc8..42875f4 100644--- a/source/client/view/components/loading.tsx+++ b/source/client/view/components/loading.tsx@@ -1,34 +1,21 @@-import { Surface, useAppearance, useThemedValue, type SurfaceProps } from "@phreshos/react-ui"+import { Surface, type SurfaceProps } from "@phreshos/react-ui"import Spinner from "./spinner"type LoadingProps = Omit<SurfaceProps, "material">/** A complete loading surface for unresolved content. */export default function ({ className, style, ...props }: LoadingProps) {- const background = useThemedValue(useAppearance().colors).background+ return <Surface- return <div+ {...props}- className={`inset-0 z-10 ${className ?? ""}`}+ className={`inset-0 z-10 grid ${className ?? ""}`}style={{ ...style, position: "absolute", borderRadius: style?.borderRadius ?? "inherit" }}>- <div- aria-hidden="true"- style={{ position: "absolute", inset: 0, borderRadius: "inherit", backgroundColor: background }}- />+ <Spinner className="m-auto size-6" />- <Surface- {...props}- className="grid"- style={{ position: "absolute", inset: 0, borderRadius: "inherit" }}- >-- <Spinner className="m-auto size-6" />-- </Surface>-- </div>+ </Surface>}diff --git a/source/client/view/components/window-manager/window-presentations.ts b/source/client/view/components/window-manager/window-presentations.tsindex dbff4f4..fbdd931 100644--- a/source/client/view/components/window-manager/window-presentations.ts+++ b/source/client/view/components/window-manager/window-presentations.ts@@ -346,7 +346,7 @@ export default class WindowPresentations implements WindowPresentationHost {}/** A new iframe representation always begins from authoritative truth. */- public release(process: string) {+ public begin(process: string) {const identity = this.live.get(process)if (!identity) returndiff --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.tsindex a0bc7ee..8c19528 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@@ -3186,7 +3186,7 @@ export default class ProcessManager extends TheLink {return { identity, window }}- @Connect("/set-title")+ @Connect("/set-title", "/change-title")public async setTitle(identity: string, title: string) {const window = this.mutableWindowOf(identity)@@ -3198,7 +3198,7 @@ export default class ProcessManager extends TheLink {return { identity, window }}- @Connect("/set-header")+ @Connect("/set-header", "/change-header")public async setHeader(identity: string, header: boolean) {const window = this.mutableWindowOf(identity)@@ -3210,7 +3210,7 @@ export default class ProcessManager extends TheLink {return { identity, window }}- @Connect("/set-frame")+ @Connect("/set-frame", "/change-frame")public async setFrame(identity: string, frame: import("@phreshos/core").WindowFrame) {const window = this.mutableWindowOf(identity)@@ -3222,7 +3222,7 @@ export default class ProcessManager extends TheLink {return { identity, window }}- @Connect("/set-transaction")+ @Connect("/set-transaction", "/change-transaction")public async setTransaction(identity: string, transaction: import("@phreshos/core").WindowTransaction) {const window = this.mutableWindowOf(identity)diff --git a/tests/client-layer-permissions.test.ts b/tests/client-layer-permissions.test.tsindex 4cb2bcf..ee3df13 100644--- a/tests/client-layer-permissions.test.ts+++ b/tests/client-layer-permissions.test.ts@@ -139,7 +139,7 @@ test("Client layer authorization validates explicit choices without reinterpretitest.each(restrictedLayers)("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)+ () => ({ size: { width: 100, height: 100 } }), {} as never, { begin: vi.fn() } as never)const deliver = vi.spyOn(boundary, "deliver").mockResolvedValue()await boundary.own("frame")const program = { identity: f.program.identity, reference: f.program.reference }diff --git a/tests/client-process-boundary-lifecycle.test.ts b/tests/client-process-boundary-lifecycle.test.tsindex 9cc5941..8e9eb08 100644--- a/tests/client-process-boundary-lifecycle.test.ts+++ b/tests/client-process-boundary-lifecycle.test.ts@@ -29,7 +29,7 @@ test("a Client question expectation survives initial iframe ownership", async ()authManager,() => ({ size: { width: 800, height: 600 } }),{} as ClientTraffic,- { release() {} } as unknown as WindowPresentationHost+ { begin() {} } as unknown as WindowPresentationHost)const question = "client:process:question"diff --git a/tests/window-geometry.test.ts b/tests/window-geometry.test.tsindex 526136d..8973998 100644--- a/tests/window-geometry.test.ts+++ b/tests/window-geometry.test.ts@@ -1,8 +1,9 @@import assert from "node:assert/strict"import ClientWindow from "@client/core/link-manager/auth-manager/process-manager/window"+import ClientProcessManager from "@client/core/link-manager/auth-manager/process-manager/process-manager"import ProcessManager from "@server/core/link-manager/auth-manager/process-manager/process-manager"import ServerWindow from "@server/core/link-manager/auth-manager/process-manager/window"-import type ClientProcessManager from "@client/core/link-manager/auth-manager/process-manager/process-manager"+import { TheLink } from "@the-link/core"import { test } from "vitest"test("window geometry contract", async () => {@@ -93,6 +94,19 @@ test("window geometry contract", async () => {"process",authority.toJSON())++ const synchronized = {+ ...authority.toJSON(),+ position: { x: "1/2", y: "0/1" },+ size: { width: "1/2", height: "1/1" }+ } as const+ const clientLink = new TheLink()+ const clientManager = new ClientProcessManager(clientLink as never, { processes: [] })+ clientManager.processes.set("process", { clientEndpoint: { window: counterpart } } as never)+ await clientLink.$inbound.publish("/process/set-geometry", { identity: "process", window: synchronized })+ assert.deepEqual(counterpart.position, synchronized.position)+ assert.deepEqual(counterpart.size, synchronized.size)+await counterpart.setGeometry(next)assert.deepEqual(publications, [["/set-geometry", "process", next]])await counterpart.setTransaction(false)diff --git a/tests/window-presentation.test.ts b/tests/window-presentation.test.tsindex d679dbb..6a7b30b 100644--- a/tests/window-presentation.test.ts+++ b/tests/window-presentation.test.ts@@ -158,7 +158,7 @@ test("presentation geometry events expose each applied representation change", (assert.deepEqual(moves, [{ x: 10, y: 0 }, { x: 20, y: 0 }])})-test("a Client boundary releases its presentation lease exactly once per document", async () => {+test("a Client boundary begins each document from authoritative presentation state without resetting on release", async () => {const lifecycle: string[] = []const boundary = new ClientProcessBoundary("requester",@@ -166,7 +166,7 @@ test("a Client boundary releases its presentation lease exactly once per documen{ processManager: { async ownFrame() {}, async releaseFrame() {} } } as never,() => ({ size: { width: 1, height: 1 } }),{} as never,- { release(identity: string) { lifecycle.push(identity) } } as never+ { begin(identity: string) { lifecycle.push(identity) } } as never)await boundary.own("first-owner")