Skip to content

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

Expose one desktop-wide host size

zohayrslileh360a0655e8c9
diff --git a/scripts/verify-client-surface.mjs b/scripts/verify-client-surface.mjs
index 4c651ee..473fec0 100644
--- a/scripts/verify-client-surface.mjs
+++ b/scripts/verify-client-surface.mjs
@@ -117,6 +117,7 @@ const authManager = {
}
const request = host(authManager, requester.identity, () => ({ width: 1, height: 1 }), () => "owner", {}, localWindow)
+assert.deepEqual(await request("desktop"), [{ width: 1, height: 1 }])
await request("localWindowSurfaceSet", settings, transaction)
await request("localWindowSurfaceRemove")
diff --git a/source/client/view/desktop/client-host/client-host.ts b/source/client/view/desktop/client-host/client-host.ts
index b8aa8f4..c4f856a 100644
--- a/source/client/view/desktop/client-host/client-host.ts
+++ b/source/client/view/desktop/client-host/client-host.ts
@@ -1,18 +1,16 @@
import ReactTunnel from "@libs/the-link/plugins/react-helper/react-tunnel"
-import { type WindowLayer } from "@phreshos/core"
+import { isPermissionName, type Size } from "@phreshos/core"
import useAnnouncements from "./announcements"
-import { type Space } from "./host"
import DesktopPointer from "./pointer"
import ClientProcessBoundary from "./client-process-boundary"
import ClientTraffic from "./client-traffic"
import { type RefObject, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"
import { AuthManagerContext } from "../../contexts"
-import { isPermissionName } from "@phreshos/core"
import { type LocalWindowHost } from "./local-window"
/**
* The browser boundary between a program pane and the desktop that hosts it.
- * It owns frame messages and the measured surfaces those frames inhabit;
+ * It owns frame messages and the measured desktop containing those frames;
* neither fact participates in rendering.
*/
export default function useClientHost(desktop: RefObject<HTMLDivElement | null>, sources: Map<string, HTMLIFrameElement | null>, localWindow: LocalWindowHost) {
@@ -33,42 +31,40 @@ export default function useClientHost(desktop: RefObject<HTMLDivElement | null>,
const [windowSurfaceSize, setWindowSurfaceSize] = useState<SurfaceSize>({ width: 0, height: 0 })
- // Read by the gate at the moment a pane asks, so the answer is
- // never a render behind.
- const latest = useRef<Record<WindowLayer, Space>>({
+ const latestDesktopSize = useRef<Size>({ width: 0, height: 0 })
- under: { width: 0, height: 0 },
+ const desktopSize = useCallback(function (): Size {
- window: { width: 0, height: 0 },
+ const bounds = desktop.current?.getBoundingClientRect()
- over: { width: 0, height: 0 },
+ return bounds
+ ? { width: Math.round(bounds.width), height: Math.round(bounds.height) }
+ : latestDesktopSize.current
- wallpaper: { width: 0, height: 0 }
- })
+ }, [desktop])
useLayoutEffect(function () {
if (!desktop.current || !windowSurfaceRef.current) return
- function measure(entry: ResizeObserverEntry): Space {
+ function measure(bounds: { width: number, height: number }): Size {
- return { width: Math.round(entry.contentRect.width), height: Math.round(entry.contentRect.height) }
+ return { width: Math.round(bounds.width), height: Math.round(bounds.height) }
}
- function announce(layer: WindowLayer, now: Space) {
+ function announceDesktop(now: Size) {
- latest.current[layer] = now
+ if (latestDesktopSize.current.width === now.width && latestDesktopSize.current.height === now.height) return
- // Announcements leave directly from the measurement. The
- // ordinary surface also participates in rendering because its
- // windows resolve which painted edges touch its boundaries.
+ latestDesktopSize.current = now
+
+ // Announcements leave directly from the full desktop measurement.
+ // Traffic carries them only to boundaries with a live interest.
if (!now.width) return
for (const identity of sources.keys()) {
- if (authManager.processManager.processes.get(identity)?.client?.window.layer !== layer) continue
-
- traffic.emit(identity, "host-surface", "resize", now).catch(() => undefined)
+ traffic.emit(identity, "host-desktop", "resize", now).catch(() => undefined)
}
}
@@ -77,35 +73,32 @@ export default function useClientHost(desktop: RefObject<HTMLDivElement | null>,
setWindowSurfaceSize(current => current.width === width && current.height === height ? current : { width, height })
}
- const initial = windowSurfaceRef.current.getBoundingClientRect()
-
- rememberWindowSurfaceSize(initial)
+ const initialDesktop = measure(desktop.current.getBoundingClientRect())
- const viewportObserver = new ResizeObserver(function ([entry]) {
+ latestDesktopSize.current = initialDesktop
- const now = measure(entry)
+ const initialWindowSurface = windowSurfaceRef.current.getBoundingClientRect()
- announce("under", now)
+ rememberWindowSurfaceSize(initialWindowSurface)
- announce("over", now)
+ const desktopObserver = new ResizeObserver(function ([entry]) {
- announce("wallpaper", now)
+ announceDesktop(measure(entry.contentRect))
})
const windowObserver = new ResizeObserver(function ([entry]) {
rememberWindowSurfaceSize(entry.contentRect)
- announce("window", measure(entry))
})
- viewportObserver.observe(desktop.current)
+ desktopObserver.observe(desktop.current)
windowObserver.observe(windowSurfaceRef.current)
return function () {
- viewportObserver.disconnect()
+ desktopObserver.disconnect()
windowObserver.disconnect()
}
@@ -224,7 +217,7 @@ export default function useClientHost(desktop: RefObject<HTMLDivElement | null>,
boundaries.current.get(identity)?.release().catch(() => undefined)
- boundaries.current.set(identity, new ClientProcessBoundary(identity, element, authManager, layer => latest.current[layer], pointer, traffic, localWindow))
+ boundaries.current.set(identity, new ClientProcessBoundary(identity, element, authManager, desktopSize, pointer, traffic, localWindow))
return
}
@@ -239,7 +232,7 @@ export default function useClientHost(desktop: RefObject<HTMLDivElement | null>,
boundary?.release().catch(() => undefined)
- }, [authManager, localWindow, pointer, sources, traffic])
+ }, [authManager, desktopSize, localWindow, pointer, sources, traffic])
const frameLoaded = useCallback(function (identity: string, element: HTMLIFrameElement) {
diff --git a/source/client/view/desktop/client-host/client-process-boundary.ts b/source/client/view/desktop/client-host/client-process-boundary.ts
index 2f0ae62..34887c4 100644
--- a/source/client/view/desktop/client-host/client-process-boundary.ts
+++ b/source/client/view/desktop/client-host/client-process-boundary.ts
@@ -1,12 +1,11 @@
import AuthManager from "@client/core/link-manager/auth-manager/auth-manager"
-import { type WindowLayer } from "@phreshos/core"
import TheLink from "@libs/the-link/the-link"
-import host, { type Space, TransferredAnswer } from "./host"
+import host, { TransferredAnswer } from "./host"
import { type PointerHost } from "./pointer"
import ClientTraffic from "./client-traffic"
import { failed, succeeded } from "@server/core/outcome"
import { type TrafficKind } from "@server/core/link-manager/auth-manager/process-manager/process-traffic"
-import { isPermissionName, type PermissionName } from "@phreshos/core"
+import { isPermissionName, type PermissionName, type Size } from "@phreshos/core"
import { type LocalWindowHost } from "./local-window"
/** The desktop boundary around one iframe execution endpoint. */
@@ -18,7 +17,7 @@ export default class ClientProcessBoundary extends TheLink {
private readonly authManager: AuthManager
- private readonly space: (layer: WindowLayer) => Space
+ private readonly desktop: () => Size
private readonly pointer: PointerHost
@@ -59,7 +58,7 @@ export default class ClientProcessBoundary extends TheLink {
private document: string | null = null
- public constructor(pane: string, element: HTMLIFrameElement, authManager: AuthManager, space: (layer: WindowLayer) => Space, pointer: PointerHost, traffic: ClientTraffic, localWindow: LocalWindowHost) {
+ public constructor(pane: string, element: HTMLIFrameElement, authManager: AuthManager, desktop: () => Size, pointer: PointerHost, traffic: ClientTraffic, localWindow: LocalWindowHost) {
super()
@@ -69,7 +68,7 @@ export default class ClientProcessBoundary extends TheLink {
this.authManager = authManager
- this.space = space
+ this.desktop = desktop
this.pointer = pointer
@@ -210,7 +209,7 @@ export default class ClientProcessBoundary extends TheLink {
return
}
- host(this.authManager, this.pane, this.space, () => this.owner, this.pointer, this.localWindow)(values[0], ...values.slice(1)).catch((error: Error) => {
+ host(this.authManager, this.pane, this.desktop, () => this.owner, this.pointer, this.localWindow)(values[0], ...values.slice(1)).catch((error: Error) => {
if (values[0] === "observe" && typeof values[1] === "string" && values[6] === true) {
@@ -449,7 +448,7 @@ export default class ClientProcessBoundary extends TheLink {
return
}
- this.answerRequest(question, host(this.authManager, this.pane, this.space, () => this.owner, this.pointer, this.localWindow)(args[0], ...args.slice(1)))
+ this.answerRequest(question, host(this.authManager, this.pane, this.desktop, () => this.owner, this.pointer, this.localWindow)(args[0], ...args.slice(1)))
}
private answerRequest(question: string, operation: Promise<unknown[] | TransferredAnswer>, cancel: () => void = () => undefined) {
diff --git a/source/client/view/desktop/client-host/host.ts b/source/client/view/desktop/client-host/host.ts
index 6a7eb12..7e1816d 100644
--- a/source/client/view/desktop/client-host/host.ts
+++ b/source/client/view/desktop/client-host/host.ts
@@ -1,4 +1,3 @@
-import { type WindowLayer } from "@phreshos/core"
import { type Launch } from "@server/core/link-manager/auth-manager/program-manager/program-manager"
import { type ProxyRequest } from "@server/core/protocol/proxy"
import AuthManager from "@client/core/link-manager/auth-manager/auth-manager"
@@ -6,7 +5,7 @@ import { type ClientBody, type ProxiedResponse, type ServedValue } from "@client
import { type PointerHost } from "./pointer"
import { type TrafficKind } from "@server/core/link-manager/auth-manager/process-manager/process-traffic"
import { sdkProcess, sdkProgram } from "./sdk-records"
-import { isPermissionName, isServiceKey, type ProgramIconSize } from "@phreshos/core"
+import { isPermissionName, isServiceKey, type ProgramIconSize, type Size, type WindowLayer } from "@phreshos/core"
import {
localGeometry,
localPosition,
@@ -22,16 +21,6 @@ export class TransferredAnswer {
public constructor(public readonly result: unknown[], public readonly transfer: Transferable[]) { }
}
-// The space windows are laid out in, as this desktop has it. Pixels,
-// because a program asking has already decided that shares will not
-// answer what it needs.
-export interface Space {
-
- width: number
-
- height: number
-}
-
/**
* The desktop's vocabulary: what a client half may ask of the interface
* that frames it.
@@ -56,7 +45,7 @@ export interface Space {
* no prototypes and refuses functions — so every word answers with plain
* values built here, never with an instance the desktop holds.
*/
-export default function host(authManager: AuthManager, pane: string, space: (layer: WindowLayer) => Space, frameOwner: () => string | null, pointer: PointerHost, localWindow: LocalWindowHost) {
+export default function host(authManager: AuthManager, pane: string, desktop: () => Size, frameOwner: () => string | null, pointer: PointerHost, localWindow: LocalWindowHost) {
const { processManager, programManager } = authManager
@@ -809,26 +798,10 @@ export default function host(authManager: AuthManager, pane: string, space: (lay
return [await programManager.database(process().program, String(args[1]), Array.isArray(args[2]) ? args[2] : [])]
}
- // How large this pane's own layer workspace is. The Window chooses
- // the layer structurally; client code cannot inspect another layer.
- // Ordinary windows use the desktop workspace, while bare layers use
- // the browser viewport.
- //
- // The desktop's own answer, never the machine's: the same
- // program may be shown in three sessions on three screens, so
- // there is no one size to give a server half — which is why this
- // word is only on this side and why the core does not hold it.
- //
- // The desktop gutter is private layout state. It never crosses into
- // a Program endpoint as part of the surface value.
- if (word === "surface") {
-
- const shown = process().client?.window
-
- if (!shown) throw new Error("This process has no live client endpoint")
-
- return [space(shown.layer)]
- }
+ // One desktop can frame many Client layers, but its complete area is
+ // one host fact. It is this desktop's answer rather than a machine
+ // fact, and the gutter remains private desktop layout state.
+ if (word === "desktop") return [desktop()]
// Coordinates use the same desktop display core as window geometry.
// Before this session has observed a pointer movement there is no
diff --git a/source/client/view/desktop/geometry.ts b/source/client/view/desktop/geometry.ts
index c4f4204..8fe0613 100644
--- a/source/client/view/desktop/geometry.ts
+++ b/source/client/view/desktop/geometry.ts
@@ -3,8 +3,8 @@ import { type CSSProperties } from "react"
/**
* The gap between adjacent painted windows, in pixels. Each window uses
* half inside its own box; the ordinary workspace uses the other half
- * at its boundary. Bare windows paint neither and receive this value
- * through `host.surface.size()` so their own layout can align deliberately.
+ * at its boundary. The gutter remains private desktop layout state and never
+ * enters the layer-independent value returned by `host.desktop.size()`.
*
* The visible window edge, taskbar edge and Start Menu geometry derive from
* this value rather than restating its pixel or rem equivalent.