Skip to content

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

Serve Desktop capability snapshots

zohayrslileh6768d58c9bdd
diff --git a/scripts/contracts/client-surface.ts b/scripts/contracts/client-surface.ts
index e8387de..e356e64 100644
--- a/scripts/contracts/client-surface.ts
+++ b/scripts/contracts/client-surface.ts
@@ -150,11 +150,14 @@ const processManager = {
}
const authManager = {
processManager,
- programManager: { programs: new Map() }
+ programManager: { programs: new Map() },
+ async permissionGranted() { return true }
}
-const request = host(authManager as never, requester.identity, () => ({ width: 1, height: 1 }), () => "owner", {} as never, localWindow as never)
+const pointer = { snapshot: () => ({ position: { x: 12, y: 24 } }) }
+const request = host(authManager as never, requester.identity, () => ({ size: { width: 1, height: 1 } }), () => "owner", pointer as never, localWindow as never)
-assert.deepEqual(await request("desktop"), [{ width: 1, height: 1 }])
+assert.deepEqual(await request("desktopSurface"), [{ size: { width: 1, height: 1 } }])
+assert.deepEqual(await request("desktopPointer"), [{ position: { x: 12, y: 24 } }])
const targetAddress = { identity: target.identity, reference: target.reference }
assert.deepEqual(await request("windowLocal", targetAddress), [{ position: { x: 70, y: 80 } }])
await request("windowLocalMove", targetAddress, { x: 70, y: 80 })
@@ -175,7 +178,7 @@ const boundary = new ClientProcessBoundary(
"requester",
{ contentWindow: null } as unknown as HTMLIFrameElement,
authManager as never,
- () => ({ width: 1, height: 1 }),
+ () => ({ size: { width: 1, height: 1 } }),
{} as never,
{} as never,
{ release(identity: string) { lifecycle.push(identity) } } as never
diff --git a/source/client/view/components/desktop-host/client-host.ts b/source/client/view/components/desktop-host/client-host.ts
index 375ecfe..6c35f0d 100644
--- a/source/client/view/components/desktop-host/client-host.ts
+++ b/source/client/view/components/desktop-host/client-host.ts
@@ -1,7 +1,6 @@
import ReactTunnel from "@libs/the-link/plugins/react-helper/react-tunnel"
-import { isPermissionName } from "@phreshos/core"
+import { isPermissionName, type DesktopSize, type DesktopSurfaceSnapshot } from "@phreshos/core"
import useAnnouncements from "./announcements"
-import { type DesktopSize } from "./host"
import DesktopPointer from "./pointer"
import ClientProcessBoundary from "./client-process-boundary"
import ClientTraffic from "./client-traffic"
@@ -31,15 +30,15 @@ export default function useClientHost(authManager: AuthManager, desktop: RefObje
const [windowSurfaceSize, setWindowSurfaceSize] = useState<SurfaceSize>({ width: 0, height: 0 })
- const latestDesktopSize = useRef<DesktopSize>({ width: 0, height: 0 })
+ const latestDesktopSurface = useRef<DesktopSurfaceSnapshot>({ size: { width: 0, height: 0 } })
- const desktopSize = useCallback(function (): DesktopSize {
+ const desktopSurface = useCallback(function (): DesktopSurfaceSnapshot {
const bounds = desktop.current?.getBoundingClientRect()
return bounds
- ? { width: Math.round(bounds.width), height: Math.round(bounds.height) }
- : latestDesktopSize.current
+ ? { size: { width: Math.round(bounds.width), height: Math.round(bounds.height) } }
+ : latestDesktopSurface.current
}, [desktop])
@@ -52,19 +51,23 @@ export default function useClientHost(authManager: AuthManager, desktop: RefObje
return { width: Math.round(bounds.width), height: Math.round(bounds.height) }
}
- function announceDesktop(now: DesktopSize) {
+ function announceDesktop(size: DesktopSize) {
- if (latestDesktopSize.current.width === now.width && latestDesktopSize.current.height === now.height) return
+ const previous = latestDesktopSurface.current.size
- latestDesktopSize.current = now
+ if (previous.width === size.width && previous.height === size.height) return
+
+ const snapshot = { size }
+
+ latestDesktopSurface.current = snapshot
// Announcements leave directly from the full desktop measurement.
// Traffic carries them only to boundaries with a live interest.
- if (!now.width) return
+ if (!size.width) return
for (const identity of sources.keys()) {
- traffic.emit(identity, "host-desktop", "resize", now).catch(() => undefined)
+ traffic.emit(identity, "host-desktop-surface", "resize", snapshot).catch(() => undefined)
}
}
@@ -75,7 +78,7 @@ export default function useClientHost(authManager: AuthManager, desktop: RefObje
const initialDesktop = measure(desktop.current.getBoundingClientRect())
- latestDesktopSize.current = initialDesktop
+ latestDesktopSurface.current = { size: initialDesktop }
const initialWindowSurface = windowSurfaceRef.current.getBoundingClientRect()
@@ -215,7 +218,7 @@ export default function useClientHost(authManager: AuthManager, desktop: RefObje
boundaries.current.get(identity)?.release().catch(() => undefined)
- boundaries.current.set(identity, new ClientProcessBoundary(identity, element, authManager, desktopSize, pointer, traffic, localWindow))
+ boundaries.current.set(identity, new ClientProcessBoundary(identity, element, authManager, desktopSurface, pointer, traffic, localWindow))
return
}
@@ -230,7 +233,7 @@ export default function useClientHost(authManager: AuthManager, desktop: RefObje
boundary?.release().catch(() => undefined)
- }, [authManager, desktopSize, localWindow, pointer, sources, traffic])
+ }, [authManager, desktopSurface, localWindow, pointer, sources, traffic])
const frameLoaded = useCallback(function (identity: string, element: HTMLIFrameElement) {
diff --git a/source/client/view/components/desktop-host/client-process-boundary.ts b/source/client/view/components/desktop-host/client-process-boundary.ts
index 7f3aac1..3205f19 100644
--- a/source/client/view/components/desktop-host/client-process-boundary.ts
+++ b/source/client/view/components/desktop-host/client-process-boundary.ts
@@ -1,11 +1,16 @@
import AuthManager from "@client/core/link-manager/auth-manager/auth-manager"
import TheLink from "@libs/the-link/the-link"
-import host, { type DesktopSize, 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 DesktopPointerPosition,
+ type DesktopSurfaceSnapshot,
+ type PermissionName
+} from "@phreshos/core"
import { type LocalWindowHost } from "./local-window"
import messagepack from "@libs/messagepack"
@@ -18,7 +23,7 @@ export default class ClientProcessBoundary extends TheLink {
private readonly authManager: AuthManager
- private readonly desktop: () => DesktopSize
+ private readonly desktop: () => DesktopSurfaceSnapshot
private readonly pointer: PointerHost
@@ -56,13 +61,13 @@ export default class ClientProcessBoundary extends TheLink {
private pointerStop: (() => void) | null = null
- private pointerPosition: { x: number, y: number } | null = null
+ private pointerPosition: DesktopPointerPosition | null = null
private owner: string | null = null
private leased: string | null = null
- public constructor(pane: string, element: HTMLIFrameElement, authManager: AuthManager, desktop: () => DesktopSize, pointer: PointerHost, traffic: ClientTraffic, localWindow: LocalWindowHost) {
+ public constructor(pane: string, element: HTMLIFrameElement, authManager: AuthManager, desktop: () => DesktopSurfaceSnapshot, pointer: PointerHost, traffic: ClientTraffic, localWindow: LocalWindowHost) {
super()
@@ -899,7 +904,7 @@ export default class ClientProcessBoundary extends TheLink {
if (this.pointerStop) return
- this.pointerPosition = this.pointer.position()
+ this.pointerPosition = this.pointer.snapshot().position
this.pointerStop = this.pointer.$inbound.subscribe("move", (position: unknown) => {
@@ -907,7 +912,7 @@ export default class ClientProcessBoundary extends TheLink {
this.pointerPosition = position
- this.deliver("host-pointer", "move", position).catch(() => undefined)
+ this.deliver("host-desktop-pointer", "move", { position }).catch(() => undefined)
})
}
@@ -924,7 +929,7 @@ export default class ClientProcessBoundary extends TheLink {
this.pointerPosition = next
- this.deliver("host-pointer", "move", next).catch(() => undefined)
+ this.deliver("host-desktop-pointer", "move", { position: next }).catch(() => undefined)
}
}
@@ -998,7 +1003,7 @@ interface EndpointSubscription {
function pointerSubscription(subscription: EndpointSubscription) {
- return subscription.kind === "publish" && subscription.route === "host-pointer" && (subscription.event === null || subscription.event === "move")
+ return subscription.kind === "publish" && subscription.route === "host-desktop-pointer" && (subscription.event === null || subscription.event === "move")
}
function desktopPreferencesSubscription(subscription: EndpointSubscription) {
diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.ts
index 5d44945..67f66e0 100644
--- a/source/client/view/components/desktop-host/host.ts
+++ b/source/client/view/components/desktop-host/host.ts
@@ -1,4 +1,7 @@
-import { type Launch } from "@phreshos/core"
+import {
+ type DesktopSurfaceSnapshot,
+ type Launch
+} from "@phreshos/core"
import { type ProxyRequest } from "@server/core/protocol/proxy"
import AuthManager from "@client/core/link-manager/auth-manager/auth-manager"
import { type ClientBody, type ProxiedResponse, type UploadValue } from "@client/core/application"
@@ -21,14 +24,6 @@ export class TransferredAnswer {
public constructor(public readonly result: unknown[], public readonly transfer: Transferable[]) { }
}
-/** The complete measured desktop area in CSS pixels. */
-export interface DesktopSize {
-
- width: number
-
- height: number
-}
-
/**
* The desktop's vocabulary: what a client half may ask of the interface
* that frames it.
@@ -53,7 +48,7 @@ export interface DesktopSize {
* browser capabilities travel only as explicit attachments, so every ordinary
* word answers with data built here, never with an instance the desktop holds.
*/
-export default function host(authManager: AuthManager, pane: string, desktop: () => DesktopSize, frameOwner: () => string | null, pointer: PointerHost, localWindow: LocalWindowHost) {
+export default function host(authManager: AuthManager, pane: string, desktop: () => DesktopSurfaceSnapshot, frameOwner: () => string | null, pointer: PointerHost, localWindow: LocalWindowHost) {
const { processManager, programManager } = authManager
@@ -693,16 +688,16 @@ export default function host(authManager: AuthManager, pane: string, desktop: ()
// 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()]
+ if (word === "desktopSurface") return [desktop()]
// Coordinates use the same desktop display core as window geometry.
// Before this session has observed a pointer movement there is no
// position to invent, so the initial answer is null.
- if (word === "pointer") {
+ if (word === "desktopPointer") {
if (await authManager.permissionGranted(pane, "pointer") !== true) throw new Error("Permission \"pointer\" is not granted")
- return [pointer.position()]
+ return [pointer.snapshot()]
}
// Uploads are one flat public collection. A pane may provide bytes or
diff --git a/source/client/view/components/desktop-host/pointer.ts b/source/client/view/components/desktop-host/pointer.ts
index 3a0d5c5..2c11c41 100644
--- a/source/client/view/components/desktop-host/pointer.ts
+++ b/source/client/view/components/desktop-host/pointer.ts
@@ -1,5 +1,6 @@
import { type RefObject } from "react"
import TheLink from "@libs/the-link/the-link"
+import { type DesktopPointerPosition, type DesktopPointerSnapshot } from "@phreshos/core"
/**
* Pointer state belongs to one desktop session. Programs may observe it,
@@ -7,7 +8,7 @@ import TheLink from "@libs/the-link/the-link"
*/
export default class DesktopPointer extends TheLink implements PointerHost {
- private latest: PointerPosition | null = null
+ private latest: DesktopPointerPosition | null = null
public constructor(private readonly desktop: RefObject<HTMLDivElement | null>) {
@@ -44,23 +45,16 @@ export default class DesktopPointer extends TheLink implements PointerHost {
}
}
- public position() {
+ public snapshot(): DesktopPointerSnapshot {
- return this.latest
+ return { position: this.latest }
}
}
-export interface PointerPosition {
-
- x: number
-
- y: number
-}
-
export interface PointerHost {
- position(): PointerPosition | null
+ snapshot(): DesktopPointerSnapshot
readonly $inbound: TheLink["$inbound"]
}
diff --git a/source/client/view/structure/desktop/geometry.ts b/source/client/view/structure/desktop/geometry.ts
index 11bd030..1549a76 100644
--- a/source/client/view/structure/desktop/geometry.ts
+++ b/source/client/view/structure/desktop/geometry.ts
@@ -4,7 +4,7 @@ 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. The gutter remains private desktop layout state and never
- * enters the layer-independent value returned by `system.desktop.size()`.
+ * enters the layer-independent `system.desktop.surface` snapshot.
*
* The visible window edge, taskbar edge and Start Menu geometry derive from
* this value rather than restating its pixel or rem equivalent.