Skip to content

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

Release PhreshOS 0.1.89

zohayrslileheb582e31f4d0
diff --git a/bun.lock b/bun.lock
index 4a62a66..abafd26 100644
--- a/bun.lock
+++ b/bun.lock
@@ -9,7 +9,7 @@
"@hono/node-server": "^2.1.1",
"@jitl/quickjs-ng-wasmfile-release-sync": "^0.32.0",
"@phreshos/core": "^0.1.59",
- "@phreshos/react-ui": "^0.1.33",
+ "@phreshos/react-ui": "^0.1.34",
"@the-link/core": "^0.3.1",
"@the-link/http": "^0.1.1",
"@the-link/ipc": "^0.2.2",
@@ -201,7 +201,7 @@
"@phreshos/core": ["@phreshos/[email protected]", "", { "dependencies": { "zod": "^4.6.5" } }, "sha512-/9qMUkCIw1qYKc/lDhzkcxpdvkCOmI00jdWoKkoBMGzB13PkN5My1zi0J8Veu2JX0j+h4zmJa5C+0JpQ4PDwmA=="],
- "@phreshos/react-ui": ["@phreshos/[email protected]", "", { "dependencies": { "@base-ui/react": "^1.7.0", "@internationalized/date": "^3.12.3", "@phreshos/core": "^0.1.59", "colorjs.io": "^0.7.1", "motion": "^13.2.0", "react-aria": "^3.51.0", "react-aria-components": "^1.20.0" }, "peerDependencies": { "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-M04X8kPcXmi+JQ/Ogo5A7UJbQDVmeZoICtq5FDgZ7JXuEidOc5klQBX3Bm4UTWpaTvLEf3dwtbV0kX+8De05lQ=="],
+ "@phreshos/react-ui": ["@phreshos/[email protected]", "", { "dependencies": { "@base-ui/react": "^1.7.0", "@internationalized/date": "^3.12.3", "@phreshos/core": "^0.1.59", "colorjs.io": "^0.7.1", "motion": "^13.2.0", "react-aria": "^3.51.0", "react-aria-components": "^1.20.0" }, "peerDependencies": { "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-GaWuftM6hhvxQi5G79TJG8yQ5++O4hfYRXlAvmXzQN00OWAPxAMqq2uw/Xo8TWY9eh68oA+HbfXcQQga/6HcCQ=="],
"@react-types/shared": ["@react-types/[email protected]", "", { "peerDependencies": { "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" } }, "sha512-AzsuD9OfxTOZMMvTRhlN3oHBwOmFN7tDh27LzqmHt4+uOgPhJT7ZM7/kVs/8/o0WxayMUIk3hBmCFRHv1FUoag=="],
diff --git a/package.json b/package.json
index 95d3c2d..92a1eb2 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "phreshos",
"displayName": "PhreshOS",
- "version": "0.1.88",
+ "version": "0.1.89",
"description": "The PhreshOS server, desktop, and authoritative system runtime.",
"type": "module",
"private": true,
@@ -37,8 +37,8 @@
"@fontsource/roboto": "^5.3.0",
"@hono/node-server": "^2.1.1",
"@jitl/quickjs-ng-wasmfile-release-sync": "^0.32.0",
- "@phreshos/core": "^0.1.59",
- "@phreshos/react-ui": "^0.1.33",
+ "@phreshos/core": "^0.1.59",
+ "@phreshos/react-ui": "^0.1.34",
"@the-link/core": "^0.3.1",
"@the-link/http": "^0.1.1",
"@the-link/ipc": "^0.2.2",
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 9fd45bc..55a0192 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
@@ -42,6 +42,20 @@ export default class ProcessManager extends TheLink {
return [...this.processes.values()]
}
+ /**
+ * Observe the complete current collection without a snapshot/subscription
+ * gap. The collection may change between a React render and its effect;
+ * subscribing before the immediate read preserves that transition.
+ */
+ public subscribeProcesses(subscriber: (processes: Process[]) => void) {
+
+ this.$inbound.subscribe("/processes", subscriber)
+
+ subscriber(this.list())
+
+ return () => this.$inbound.unsubscribe("/processes", subscriber)
+ }
+
/** The shown authoritative Window at the front of one projected layer. */
public front(layer: WindowLayer) {
diff --git a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts
index b98fba8..decffd3 100644
--- a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts
+++ b/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts
@@ -44,6 +44,21 @@ export default class ProgramManager extends TheLink {
this.connectTo(this.authManager, "/program")
}
+ private list() {
+
+ return [...this.programs.values()]
+ }
+
+ /** Observe the complete collection without a snapshot/subscription gap. */
+ public subscribePrograms(subscriber: (programs: Program[]) => void) {
+
+ this.$inbound.subscribe("/programs", subscriber)
+
+ subscriber(this.list())
+
+ return () => this.$inbound.unsubscribe("/programs", subscriber)
+ }
+
// A store's five controls, asked of the core. The desktop answers a
// pane's store words with this, so a client half means the same
// thing by them as a server half does — one implementation, two
@@ -175,7 +190,7 @@ export default class ProgramManager extends TheLink {
this.programs.set(payload.identity, new Program(this, payload))
- return [...this.programs.values()]
+ return this.list()
}
@Subscribe("/create")
@@ -219,7 +234,7 @@ export default class ProgramManager extends TheLink {
if (program) await this.$inbound.publish("/forgotten", program)
- return [...this.programs.values()]
+ return this.list()
}
}
diff --git a/source/client/view/components/loading.tsx b/source/client/view/components/loading.tsx
index 42875f4..d870ffd 100644
--- a/source/client/view/components/loading.tsx
+++ b/source/client/view/components/loading.tsx
@@ -4,7 +4,9 @@ import Spinner from "./spinner"
type LoadingProps = Omit<SurfaceProps, "material">
/** A complete loading surface for unresolved content. */
-export default function ({ className, style, ...props }: LoadingProps) {
+export default function ({ className, style, children, ...props }: LoadingProps) {
+ const described = children !== undefined
+
return <Surface
{...props}
@@ -15,7 +17,13 @@ export default function ({ className, style, ...props }: LoadingProps) {
>
- <Spinner className="m-auto size-6" />
+ <div className="m-auto grid justify-items-center gap-3" role={described ? "status" : undefined}>
+
+ <Spinner aria-hidden={described ? true : undefined} className="size-6" />
+
+ {described && <span data-loading-message className="text-sm opacity-60">{children}</span>}
+
+ </div>
</Surface>
}
diff --git a/source/client/view/components/window-manager/window-manager.ts b/source/client/view/components/window-manager/window-manager.ts
index 970e8ac..2e25928 100644
--- a/source/client/view/components/window-manager/window-manager.ts
+++ b/source/client/view/components/window-manager/window-manager.ts
@@ -1,10 +1,9 @@
import ClientState from "@client/core/link-manager/auth-manager/process-manager/client-state"
import Process from "@client/core/link-manager/auth-manager/process-manager/process"
-import { ReactTunnel } from "@the-link/react"
import { type Layer, type Position, type Size, type Value } from "@phreshos/core"
-import { useCallback, useRef, useState } from "react"
+import { useCallback, useLayoutEffect, useRef, useState } from "react"
import { type default as AuthManager } from "@client/core/link-manager/auth-manager/auth-manager"
-import WindowPresentations from "./window-presentations"
+import WindowPresentations, { type PresentedWindow } from "./window-presentations"
import { isDesktopReplacementLayer } from "@shared/window-layers"
import { type SharedResizeWindow } from "./shared-resize"
import { type WindowRegion } from "./window-geometry"
@@ -18,17 +17,15 @@ import { type WindowRegion } from "./window-geometry"
* 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. Stopping a Client removes only its execution
- * context; its Client Endpoint-owned authoritative Window remains. The last
- * desktop-owned representation is kept until its exit animation reports
- * done, while the iframe leaves as soon as the stop is confirmed.
+ * Departure is representation. Stopping a Client invalidates its live Window
+ * state. The last desktop-owned representation is kept until its exit
+ * animation reports done, while the iframe leaves as soon as the stop is
+ * confirmed.
*/
export default function useWindows(authManager: AuthManager) {
const peer = authManager.processManager
- const inbound = ReactTunnel.useFactory(peer.$inbound)
-
const [processes, setProcesses] = useState(() => [...peer.processes.values()])
const incarnationIds = useRef(new WeakMap<ClientState, string>())
@@ -46,7 +43,7 @@ export default function useWindows(authManager: AuthManager) {
incarnationIds.current.set(client, identity)
}
- return { identity, record, client }
+ return captureWindowIncarnation(identity, record, client)
}, [])
@@ -72,7 +69,7 @@ export default function useWindows(authManager: AuthManager) {
// not launched, so their representations must not replay an entrance.
const inheritedClients = useRef(new WeakSet([...initialClients.values()].map(({ client }) => client)))
- const [leaving, setLeaving] = useState<WindowIncarnation[]>([])
+ const [leaving, setLeaving] = useState<LeavingWindow[]>([])
// A close press asks the core to terminate the Process. Keep that request
// visible until the Process actually leaves the authoritative collection.
@@ -97,8 +94,6 @@ export default function useWindows(authManager: AuthManager) {
const currentClients = new Map(list.flatMap(record => record.client ? [[record.identity, incarnation(record, record.client)] as const] : []))
- presentation.reconcile(currentClients)
-
let settled = false
for (const identity of stopping.current) {
@@ -114,11 +109,22 @@ export default function useWindows(authManager: AuthManager) {
const gone = [...previousClients.current.values()].filter(previous => currentClients.get(previous.record.identity)?.client !== previous.client)
- const departed = new Set(gone.filter(({ client }) => isDesktopReplacementLayer(client.window.layer)).map(({ identity }) => identity))
-
- for (const identity of departed) presentation.remove(identity)
+ // Window state ends before the Process collection announces departure.
+ // Use the layer captured while this incarnation was live; consulting
+ // the retained Window handle here would abort the collection broadcast.
+ const departed = new Set(gone.filter(({ layer }) => isDesktopReplacementLayer(layer)).map(({ identity }) => identity))
+
+ // The controller now forgets the ended Client, but an ordinary
+ // departure still owns one immutable visual snapshot until its exit
+ // animation completes.
+ const animated = gone
+ .filter(({ identity }) => !departed.has(identity))
+ .flatMap(window => {
+ const retained = captureLeavingWindow(window, presentation.windows)
+ return retained ? [retained] : []
+ })
- const animated = gone.filter(({ identity }) => !departed.has(identity))
+ presentation.reconcile(currentClients)
if (animated.length) setLeaving(function (current) {
@@ -142,7 +148,7 @@ export default function useWindows(authManager: AuthManager) {
}, [incarnation])
- inbound.useSubscribe("/processes", subscriber)
+ useLayoutEffect(() => peer.subscribeProcesses(subscriber), [peer, subscriber])
const records = processes.filter(process => process.client)
@@ -311,7 +317,7 @@ export default function useWindows(authManager: AuthManager) {
return { ...live, presentation: presentations.get(live.identity)!, closing: false, stopping: stopping.current.has(record.identity), entering: !inheritedClients.current.has(live.client) }
}),
- ...leaving.map(window => ({ ...window, presentation: presentations.get(window.identity)!, closing: true, stopping: false, entering: !inheritedClients.current.has(window.client) }))
+ ...leaving.map(window => ({ ...window, closing: true, stopping: false, entering: !inheritedClients.current.has(window.client) }))
]
.sort((one, other) => (rank.get(one.identity) ?? Number.MAX_SAFE_INTEGER) - (rank.get(other.identity) ?? Number.MAX_SAFE_INTEGER))
@@ -451,11 +457,30 @@ export default function useWindows(authManager: AuthManager) {
export type DesktopWindows = ReturnType<typeof useWindows>
-interface WindowIncarnation {
+export interface WindowIncarnation {
identity: string
record: Process
client: ClientState
+
+ layer: Layer
+}
+
+export interface LeavingWindow extends WindowIncarnation {
+
+ presentation: PresentedWindow
+}
+
+export function captureWindowIncarnation(identity: string, record: Process, client: ClientState): WindowIncarnation {
+
+ return { identity, record, client, layer: client.window.layer }
+}
+
+export function captureLeavingWindow(window: WindowIncarnation, presentations: ReadonlyMap<string, PresentedWindow>): LeavingWindow | null {
+
+ const presentation = presentations.get(window.identity)
+
+ return presentation ? { ...window, presentation } : null
}
diff --git a/source/client/view/components/window-manager/window-presentations.ts b/source/client/view/components/window-manager/window-presentations.ts
index efb6f8e..f4ea6cd 100644
--- a/source/client/view/components/window-manager/window-presentations.ts
+++ b/source/client/view/components/window-manager/window-presentations.ts
@@ -307,11 +307,13 @@ export default class WindowPresentations implements WindowPresentationHost {
this.cancel(identity, "geometry", reason)
this.cancel(identity, "surface", reason)
this.cancelIdentityMoveGestures(identity)
- this.representations.delete(identity)
}
private release(identity: string, reason: string) {
this.releaseTransient(identity, reason)
+ // The geometry representation belongs to the mounted Desktop Window,
+ // not to an iframe document that may be replaced inside it.
+ this.representations.delete(identity)
this.moveGestureControllers.delete(identity)
}
}
@@ -383,6 +385,7 @@ function initialPresentationState(client: ClientState): PresentedWindow {
function followStandardWindow(current: PresentedWindow, client: ClientState, revision: number): PresentedWindow {
const window = client.window
const geometryChanged = JSON.stringify([current.position, current.size]) !== JSON.stringify([window.position, window.size])
+ const maximizedChanged = current.maximized !== window.maximized
const minimizedChanged = current.minimized !== window.minimized
return {
...current,
@@ -393,7 +396,9 @@ function followStandardWindow(current: PresentedWindow, client: ClientState, rev
minimized: window.minimized,
maximized: window.maximized,
depth: window.depth,
- geometryAnimation: geometryChanged && !window.minimized
+ // Maximization changes the Desktop-owned projection without changing
+ // the authoritative position or size, so it still needs geometry motion.
+ geometryAnimation: (geometryChanged || maximizedChanged) && !window.minimized
? { revision }
: current.geometryAnimation,
minimizeAnimation: minimizedChanged
diff --git a/source/client/view/structure/authentication/authentication.tsx b/source/client/view/structure/authentication/authentication.tsx
index 549d889..f3020c2 100644
--- a/source/client/view/structure/authentication/authentication.tsx
+++ b/source/client/view/structure/authentication/authentication.tsx
@@ -13,6 +13,7 @@ import { WallpaperStage } from "../desktop/layers/wallpaper/wallpaper"
import { useReady } from "@libs/readiness"
import { useThemedValue } from "@phreshos/react-ui"
import { useProperty } from "@the-link/react"
+import { sessionRequirement, wallpaperRequirement } from "../readiness-requirements"
export default function () {
@@ -109,16 +110,16 @@ export default function () {
function ReadySession({ children }: { children: ReactNode }) {
- useReady("session")
+ useReady(sessionRequirement)
return children
}
function FailedSession({ children }: { children: ReactNode }) {
- useReady("session")
+ useReady(sessionRequirement)
- useReady("wallpaper")
+ useReady(wallpaperRequirement)
return children
}
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsx
index dd1ad25..9f840db 100644
--- a/source/client/view/structure/desktop/desktop.tsx
+++ b/source/client/view/structure/desktop/desktop.tsx
@@ -17,6 +17,7 @@ import { useRequirement } from "@libs/readiness"
import { usePreferences, useThemedValue } from "@phreshos/react-ui"
import { useProperty } from "@the-link/react"
import SharedResizeBoundaries from "./windows/shared-resize-boundaries"
+import { programsRequirement } from "../readiness-requirements"
export default function Workspace() {
@@ -34,7 +35,7 @@ export default function Workspace() {
const windows = useWindows(authManager)
- const completePrograms = useRequirement("programs")
+ const completePrograms = useRequirement(programsRequirement)
const initialPrograms = useRef<ReadonlySet<string> | null>(null)
diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsx
index 7ad23c4..760fc99 100644
--- a/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsx
+++ b/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsx
@@ -1,23 +1,23 @@
-import { ReactTunnel } from "@the-link/react"
import { AuthManagerContext } from "@client/view/contexts"
import ProcessItem from "./process-item"
import { matchesProcess } from "../search"
import { ScrollArea } from "@phreshos/react-ui"
+import { useLayoutEffect, useState } from "react"
/** All live Processes, including those without a Client window. */
export default function Processes({ terms }: Readonly<{ terms: readonly string[] }>) {
const manager = AuthManagerContext.useValue().processManager
- const inbound = ReactTunnel.useFactory(manager.$inbound)
-
- const processes = inbound.useFirstState("/processes", [...manager.processes.values()])
+ const [processes, setProcesses] = useState(() => [...manager.processes.values()])
const programManager = manager.authManager.programManager
- const programsInbound = ReactTunnel.useFactory(programManager.$inbound)
+ const [programs, setPrograms] = useState(() => [...programManager.programs.values()])
+
+ useLayoutEffect(() => manager.subscribeProcesses(setProcesses), [manager])
- const programs = programsInbound.useFirstState("/programs", [...programManager.programs.values()])
+ useLayoutEffect(() => programManager.subscribePrograms(setPrograms), [programManager])
const programsByIdentity = new Map(programs.map(program => [program.identity, program]))
diff --git a/source/client/view/structure/desktop/layers/wallpaper/wallpaper.tsx b/source/client/view/structure/desktop/layers/wallpaper/wallpaper.tsx
index 4f41fe0..1864ca8 100644
--- a/source/client/view/structure/desktop/layers/wallpaper/wallpaper.tsx
+++ b/source/client/view/structure/desktop/layers/wallpaper/wallpaper.tsx
@@ -4,6 +4,7 @@ import { ApplicationContext } from "@client/view/contexts"
import { useEffect, useEffectEvent, useRef, useState, type ReactNode, type TransitionEvent } from "react"
import Loading from "@client/view/components/loading"
import { useReady } from "@libs/readiness"
+import { wallpaperRequirement } from "../../../readiness-requirements"
import { useAppearance, usePreferences } from "@phreshos/react-ui"
import { useReducedMotion } from "@libs/react-motion"
import { cssEasing } from "@client/view/appearance/motion"
@@ -213,7 +214,7 @@ export function WallpaperStage({ file, children }: WallpaperStageProps) {
}
export function ReadyWallpaper() {
- useReady("wallpaper")
+ useReady(wallpaperRequirement)
return null
}
diff --git a/source/client/view/structure/desktop/programs/programs.ts b/source/client/view/structure/desktop/programs/programs.ts
index 3eeaa1a..17f4b68 100644
--- a/source/client/view/structure/desktop/programs/programs.ts
+++ b/source/client/view/structure/desktop/programs/programs.ts
@@ -1,5 +1,5 @@
-import { ReactTunnel } from "@the-link/react"
import { AuthManagerContext } from "@client/view/contexts"
+import { useLayoutEffect, useState } from "react"
/**
* The authorized view's programs: the list the peer re-emits on its
@@ -10,7 +10,11 @@ export default function usePrograms() {
const authManager = AuthManagerContext.useValue()
- const inbound = ReactTunnel.useFactory(authManager.programManager.$inbound)
+ const manager = authManager.programManager
- return inbound.useFirstState("/programs", [...authManager.programManager.programs.values()]).filter(program => program.installed)
+ const [programs, setPrograms] = useState(() => [...manager.programs.values()])
+
+ useLayoutEffect(() => manager.subscribePrograms(setPrograms), [manager])
+
+ return programs.filter(program => program.installed)
}
diff --git a/source/client/view/structure/desktop/windows/process-window.tsx b/source/client/view/structure/desktop/windows/process-window.tsx
index 5ba2bea..a78df30 100644
--- a/source/client/view/structure/desktop/windows/process-window.tsx
+++ b/source/client/view/structure/desktop/windows/process-window.tsx
@@ -12,6 +12,13 @@ import { memo, type SyntheticEvent, useCallback, useEffect, useState } from "rea
const settleDelay = 80
+export function processWindowProgress(layer: WindowLayer, loading: boolean, stopping: boolean, closing: boolean) {
+
+ if (layer !== "window") return null
+
+ return stopping || closing ? "Closing" : loading ? "Loading" : null
+}
+
/**
* One process pane at the React boundary. Its primitive window values are
* props so memoization can see which process actually changed even though
@@ -88,9 +95,9 @@ export default memo(function ({ identity, record, assetId, client, title, header
const frameLoading = programAccess === "available" && (loading.source !== frameSource || loading.phase !== "ready")
- const surfaced = surface !== false && layer !== "wallpaper"
-
- const progress = surfaced && (stopping || closing ? "Closing" : frameLoading ? "Loading" : null)
+ // Raw layers belong to their Programs. Desktop progress paint is part of
+ // the standard Window representation and must never cover raw content.
+ const progress = processWindowProgress(layer, frameLoading, stopping, closing)
return <Window
diff --git a/source/client/view/structure/desktop/windows/window-header.tsx b/source/client/view/structure/desktop/windows/window-header.tsx
index 3991436..bf28768 100644
--- a/source/client/view/structure/desktop/windows/window-header.tsx
+++ b/source/client/view/structure/desktop/windows/window-header.tsx
@@ -1,16 +1,17 @@
-import type { PointerEvent as ReactPointerEvent, ReactNode } from "react"
+import type { ReactNode } from "react"
+import type { BeginWindowMoveGesture } from "@phreshos/core"
import { Window } from "@phreshos/react-ui"
/** Connects Desktop Window behavior to React UI's shared header. */
-export default function WindowHeader({ title, icon, active, whole, stopping, onGrab, onMinimize, onMaximize, onClose }: WindowHeaderProps) {
- return <Window.Header active={active} onPointerDown={onGrab} onDoubleClick={onMaximize}>
+export default function WindowHeader({ title, icon, active, whole, stopping, beginMoveGesture, onMinimize, onMaximize, onClose }: WindowHeaderProps) {
+ return <Window.Header active={active} beginMoveGesture={beginMoveGesture} maximized={whole} onMaximize={onMaximize}>
<Window.Header.Identity icon={icon} title={title} />
<Window.Header.Actions>
{/* The Desktop transfers focus before either operation makes the
iframe unavailable. React Aria must not preserve focus in that
disappearing cross-document target. */}
{onMinimize && <Window.Header.Minimize preventFocusOnPress={false} onPress={onMinimize} />}
- {onMaximize && <Window.Header.Maximize maximized={whole} onPress={onMaximize} />}
+ {onMaximize && <Window.Header.Maximize />}
{onClose && <Window.Header.Close preventFocusOnPress={false} onPress={onClose} disabled={stopping} />}
</Window.Header.Actions>
</Window.Header>
@@ -22,7 +23,7 @@ interface WindowHeaderProps {
active: boolean
whole: boolean
stopping: boolean
- onGrab: (event: ReactPointerEvent<HTMLElement>) => void
+ beginMoveGesture: BeginWindowMoveGesture
onMinimize?: () => void
onMaximize?: () => void
onClose?: () => void
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index 2442444..22901c0 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -1,16 +1,16 @@
-import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useEffect, useLayoutEffect, useRef, useState } from "react"
+import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"
import { useReducedMotion } from "@libs/react-motion"
import { surfaceLifecyclePose, surfacePresencePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"
import WindowPanel from "./window-panel"
import { absoluteWindowGeometry, constrainWindowGeometry, minimumWindowSize, resolveWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
-import { type Position, type Size, type WindowPresentationSurface as WindowSurfaceDefinition, type WindowLayer } from "@phreshos/core"
+import { type BeginWindowMoveGesture, type Position, type Size, type WindowPresentationSurface as WindowSurfaceDefinition, type WindowLayer } from "@phreshos/core"
import WindowHeader from "./window-header"
import WindowSurface, { windowSurfaceRadius } from "./window-surface"
import { type PresentationAnimation, type PresentationMoveGestureController, type PresentationMovePoint } from "@client/view/components/desktop-host/window-presentation"
import { type PresentationGeometryRepresentation } from "@client/view/components/window-manager/window-presentations"
import { motion } from "motion/react"
import { motionTransition, resolveWindowTransaction } from "@client/view/appearance/motion"
-import { useAppearance } from "@phreshos/react-ui"
+import { useAppearance, Window as UIWindow } from "@phreshos/react-ui"
import SnapPreview, { type SnapTarget } from "./snap-preview"
import useWindowGeometryMotion from "./window-geometry-motion"
import { physicalToDesktopPixels, useDesktopScale } from "../desktop-scale"
@@ -88,8 +88,8 @@ export default function ({ title, header = true, surface, layer, icon, children,
const [gesture, setGesture] = useState<Gesture | null>(null)
const [externalMoveActive, setExternalMoveActive] = useState(false)
const externalMove = useRef<ExternalMove | null>(null)
- const beginMoveGesture = useRef<(point: PresentationMovePoint) => ActivePointerGesture | null>(() => null)
- beginMoveGesture.current = point => {
+ const beginPointerGesture = useRef<(point: PresentationMovePoint) => ActivePointerGesture | null>(() => null)
+ beginPointerGesture.current = point => {
let active: ActivePointerGesture | null = null
grab(point, null, gesture => { active = gesture })
return active
@@ -118,7 +118,7 @@ export default function ({ title, header = true, surface, layer, icon, children,
moveGestureController.current = {
begin(origin, point) {
if (externalMove.current) throw new Error("This Window already has an active move gesture")
- const pointer = beginMoveGesture.current(origin)
+ const pointer = beginPointerGesture.current(origin)
if (!pointer) throw new Error("This Window cannot currently begin a move gesture")
pointer.update(point)
let markReady: () => void = () => undefined
@@ -133,6 +133,10 @@ export default function ({ title, header = true, surface, layer, icon, children,
}
}
+ const beginWindowMoveGesture = useCallback<BeginWindowMoveGesture>(start => {
+ return moveGestureController.current!.begin(start.origin, start.point)
+ }, [])
+
function finishExternalMove(point: PresentationMovePoint | null) {
const active = externalMove.current
if (!active) return
@@ -521,10 +525,9 @@ export default function ({ title, header = true, surface, layer, icon, children,
return <>
- {externalMoveActive && createPortal(<div
+ {externalMoveActive && createPortal(<UIWindow.MoveCapture
data-window-move-capture
ref={element => { if (element) externalMove.current?.markReady() }}
- className="fixed inset-0 touch-none select-none cursor-move"
style={{ zIndex: 2147483647 }}
onPointerMove={event => {
if (!event.currentTarget.hasPointerCapture(event.pointerId)) {
@@ -630,7 +633,7 @@ export default function ({ title, header = true, surface, layer, icon, children,
whole={whole}
- onGrab={event => grab(event, null)}
+ beginMoveGesture={beginWindowMoveGesture}
onMinimize={onMinimize}
diff --git a/source/client/view/structure/readiness-requirements.ts b/source/client/view/structure/readiness-requirements.ts
new file mode 100644
index 0000000..94db3bb
--- /dev/null
+++ b/source/client/view/structure/readiness-requirements.ts
@@ -0,0 +1,26 @@
+export interface DesktopReadinessRequirement {
+
+ readonly message: string
+}
+
+export const connectionRequirement = Object.freeze<DesktopReadinessRequirement>({
+ message: "Connecting…"
+})
+
+export const sessionRequirement = Object.freeze<DesktopReadinessRequirement>({
+ message: "Preparing your session…"
+})
+
+export const wallpaperRequirement = Object.freeze<DesktopReadinessRequirement>({
+ message: "Loading wallpaper…"
+})
+
+export const programsRequirement = Object.freeze<DesktopReadinessRequirement>({
+ message: "Loading programs…"
+})
+
+export const startupRequirements = Object.freeze([
+ connectionRequirement,
+ sessionRequirement,
+ wallpaperRequirement
+])
diff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsx
index bbb2a7e..1d57945 100644
--- a/source/client/view/structure/structure.tsx
+++ b/source/client/view/structure/structure.tsx
@@ -11,11 +11,16 @@ import { useDesktopPreferences } from "../appearance/desktop-preferences"
import { useRememberSystemAppearance } from "../appearance/appearance"
import Authentication from "./authentication/authentication"
import { useCallback, useEffect, useState } from "react"
-import Readiness, { useReady } from "@libs/readiness"
+import Readiness, { useReadiness, useReady } from "@libs/readiness"
import { type DesktopPreferencesUpdate } from "@phreshos/core"
import { cssEasing } from "../appearance/motion"
-
-const startupRequirements = ["connection", "session", "wallpaper"] as const
+import {
+ connectionRequirement,
+ sessionRequirement,
+ startupRequirements,
+ type DesktopReadinessRequirement,
+ wallpaperRequirement
+} from "./readiness-requirements"
export default function () {
const appearance = useAppearance()
@@ -24,25 +29,30 @@ export default function () {
<Desktop />
- <Readiness.Pending>
+ <DesktopReadiness appearance={appearance} />
- {pending => <Loading
+ </Readiness>
+}
- aria-hidden={pending.length === 0}
+function DesktopReadiness({ appearance }: { appearance: ReturnType<typeof useAppearance> }) {
+ const { pending } = useReadiness<DesktopReadinessRequirement>()
- className={pending.length ? "opacity-100" : "pointer-events-none opacity-0"}
+ return <Loading
- style={{
- transitionDuration: String(appearance.transaction.duration) + "ms",
- transitionTimingFunction: cssEasing(appearance.transaction.easing),
- transitionProperty: "opacity"
- }}
- />}
+ aria-hidden={pending.length === 0}
- </Readiness.Pending>
+ className={pending.length ? "opacity-100" : "pointer-events-none opacity-0"}
- </Readiness>
+ style={{
+ // New pending work must cover the next representation
+ // immediately; only completed readiness fades away.
+ transitionDuration: pending.length ? "0ms" : String(appearance.transaction.duration) + "ms",
+ transitionTimingFunction: cssEasing(appearance.transaction.easing),
+ transitionProperty: "opacity"
+ }}
+
+ >{pending[0]?.message ?? "Loading…"}</Loading>
}
function Desktop() {
@@ -87,11 +97,11 @@ function Desktop() {
function FailedConnection({ exception, retry }: { exception: unknown, retry: () => void }) {
- useReady("connection")
+ useReady(connectionRequirement)
- useReady("session")
+ useReady(sessionRequirement)
- useReady("wallpaper")
+ useReady(wallpaperRequirement)
return <Alert className="m-auto grid w-fit gap-3">
@@ -104,7 +114,7 @@ function FailedConnection({ exception, retry }: { exception: unknown, retry: ()
function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {
- useReady("connection")
+ useReady(connectionRequirement)
const { preferences, update } = useDesktopPreferences()
diff --git a/source/libs/readiness.tsx b/source/libs/readiness.tsx
index d2d4a86..6408fc4 100644
--- a/source/libs/readiness.tsx
+++ b/source/libs/readiness.tsx
@@ -1,61 +1,59 @@
import { createContext, useCallback, useContext, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react"
/** The immutable state beneath a readiness boundary. */
-export class ReadinessState {
+export class ReadinessState<Requirement = unknown> {
- public readonly requirements: readonly string[]
+ public readonly requirements: readonly Requirement[]
- public readonly pending: readonly string[]
+ public readonly pending: readonly Requirement[]
- private constructor(requirements: readonly string[], pending: readonly string[]) {
+ private constructor(requirements: readonly Requirement[], pending: readonly Requirement[]) {
this.requirements = [...requirements]
this.pending = [...pending]
}
- public static start(requirements: readonly string[]) {
+ public static start<Requirement>(requirements: readonly Requirement[]) {
validate(requirements)
- return new ReadinessState(requirements, requirements)
+ return new ReadinessState<Requirement>(requirements, requirements)
}
/** Mark one known requirement ready. Repeated readiness is harmless. */
- public ready(requirement: string) {
+ public ready(requirement: Requirement) {
- if (!this.requirements.includes(requirement)) throw new Error(`Readiness does not know the requirement "${requirement}"`)
+ if (!hasRequirement(this.requirements, requirement)) throw new Error("Readiness does not know that requirement")
- if (!this.pending.includes(requirement)) return this
+ if (!hasRequirement(this.pending, requirement)) return this
- const pending = this.pending.filter(candidate => candidate !== requirement)
+ const pending = this.pending.filter(candidate => !Object.is(candidate, requirement))
- return new ReadinessState(this.requirements, pending)
+ return new ReadinessState<Requirement>(this.requirements, pending)
}
/** Add new work or restore one completed requirement. */
- public require(requirement: string) {
+ public require(requirement: Requirement) {
- validateRequirement(requirement)
+ if (hasRequirement(this.pending, requirement)) return this
- if (this.pending.includes(requirement)) return this
-
- const requirements = this.requirements.includes(requirement)
+ const requirements = hasRequirement(this.requirements, requirement)
? this.requirements
: [...this.requirements, requirement]
- const restored = new Set([...this.pending, requirement])
+ const restored = [...this.pending, requirement]
- return new ReadinessState(requirements, requirements.filter(candidate => restored.has(candidate)))
+ return new ReadinessState<Requirement>(requirements, requirements.filter(candidate => hasRequirement(restored, candidate)))
}
}
-const ReadinessContext = createContext<ReadinessValue | null>(null)
+const ReadinessContext = createContext<ReadinessValue<unknown> | null>(null)
/** Provides one readiness lifecycle to every operation inside the boundary. */
-export default function Readiness({ requirements, children }: ReadinessProps) {
+export default function Readiness<Requirement>({ requirements, children }: ReadinessProps<Requirement>) {
- const declared = useRef<readonly string[] | null>(null)
+ const declared = useRef<readonly Requirement[] | null>(null)
declared.current ??= [...requirements]
@@ -65,7 +63,7 @@ export default function Readiness({ requirements, children }: ReadinessProps) {
const current = useRef(state)
- const change = useCallback(function (next: ReadinessState) {
+ const change = useCallback(function (next: ReadinessState<Requirement>) {
if (next === current.current) return
@@ -74,17 +72,17 @@ export default function Readiness({ requirements, children }: ReadinessProps) {
setState(next)
}, [])
- const ready = useCallback(function (requirement: string) {
+ const ready = useCallback(function (requirement: Requirement) {
change(current.current.ready(requirement))
}, [change])
- const require = useCallback(function (requirement: string) {
+ const require = useCallback(function (requirement: Requirement) {
change(current.current.require(requirement))
}, [change])
- const value = useMemo<ReadinessValue>(() => ({
+ const value = useMemo<ReadinessValue<Requirement>>(() => ({
pending: state.pending,
@@ -94,13 +92,13 @@ export default function Readiness({ requirements, children }: ReadinessProps) {
}), [ready, require, state.pending])
- return <ReadinessContext.Provider value={value}>{children}</ReadinessContext.Provider>
+ return <ReadinessContext.Provider value={value as unknown as ReadinessValue<unknown>}>{children}</ReadinessContext.Provider>
}
/** Observe pending work or render one representation only while work remains. */
-function Pending({ children }: PendingProps) {
+function Pending<Requirement = unknown>({ children }: PendingProps<Requirement>) {
- const { pending } = useReadiness()
+ const { pending } = useReadiness<Requirement>()
if (typeof children === "function") return children(pending)
@@ -110,19 +108,19 @@ function Pending({ children }: PendingProps) {
Readiness.Pending = Pending
/** Access the nearest readiness boundary. */
-export function useReadiness() {
+export function useReadiness<Requirement = unknown>() {
const readiness = useContext(ReadinessContext)
if (!readiness) throw new Error("Readiness was not provided")
- return readiness
+ return readiness as ReadinessValue<Requirement>
}
/** Register pending work owned by this component and return its completion. */
-export function useRequirement(requirement: string) {
+export function useRequirement<Requirement>(requirement: Requirement) {
- const { ready, require } = useReadiness()
+ const { ready, require } = useReadiness<Requirement>()
useLayoutEffect(function () {
@@ -135,9 +133,9 @@ export function useRequirement(requirement: string) {
}
/** Treat this component's mounted presence as proof of readiness. */
-export function useReady(requirement: string) {
+export function useReady<Requirement>(requirement: Requirement) {
- const { ready, require } = useReadiness()
+ const { ready, require } = useReadiness<Requirement>()
useLayoutEffect(function () {
@@ -147,47 +145,47 @@ export function useReady(requirement: string) {
}, [ready, require, requirement])
}
-function sameRequirements(left: readonly string[], right: readonly string[]) {
+function sameRequirements<Requirement>(left: readonly Requirement[], right: readonly Requirement[]) {
- return left.length === right.length && left.every((requirement, index) => requirement === right[index])
+ return left.length === right.length && left.every((requirement, index) => Object.is(requirement, right[index]))
}
-function validate(requirements: readonly string[]) {
-
- const known = new Set<string>()
+function hasRequirement<Requirement>(requirements: readonly Requirement[], requirement: Requirement) {
- for (const requirement of requirements) {
+ // Requirements are opaque to readiness; their own identity is the only
+ // relation the lifecycle may use.
+ return requirements.some(candidate => Object.is(candidate, requirement))
+}
- validateRequirement(requirement)
+function validate<Requirement>(requirements: readonly Requirement[]) {
- if (known.has(requirement)) throw new Error(`Readiness already knows the requirement "${requirement}"`)
+ const known: Requirement[] = []
- known.add(requirement)
- }
-}
+ for (const requirement of requirements) {
-function validateRequirement(requirement: string) {
+ if (hasRequirement(known, requirement)) throw new Error("Readiness already knows that requirement")
- if (!requirement.trim()) throw new Error("A readiness requirement must have a name")
+ known.push(requirement)
+ }
}
-interface ReadinessProps {
+interface ReadinessProps<Requirement> {
- requirements: readonly string[]
+ requirements: readonly Requirement[]
children: ReactNode
}
-interface PendingProps {
+interface PendingProps<Requirement> {
- children: ReactNode | ((pending: readonly string[]) => ReactNode)
+ children: ReactNode | ((pending: readonly Requirement[]) => ReactNode)
}
-export interface ReadinessValue {
+export interface ReadinessValue<Requirement = unknown> {
- pending: readonly string[]
+ pending: readonly Requirement[]
- ready: (requirement: string) => void
+ ready: (requirement: Requirement) => void
- require: (requirement: string) => void
+ require: (requirement: Requirement) => void
}
diff --git a/tests/client-process-collection.test.ts b/tests/client-process-collection.test.ts
new file mode 100644
index 0000000..76fa732
--- /dev/null
+++ b/tests/client-process-collection.test.ts
@@ -0,0 +1,51 @@
+import assert from "node:assert/strict"
+import { TheLink } from "@the-link/core"
+import ClientProcessManager from "@client/core/link-manager/auth-manager/process-manager/process-manager"
+import ClientProgramManager from "@client/core/link-manager/auth-manager/program-manager/program-manager"
+import { test } from "vitest"
+
+test("process collection subscription closes the snapshot and subscription gap", async () => {
+ const connection = new TheLink()
+ const manager = new ClientProcessManager(connection as never, { processes: [] })
+ const process = { identity: "created-before-subscription" }
+
+ // This mutation represents an event received after a view read the old
+ // snapshot but before React installed its subscription.
+ manager.processes.set(process.identity, process as never)
+
+ const collections: string[][] = []
+ const unsubscribe = manager.subscribeProcesses(processes => {
+ collections.push(processes.map(current => current.identity))
+ })
+
+ assert.deepEqual(collections, [[process.identity]])
+
+ const next = { identity: "created-after-subscription" }
+ manager.processes.set(next.identity, next as never)
+ await manager.changed()
+
+ assert.deepEqual(collections.at(-1), [process.identity, next.identity])
+
+ unsubscribe()
+ manager.processes.delete(process.identity)
+ await manager.changed()
+
+ assert.deepEqual(collections.at(-1), [process.identity, next.identity])
+})
+
+test("program collection subscription closes the snapshot and subscription gap", async () => {
+ const connection = new TheLink()
+ const manager = new ClientProgramManager(connection as never, { programs: [] })
+ const program = { identity: "installed-before-subscription" }
+
+ manager.programs.set(program.identity, program as never)
+
+ const collections: string[][] = []
+ const unsubscribe = manager.subscribePrograms(programs => {
+ collections.push(programs.map(current => current.identity))
+ })
+
+ assert.deepEqual(collections, [[program.identity]])
+
+ unsubscribe()
+})
diff --git a/tests/process-window-progress.test.ts b/tests/process-window-progress.test.ts
new file mode 100644
index 0000000..0fe6f44
--- /dev/null
+++ b/tests/process-window-progress.test.ts
@@ -0,0 +1,14 @@
+import { processWindowProgress } from "@client/view/structure/desktop/windows/process-window"
+import { expect, test } from "vitest"
+
+test("private progress belongs only to the standard Window representation", () => {
+ expect(processWindowProgress("window", true, false, false)).toBe("Loading")
+ expect(processWindowProgress("window", false, true, false)).toBe("Closing")
+ expect(processWindowProgress("window", false, false, true)).toBe("Closing")
+ expect(processWindowProgress("window", false, false, false)).toBeNull()
+
+ for (const layer of ["wallpaper", "under", "over", "shell"] as const) {
+ expect(processWindowProgress(layer, true, false, false)).toBeNull()
+ expect(processWindowProgress(layer, false, true, true)).toBeNull()
+ }
+})
diff --git a/tests/readiness.test.tsx b/tests/readiness.test.tsx
index bb9a2aa..d5b2d2d 100644
--- a/tests/readiness.test.tsx
+++ b/tests/readiness.test.tsx
@@ -1,38 +1,46 @@
import assert from "node:assert/strict"
import { renderToStaticMarkup } from "react-dom/server"
import Readiness, { ReadinessState } from "@libs/readiness"
+import Loading from "@client/view/components/loading"
import { test } from "vitest"
test("readiness contract", async () => {
- const startup = ReadinessState.start(["connection", "session", "wallpaper"])
+ const connection = { message: "Connecting" }
+ const sessionRequirement = { message: "Preparing session" }
+ const wallpaper = { message: "Loading wallpaper" }
+ const programs = { message: "Loading programs" }
+ const startup = ReadinessState.start([connection, sessionRequirement, wallpaper])
- assert.deepEqual(startup.pending, ["connection", "session", "wallpaper"])
+ assert.deepEqual(startup.pending, [connection, sessionRequirement, wallpaper])
- const connected = startup.ready("connection")
- const extended = connected.require("programs")
- const session = extended.ready("session")
- const wallpaper = session.ready("wallpaper")
- const complete = wallpaper.ready("programs")
+ const connected = startup.ready(connection)
+ const extended = connected.require(programs)
+ const session = extended.ready(sessionRequirement)
+ const wallpaperReady = session.ready(wallpaper)
+ const complete = wallpaperReady.ready(programs)
- assert.deepEqual(connected.pending, ["session", "wallpaper"])
- assert.deepEqual(extended.pending, ["session", "wallpaper", "programs"])
+ assert.deepEqual(connected.pending, [sessionRequirement, wallpaper])
+ assert.deepEqual(extended.pending, [sessionRequirement, wallpaper, programs])
assert.deepEqual(complete.pending, [])
- assert.equal(complete.ready("programs"), complete)
+ assert.equal(complete.ready(programs), complete)
- const recomposed = complete.require("wallpaper").require("connection").require("session")
+ const recomposed = complete.require(wallpaper).require(connection).require(sessionRequirement)
- assert.deepEqual(recomposed.pending, ["connection", "session", "wallpaper"])
- assert.deepEqual(recomposed.ready("connection").ready("session").ready("wallpaper").pending, [])
- assert.equal(recomposed.require("connection"), recomposed)
+ assert.deepEqual(recomposed.pending, [connection, sessionRequirement, wallpaper])
+ assert.deepEqual(recomposed.ready(connection).ready(sessionRequirement).ready(wallpaper).pending, [])
+ assert.equal(recomposed.require(connection), recomposed)
- const late = complete.require("late")
+ const lateRequirement = { message: "Late work" }
+ const late = complete.require(lateRequirement)
- assert.deepEqual(late.requirements, ["connection", "session", "wallpaper", "programs", "late"])
- assert.deepEqual(late.pending, ["late"])
+ assert.deepEqual(late.requirements, [connection, sessionRequirement, wallpaper, programs, lateRequirement])
+ assert.deepEqual(late.pending, [lateRequirement])
- assert.throws(() => startup.ready("unknown"), /does not know/)
- assert.throws(() => ReadinessState.start(["connection", "connection"]), /already knows/)
- assert.throws(() => ReadinessState.start([""]), /must have a name/)
+ assert.throws(() => startup.ready({ message: "Connecting" }), /does not know/)
+ assert.throws(() => ReadinessState.start([connection, connection]), /already knows/)
+
+ const sameDataWithDistinctIdentities = ReadinessState.start([{ message: "Same" }, { message: "Same" }])
+ assert.equal(sameDataWithDistinctIdentities.pending.length, 2)
const pendingMarkup = renderToStaticMarkup(
<Readiness requirements={["connection"]}>
@@ -65,6 +73,19 @@ test("readiness contract", async () => {
</Readiness>
)
+ const describedRequirementMarkup = renderToStaticMarkup(
+ <Readiness requirements={[connection]}>
+ <Readiness.Pending<{ message: string }>>
+ {pending => <span>{pending[0]?.message}</span>}
+ </Readiness.Pending>
+ </Readiness>
+ )
+
assert.match(observedPendingMarkup, /connection,session/)
assert.match(observedReadyMarkup, />0</)
+ assert.match(describedRequirementMarkup, /Connecting/)
+
+ const fallbackMessageMarkup = renderToStaticMarkup(<Loading>Loading…</Loading>)
+ assert.match(fallbackMessageMarkup, /data-loading-message="true"/)
+ assert.match(fallbackMessageMarkup, /Loading…/)
}, 120_000)
diff --git a/tests/window-incarnation-lifecycle.test.ts b/tests/window-incarnation-lifecycle.test.ts
new file mode 100644
index 0000000..401bb3c
--- /dev/null
+++ b/tests/window-incarnation-lifecycle.test.ts
@@ -0,0 +1,38 @@
+import { expect, test } from "vitest"
+import { captureLeavingWindow, captureWindowIncarnation } from "@client/view/components/window-manager/window-manager"
+import type ClientState from "@client/core/link-manager/auth-manager/process-manager/client-state"
+import type Process from "@client/core/link-manager/auth-manager/process-manager/process"
+
+test("a departing presentation retains the layer captured while its Window was live", () => {
+ let running = true
+
+ const client = {
+ window: {
+ get layer() {
+ if (!running) throw new Error("This Client Endpoint is not running")
+
+ return "wallpaper" as const
+ }
+ }
+ } as ClientState
+
+ const incarnation = captureWindowIncarnation("process:0", { identity: "process" } as Process, client)
+
+ running = false
+
+ expect(incarnation.layer).toBe("wallpaper")
+})
+
+test("an ended Client animates from its captured presentation after the live controller forgets it", () => {
+ const client = { window: { layer: "window" } } as ClientState
+ const incarnation = captureWindowIncarnation("process:0", { identity: "process" } as Process, client)
+ const presented = { layer: "window", position: { x: 20, y: 30 } }
+ const live = new Map([[incarnation.identity, presented]])
+
+ const leaving = captureLeavingWindow(incarnation, live as never)
+
+ live.clear()
+
+ expect(leaving?.presentation).toBe(presented)
+ expect(live.has(incarnation.identity)).toBe(false)
+})
diff --git a/tests/window-presentation.test.ts b/tests/window-presentation.test.ts
index 2f9db42..e22a14c 100644
--- a/tests/window-presentation.test.ts
+++ b/tests/window-presentation.test.ts
@@ -72,6 +72,20 @@ test("a standard Window follows authoritative state but accepts only move gestur
assert.throws(() => presentations.move("ordinary", { x: 1, y: 2 }), /does not support raw/)
assert.throws(() => presentations.setSurface("ordinary", false), /does not support raw/)
+ ordinary.window.maximized = true
+ presentations.reconcile(entries)
+ const maximizing = presentations.projection("ordinary").geometryAnimation
+ assert.equal(presentations.projection("ordinary").maximized, true)
+ assert.ok(maximizing)
+
+ presentations.complete("ordinary", "geometry", maximizing.revision)
+ ordinary.window.maximized = false
+ presentations.reconcile(entries)
+ const restoring = presentations.projection("ordinary").geometryAnimation
+ assert.equal(presentations.projection("ordinary").maximized, false)
+ assert.ok(restoring)
+ assert.notEqual(restoring.revision, maximizing.revision)
+
const events: unknown[] = []
let ready!: () => void
let finish!: () => void
@@ -111,6 +125,29 @@ test("a Client boundary initializes each new document exactly once", async () =>
assert.deepEqual(lifecycle, ["requester", "requester"])
})
+test("a new Client document preserves its mounted Desktop geometry representation", () => {
+ const ordinary = client("window")
+ const entries = entry("ordinary", ordinary)
+ const presentations = new WindowPresentations(entries, () => ordinary as never)
+ const geometry = { x: 20, y: 30, width: 400, height: 300 }
+
+ presentations.represent("ordinary", {
+ read: () => geometry,
+ present() {},
+ begin: () => geometry,
+ finish() {},
+ cancel() {}
+ })
+
+ presentations.begin("ordinary")
+
+ assert.deepEqual(presentations.representedGeometry("ordinary"), geometry)
+
+ presentations.reconcile(new Map())
+
+ assert.equal(presentations.representedGeometry("ordinary"), null)
+})
+
function entry(process: string, selected: ReturnType<typeof client>) {
return new Map([[process, { identity: `${process}:0`, client: selected }]]) as unknown as ReadonlyMap<string, WindowPresentationEntry>
}
diff --git a/vitest.config.ts b/vitest.config.ts
index 3b95022..58e61da 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -4,7 +4,7 @@ import workerThreadPlugin from "./source/libs/worker-thread-plugin.js"
export default defineConfig({
plugins: [decoratorPlugin(), workerThreadPlugin()],
- resolve: { tsconfigPaths: true },
+ resolve: { tsconfigPaths: true, dedupe: ["react", "react-dom"] },
test: {
pool: "forks",
maxWorkers: 2,