Skip to content

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

Move local representation targeting into Window handles

zohayrslileha6a18db2aced
diff --git a/package.json b/package.json
index 3480f42..3df2367 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "phreshos",
"displayName": "PhreshOS",
- "version": "0.1.14",
+ "version": "0.1.15",
"description": "The PhreshOS server, desktop, and authoritative system runtime.",
"type": "module",
"private": true,
@@ -26,11 +26,11 @@
"scripts": {
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
"check": "tsc --noEmit",
- "dev": "vite-node --config vite.server.ts source/dev.ts",
- "build": "vite-node --config vite.server.ts source/build.ts",
+ "dev": "vite-node scripts/dev.ts",
+ "build": "vite-node scripts/build.ts",
"start": "node --run build && node dist/server/main.js",
- "pack": "node --run build && vite-node --config vite.server.ts source/pack.ts",
- "verify:contracts": "vite-node --config vite.server.ts scripts/verify-client-launch.mjs && vite-node --config vite.server.ts scripts/verify-client-surface.mjs && vite-node --config vite.server.ts scripts/verify-window-geometry.mjs && vite-node --config vite.server.ts scripts/verify-readiness.mjs && vite-node --config vite.server.ts scripts/verify-endpoint-services.mjs && vite-node --config vite.server.ts scripts/verify-intake-address.mjs",
+ "pack": "node --run build && vite-node scripts/pack.ts",
+ "verify:contracts": "vite-node scripts/verify-client-launch.mjs && vite-node scripts/verify-client-surface.mjs && vite-node scripts/verify-window-geometry.mjs && vite-node scripts/verify-readiness.mjs && vite-node scripts/verify-endpoint-services.mjs && vite-node scripts/verify-intake-address.mjs",
"verify:distribution": "node scripts/verify-distribution.mjs",
"verify": "node --run check && node --run verify:contracts && node --run verify:distribution"
},
diff --git a/source/build.ts b/scripts/build.ts
similarity index 85%
rename from source/build.ts
rename to scripts/build.ts
index 2d6beb2..0a01395 100644
--- a/source/build.ts
+++ b/scripts/build.ts
@@ -1,4 +1,4 @@
-import { externalDependencies } from "@/vite.server"
+import { externalDependencies } from "@/vite.config"
import { rm, writeFile } from "node:fs/promises"
import packageConfig from "@/package.json"
@@ -15,7 +15,7 @@ for (const externalDependency of externalDependencies) {
dependencies[externalDependency] = packageConfig.dependencies[externalDependency]
}
-await build({ configFile: "vite.server.ts", ssr: { noExternal: true } })
+await build({ configFile: "vite.config.ts", ssr: { noExternal: true } })
await build({ configFile: "vite.client.ts" })
diff --git a/source/dev.ts b/scripts/dev.ts
similarity index 100%
rename from source/dev.ts
rename to scripts/dev.ts
diff --git a/source/pack.ts b/scripts/pack.ts
similarity index 100%
rename from source/pack.ts
rename to scripts/pack.ts
diff --git a/scripts/verify-client-surface.mjs b/scripts/verify-client-surface.mjs
index c4db2dd..8a75871 100644
--- a/scripts/verify-client-surface.mjs
+++ b/scripts/verify-client-surface.mjs
@@ -113,9 +113,17 @@ const requester = {
program: "program",
client: { window: { process: "requester", layer: "over" } }
}
-const processes = new Map([[requester.identity, requester]])
+const target = {
+ identity: "target",
+ reference: "target-reference",
+ program: "program",
+ client: { window: { process: "target", layer: "over", position: { x: 10, y: 20 } } }
+}
+const processes = new Map([[requester.identity, requester], [target.identity, target]])
const calls = []
const localWindow = {
+ state(identity) { return { position: identity === "target" ? { x: 70, y: 80 } : { x: 0, y: 0 } } },
+ move(identity, value, motion) { calls.push(["move", identity, value, motion]) },
setSurface(identity, value, motion) { calls.push(["set", identity, value, motion]) },
removeSurface(identity) { calls.push(["remove", identity]) }
}
@@ -126,11 +134,20 @@ 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")
-
-assert.deepEqual(calls, [["set", "requester", settings, transaction], ["remove", "requester"]])
-await assert.rejects(request("localWindowSurfaceSet", { identity: "target" }), /no "identity" field/)
+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 })
+await request("windowLocalSurfaceSet", targetAddress, settings, transaction)
+await request("windowLocalSurfaceRemove", targetAddress)
+
+assert.deepEqual(calls, [
+ ["move", "target", { x: 70, y: 80 }, undefined],
+ ["set", "target", settings, transaction],
+ ["remove", "target"]
+])
+assert.deepEqual(target.client.window.position, { x: 10, y: 20 })
+await assert.rejects(request("windowLocalSurfaceSet", targetAddress, { identity: "unexpected" }), /no "identity" field/)
+await assert.rejects(request("windowLocalSurfaceSet", { ...targetAddress, reference: "wrong" }, settings), /does not know this process/)
const lifecycle = []
const boundary = new ClientProcessBoundary(
diff --git a/source/client/view/desktop/client-host/host.ts b/source/client/view/desktop/client-host/host.ts
index 8ed8cde..7916ff6 100644
--- a/source/client/view/desktop/client-host/host.ts
+++ b/source/client/view/desktop/client-host/host.ts
@@ -114,6 +114,17 @@ export default function host(authManager: AuthManager, pane: string, desktop: ()
return found
}
+ function localProcess(named: unknown) {
+
+ const found = sibling(named)
+
+ if (!found.client) throw new Error("This process has no live client endpoint")
+
+ if (found.client.window.layer === "wallpaper") throw new Error("A wallpaper Window is managed by the system")
+
+ return found
+ }
+
function declared(found: ReturnType<typeof process>, half: "server" | "client") {
return (programManager.programs.get(found.program)?.[half] ?? null) !== null
@@ -630,60 +641,60 @@ export default function host(authManager: AuthManager, pane: string, desktop: ()
return [pane]
}
- if (word === "localWindow") return [localWindow.state(pane)]
+ if (word === "windowLocal") return [localWindow.state(localProcess(args[0]).identity)]
- if (word === "localWindowMove") {
+ if (word === "windowLocalMove") {
- await localWindow.move(pane, localPosition(args[0]), visualTransaction(args[1]))
+ await localWindow.move(localProcess(args[0]).identity, localPosition(args[1]), visualTransaction(args[2]))
return []
}
- if (word === "localWindowResize") {
+ if (word === "windowLocalResize") {
- await localWindow.resize(pane, localSize(args[0]), visualTransaction(args[1]))
+ await localWindow.resize(localProcess(args[0]).identity, localSize(args[1]), visualTransaction(args[2]))
return []
}
- if (word === "localWindowGeometry") {
+ if (word === "windowLocalGeometry") {
- await localWindow.geometry(pane, localGeometry(args[0]), visualTransaction(args[1]))
+ await localWindow.geometry(localProcess(args[0]).identity, localGeometry(args[1]), visualTransaction(args[2]))
return []
}
- if (word === "localWindowMinimize") {
+ if (word === "windowLocalMinimize") {
- localWindow.minimize(pane, args[0] !== false)
+ localWindow.minimize(localProcess(args[0]).identity, args[1] !== false)
return []
}
- if (word === "localWindowTitle") {
+ if (word === "windowLocalTitle") {
- localWindow.title(pane, String(args[0] ?? ""))
+ localWindow.title(localProcess(args[0]).identity, String(args[1] ?? ""))
return []
}
- if (word === "localWindowRaise") {
+ if (word === "windowLocalRaise") {
- localWindow.raise(pane)
+ localWindow.raise(localProcess(args[0]).identity)
return []
}
- if (word === "localWindowSurfaceSet") {
+ if (word === "windowLocalSurfaceSet") {
- await localWindow.setSurface(pane, surfaceSettings(args[0] === undefined ? {} : args[0]), visualTransaction(args[1]))
+ await localWindow.setSurface(localProcess(args[0]).identity, surfaceSettings(args[1] === undefined ? {} : args[1]), visualTransaction(args[2]))
return []
}
- if (word === "localWindowSurfaceRemove") {
+ if (word === "windowLocalSurfaceRemove") {
- localWindow.removeSurface(pane)
+ localWindow.removeSurface(localProcess(args[0]).identity)
return []
}
diff --git a/vite.server.ts b/vite.config.ts
similarity index 100%
rename from vite.server.ts
rename to vite.config.ts