Skip to content

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

Release System 0.1.91

zohayrslileh5ddf54d978b1
diff --git a/package.json b/package.json
index b265589..06a7a08 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "phreshos",
"displayName": "PhreshOS",
- "version": "0.1.90",
+ "version": "0.1.91",
"description": "The PhreshOS server, desktop, and authoritative system runtime.",
"type": "module",
"private": true,
diff --git a/source/client/view/components/window-manager/window-manager.ts b/source/client/view/components/window-manager/window-manager.ts
index 2e25928..4e80bdd 100644
--- a/source/client/view/components/window-manager/window-manager.ts
+++ b/source/client/view/components/window-manager/window-manager.ts
@@ -190,6 +190,24 @@ export default function useWindows(authManager: AuthManager) {
request.catch(() => undefined)
}, [])
+ // A pointer gesture must retain its visible result until the authoritative
+ // request settles. Returning failure as data keeps ignored button presses
+ // handled while allowing the gesture owner to restore authoritative state.
+ const settle = useCallback(async function (request: Promise<void>) {
+
+ try {
+
+ await request
+
+ return true
+ }
+
+ catch {
+
+ return false
+ }
+ }, [])
+
const close = useCallback(function (process: Process) {
if (stopping.current.has(process.identity)) return
@@ -257,48 +275,47 @@ export default function useWindows(authManager: AuthManager) {
const window = process.client?.window
- if (!window || window.layer !== "window") return
+ if (!window || window.layer !== "window") return Promise.resolve(false)
- commit(window.move({ x, y }))
+ return settle(window.move({ x, y }))
- }, [commit])
+ }, [settle])
const resize = useCallback(function (process: Process, width: Value, height: Value, position: Position | null) {
const window = process.client?.window
- if (!window || window.layer !== "window") return
+ if (!window || window.layer !== "window") return Promise.resolve(false)
if (!position) {
- commit(window.resize({ width, height }))
+ return settle(window.resize({ width, height }))
- return
}
const geometry = { ...position, width, height }
- commit(window.setGeometry(geometry))
+ return settle(window.setGeometry(geometry))
- }, [commit])
+ }, [settle])
const snap = useCallback(function (process: Process, position: Position, size: Size) {
const window = process.client?.window
- if (!window || window.layer !== "window") return
+ if (!window || window.layer !== "window") return Promise.resolve(false)
const geometry = { ...position, ...size }
- commit(window.setGeometry(geometry))
+ return settle(window.setGeometry(geometry))
- }, [commit])
+ }, [settle])
const fill = useCallback(function (process: Process) {
const window = process.client?.window
- if (!window || window.layer !== "window") return
+ if (!window || window.layer !== "window") return Promise.resolve(false)
const maximized = !presentation.projection(process.identity).maximized
- commit(window.maximize(maximized))
- }, [commit])
+ return settle(window.maximize(maximized))
+ }, [presentation, settle])
// Every window on the desktop, in one list and one order.
//
diff --git a/source/client/view/structure/desktop/windows/process-window.tsx b/source/client/view/structure/desktop/windows/process-window.tsx
index 9a5b892..4cfb9aa 100644
--- a/source/client/view/structure/desktop/windows/process-window.tsx
+++ b/source/client/view/structure/desktop/windows/process-window.tsx
@@ -292,7 +292,7 @@ interface ProcessWindowProps {
onMinimize: (record: Process, minimized: boolean) => void
- onFill: (record: Process) => void
+ onFill: (record: Process) => Promise<boolean>
onClose: (record: Process) => void
@@ -300,11 +300,11 @@ interface ProcessWindowProps {
onUnavailable: (record: Process, reason: "minimize" | "close") => void
- onMove: (record: Process, x: number, y: number) => void
+ onMove: (record: Process, x: number, y: number) => Promise<boolean>
- onResize: (record: Process, width: number, height: number, position: { x: number, y: number } | null) => void
+ onResize: (record: Process, width: number, height: number, position: { x: number, y: number } | null) => Promise<boolean>
- onSnap: (record: Process, position: Position, size: Size) => void
+ onSnap: (record: Process, position: Position, size: Size) => Promise<boolean>
}
interface LoadingState {
diff --git a/source/client/view/structure/desktop/windows/window-geometry-motion.ts b/source/client/view/structure/desktop/windows/window-geometry-motion.ts
index 7dd63c0..397fbd6 100644
--- a/source/client/view/structure/desktop/windows/window-geometry-motion.ts
+++ b/source/client/view/structure/desktop/windows/window-geometry-motion.ts
@@ -40,6 +40,7 @@ export default function useWindowGeometryMotion({ position, size, animation, tra
const animator = useRef<WindowGeometryAnimation | null>(null)
if (!animator.current) animator.current = new WindowGeometryAnimation({ x, y, width, height }, { width: layoutWidth, height: layoutHeight })
const gesturing = useRef(false)
+ const gestureRevision = useRef(0)
const restoringGesture = useRef(false)
const initialized = useRef(false)
const values = useRef({ position, size, animation, transaction, immediate, minimumSize, onComplete })
@@ -179,13 +180,15 @@ export default function useWindowGeometryMotion({ position, size, animation, tra
completeGestureRestore()
gesturing.current = true
+ const revision = ++gestureRevision.current
stop()
const physical = parent.getBoundingClientRect()
return {
bounds: { left: physical.left, top: physical.top, ...logicalSize(parent) },
- region: read()
+ region: read(),
+ revision
}
}
@@ -212,7 +215,31 @@ export default function useWindowGeometryMotion({ position, size, animation, tra
})
}
- function finishGesture(region?: WindowRegion) {
+ function targetGesture(revision: number, region: WindowRegion) {
+
+ if (gestureRevision.current !== revision) return false
+
+ completeGestureRestore()
+ transition(region)
+
+ return true
+ }
+
+ function settleGesture(revision: number) {
+
+ if (gestureRevision.current !== revision) return false
+
+ // The authoritative request has now settled. The visible values
+ // already express its result, so ownership can change without
+ // retargeting Motion through an earlier server snapshot.
+ gesturing.current = false
+
+ return true
+ }
+
+ function finishGesture(region?: WindowRegion, revision = gestureRevision.current) {
+
+ if (gestureRevision.current !== revision) return false
gesturing.current = false
@@ -221,9 +248,13 @@ export default function useWindowGeometryMotion({ position, size, animation, tra
completeGestureRestore()
transition(region)
}
+
+ return true
}
- function cancelGesture() {
+ function cancelGesture(revision = gestureRevision.current) {
+
+ if (gestureRevision.current !== revision) return false
gesturing.current = false
completeGestureRestore()
@@ -234,6 +265,8 @@ export default function useWindowGeometryMotion({ position, size, animation, tra
set(region)
}
+
+ return true
}
return {
@@ -244,6 +277,8 @@ export default function useWindowGeometryMotion({ position, size, animation, tra
beginGesture,
updateGesture,
restoreGesture,
+ targetGesture,
+ settleGesture,
finishGesture,
cancelGesture
}
diff --git a/source/client/view/structure/desktop/windows/window-gesture-commit.ts b/source/client/view/structure/desktop/windows/window-gesture-commit.ts
new file mode 100644
index 0000000..eacfd18
--- /dev/null
+++ b/source/client/view/structure/desktop/windows/window-gesture-commit.ts
@@ -0,0 +1,25 @@
+/** Orders the authoritative mutations produced by one visible Window gesture. */
+export default class WindowGestureCommit {
+
+ private outcome = Promise.resolve(true)
+
+ public request(operation: () => Promise<boolean> | undefined) {
+
+ this.outcome = this.outcome.then(async accepted => {
+
+ if (!accepted) return false
+
+ try {
+
+ return await (operation() ?? true)
+ }
+
+ catch {
+
+ return false
+ }
+ })
+ }
+
+ public settle() { return this.outcome }
+}
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index 00a20a8..baf9a33 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -13,6 +13,7 @@ import { motionTransition, resolveWindowTransaction } from "@client/view/appeara
import { useAppearance, Window as UIWindow } from "@phreshos/react-ui"
import SnapPreview, { type SnapTarget } from "./snap-preview"
import useWindowGeometryMotion from "./window-geometry-motion"
+import WindowGestureCommit from "./window-gesture-commit"
import { physicalToDesktopPixels, useDesktopScale } from "../desktop-scale"
import { createPortal } from "react-dom"
@@ -27,8 +28,8 @@ import { createPortal } from "react-dom"
* through a gesture, and into the next target. Release reports the outcome
* (onMove or onResize with resting pixels —
* a resize carrying an origin only when the edge dragged moved one —
- * onSnap with the shares a zone names) and drops the gesture in the same
- * batch the record updates, so nothing jumps.
+ * onSnap with the shares a zone names). The gesture retains the visible
+ * result until those ordered authoritative mutations settle, then yields.
*
* Motion owns every local interpolation, never the authoritative record.
*
@@ -101,6 +102,7 @@ export default function ({ title, header = true, surface, layer, icon, children,
const frameElement = geometryMotion.frame
const [gesture, setGesture] = useState<Gesture | null>(null)
+ const [settlingGeometry, setSettlingGeometry] = useState<WindowRegion | null>(null)
const [externalMoveActive, setExternalMoveActive] = useState(false)
const externalMove = useRef<ExternalMove | null>(null)
const beginPointerGesture = useRef<(point: PresentationMovePoint) => ActivePointerGesture | null>(() => null)
@@ -304,7 +306,9 @@ export default function ({ title, header = true, surface, layer, icon, children,
if (!started) return
- const { bounds } = started
+ const { bounds, revision } = started
+
+ setSettlingGeometry(null)
// The Motion values are the current visible representation, including
// a geometry animation interrupted by this press.
@@ -328,6 +332,25 @@ export default function ({ title, header = true, surface, layer, icon, children,
let renderFrame = 0
+ const commit = new WindowGestureCommit()
+
+ function request(operation: () => Promise<boolean> | undefined) {
+
+ commit.request(operation)
+ }
+
+ function settle() {
+
+ void commit.settle().then(committed => {
+
+ const current = committed
+ ? geometryMotion.settleGesture(revision)
+ : geometryMotion.cancelGesture(revision)
+
+ if (current) setSettlingGeometry(null)
+ })
+ }
+
const start = { pointerX: pointer.x, pointerY: pointer.y }
// Pointer hardware can report faster than the display can paint. Keep
@@ -406,7 +429,7 @@ export default function ({ title, header = true, surface, layer, icon, children,
if (restoringMaximized) {
const stored = resolvePresentedGeometry(position, size, bounds)
origin = { ...origin, width: stored.width, height: stored.height }
- onMaximize?.()
+ request(() => onMaximize?.())
}
origin = { x: pointerX - origin.width * ratio, y: pointerY - Math.min(Math.max(pointerY - origin.y, 0), 40), width: origin.width, height: origin.height }
@@ -417,7 +440,7 @@ export default function ({ title, header = true, surface, layer, icon, children,
start.pointerY = motion.y
- onMove?.(origin.x, origin.y)
+ request(() => onMove?.(origin.x, origin.y))
if (restoringMaximized) geometryMotion.restoreGesture(current)
@@ -473,7 +496,8 @@ export default function ({ title, header = true, surface, layer, icon, children,
// nothing: the render returns to the tile it never left.
if (restoring) {
- geometryMotion.finishGesture()
+ geometryMotion.finishGesture(undefined, revision)
+ setSettlingGeometry(null)
setGesture(null)
return
@@ -481,32 +505,44 @@ export default function ({ title, header = true, surface, layer, icon, children,
const term = moved && edge === null && committed ? snapTerm(motion) : null
- // The outcome and the gesture's end land in one batch: the
- // record updates as the gesture stops overriding it, so the
- // frame never shows a stale in-between.
+ // Pointer input has ended, but visible gesture ownership remains
+ // until every authoritative mutation below has settled.
if (term) {
- geometryMotion.finishGesture(resolvePresentedGeometry(term.position, term.size, bounds))
- onSnap?.(term.position, term.size)
+ const target = resolvePresentedGeometry(term.position, term.size, bounds)
+ geometryMotion.targetGesture(revision, target)
+ setSettlingGeometry(target)
+ request(() => onSnap?.(term.position, term.size))
+ settle()
}
else if (moved && committed) {
- geometryMotion.finishGesture()
+ setSettlingGeometry(current)
- if (edge === null) onMove?.(current.x, current.y)
+ if (edge === null) request(() => onMove?.(current.x, current.y))
// Only the west and north edges move the origin. A drag
// on any other reports no position, because none was
// chosen — and a position nobody chose would replace a
// share with the pixels it happened to resolve to.
- else onResize?.(current.width, current.height, current.x === origin.x && current.y === origin.y ? null : { x: current.x, y: current.y })
+ else request(() => onResize?.(current.width, current.height, current.x === origin.x && current.y === origin.y ? null : { x: current.x, y: current.y }))
+
+ settle()
+
+ }
+
+ else if (!committed) {
+ geometryMotion.cancelGesture(revision)
+ setSettlingGeometry(null)
}
- else if (!committed) geometryMotion.cancelGesture()
+ else {
- else geometryMotion.finishGesture()
+ geometryMotion.finishGesture(undefined, revision)
+ setSettlingGeometry(null)
+ }
setGesture(null)
}
@@ -538,7 +574,10 @@ export default function ({ title, header = true, surface, layer, icon, children,
// half of Appearance spacing so the painted gap equals the layer inset.
const paintInset = standard ? spacing / 2 : 0
- const paintedInsets = windowPaintInsets(presented.current.position, presented.current.size, paintSurfaceSize, paintInset, gesture?.current)
+ // Pointer input may end before its authoritative mutation settles. Paint
+ // follows the same locally owned geometry throughout that interval so an
+ // old boundary contact cannot flash back for one frame.
+ const paintedInsets = windowPaintInsets(presented.current.position, presented.current.size, paintSurfaceSize, paintInset, gesture?.current ?? settlingGeometry ?? undefined)
return <>
@@ -709,18 +748,18 @@ interface WindowProps extends Omit<ComponentProps<"div">, "onAnimationStart" | "
onMinimize?: () => void
- onMaximize?: () => void
+ onMaximize?: () => Promise<boolean>
onActivate?: () => void
/** The window is leaving interaction; its composition chooses new focus. */
onUnavailable?: (reason: "minimize" | "close") => void
- onMove?: (x: number, y: number) => void
+ onMove?: (x: number, y: number) => Promise<boolean>
- onResize?: (width: number, height: number, position: { x: number, y: number } | null) => void
+ onResize?: (width: number, height: number, position: { x: number, y: number } | null) => Promise<boolean>
- onSnap?: (position: Position, size: Size) => void
+ onSnap?: (position: Position, size: Size) => Promise<boolean>
active?: boolean
diff --git a/tests/window-geometry.test.ts b/tests/window-geometry.test.ts
index 644e273..ec7bd0c 100644
--- a/tests/window-geometry.test.ts
+++ b/tests/window-geometry.test.ts
@@ -32,6 +32,20 @@ test("tiled standard windows share the Appearance gap inside the equally inset s
assert.equal(left.right + right.left, defaultAppearance.spacing)
})
+test("settling paint follows released geometry instead of its former boundary contacts", () => {
+ const surface = { width: 1000, height: 600 }
+ const half = defaultAppearance.spacing / 2
+ const released = { x: 120, y: 90, width: 500, height: 300 }
+ const former = windowPaintInsets({ x: 0, y: 0 }, { width: 500, height: 300 }, surface, half)
+
+ assert.deepEqual(former, { top: 0, right: half, bottom: half, left: 0 })
+
+ assert.deepEqual(
+ windowPaintInsets({ x: 0, y: 0 }, { width: 500, height: 300 }, surface, half, released),
+ { top: half, right: half, bottom: half, left: half }
+ )
+})
+
test("window geometry contract", async () => {
const initial = {
position: { x: 10, y: 20 },
diff --git a/tests/window-gesture.test.ts b/tests/window-gesture.test.ts
new file mode 100644
index 0000000..14cf849
--- /dev/null
+++ b/tests/window-gesture.test.ts
@@ -0,0 +1,49 @@
+import { expect, test } from "vitest"
+import WindowGestureCommit from "@client/view/structure/desktop/windows/window-gesture-commit"
+
+test("a Window gesture orders its authoritative mutations and settles after the last one", async () => {
+
+ let finish!: (accepted: boolean) => void
+ const first = new Promise<boolean>(resolve => { finish = resolve })
+ const commit = new WindowGestureCommit()
+ const calls: string[] = []
+ commit.request(() => {
+ calls.push("first")
+ return first
+ })
+ commit.request(() => {
+ calls.push("final")
+ return Promise.resolve(true)
+ })
+ let settled = false
+ const outcome = commit.settle().then(value => {
+
+ settled = true
+
+ return value
+ })
+
+ await Promise.resolve()
+
+ expect(calls).toEqual(["first"])
+ expect(settled).toBe(false)
+
+ finish(true)
+
+ await expect(outcome).resolves.toBe(true)
+ expect(calls).toEqual(["first", "final"])
+})
+
+test("a rejected authoritative mutation restores the Window instead of accepting the gesture", async () => {
+
+ const commit = new WindowGestureCommit()
+ let finalCalled = false
+ commit.request(() => Promise.reject(new Error("authoritative mutation failed")))
+ commit.request(() => {
+ finalCalled = true
+ return Promise.resolve(true)
+ })
+
+ await expect(commit.settle()).resolves.toBe(false)
+ expect(finalCalled).toBe(false)
+})