An open-source, self-hosted system for apps built with web technologies.
Apply view scaling and shared lifecycle motion
zohayrslileh1e27cbb6f947
diff --git a/source/client/view/appearance/appearance.tsx b/source/client/view/appearance/appearance.tsxindex 7959eac..63fa94f 100644--- a/source/client/view/appearance/appearance.tsx+++ b/source/client/view/appearance/appearance.tsx@@ -1,9 +1,14 @@-import DesktopPreferencesProvider, { useDesktopPreferences } from "./desktop-preferences"-import { defaultAppearance } from "@phreshos/core"+import DesktopPreferencesProvider, { useDesktopPreferences, useDesktopThemeTransaction } from "./desktop-preferences"+import { defaultAppearance, parseAppearance, type Appearance } from "@phreshos/core"+import { UIProvider } from "@phreshos/react-ui"import ReducedMotion from "@libs/react-motion"-import { PropsWithChildren } from "react"+import { createContext, type PropsWithChildren, useCallback, useContext, useLayoutEffect, useState } from "react"+import { DesktopScaleProvider } from "../structure/desktop/desktop-scale"import "./appearance.css"+const appearanceKey = "appearance"+const RememberAppearanceContext = createContext<((appearance: Appearance) => void) | null>(null)+export default function ({ children }: PropsWithChildren) {return <DesktopPreferencesProvider>@@ -15,15 +20,62 @@ export default function ({ children }: PropsWithChildren) {function AppearanceRoot({ children }: PropsWithChildren) {const { preferences } = useDesktopPreferences()- const background = defaultAppearance.colors[preferences.theme].background+ const [appearance, setAppearance] = useState(() => resolveStoredAppearance(localStorage.getItem(appearanceKey)))+ const remember = useCallback(function (value: Appearance) {+ setAppearance(value)+ localStorage.setItem(appearanceKey, JSON.stringify(value))+ }, [])+ const background = appearance.colors[preferences.theme].background++ useDesktopThemeTransaction(appearance.transaction)++ return <RememberAppearanceContext.Provider value={remember}>++ <UIProvider appearance={appearance} preferences={preferences}>++ <DesktopScaleProvider scale={preferences.scale}>++ <div className="relative isolate h-dvh overflow-hidden" style={{ backgroundColor: background }}>++ <ReducedMotion reduced={!preferences.animations}>++ <div+ className="absolute top-0 left-0 isolate grid font-roboto"+ style={{ width: "100%", height: "100%", zoom: preferences.scale }}+ >++ {children}- return <ReducedMotion reduced={!preferences.animations}>+ </div>- <div className="relative isolate grid h-dvh overflow-hidden font-roboto" style={{ backgroundColor: background }}>+ </ReducedMotion>- {children}+ </div>++ </DesktopScaleProvider>++ </UIProvider>++ </RememberAppearanceContext.Provider>+}++/** Replaces the provisional browser snapshot with an authoritative System Appearance. */+export function useRememberSystemAppearance(appearance: Appearance) {+ const remember = useContext(RememberAppearanceContext)++ if (!remember) throw new Error("useRememberSystemAppearance() requires the Desktop Appearance owner")++ useLayoutEffect(() => remember(appearance), [appearance, remember])+}- </div>+/** Restores one complete cached Appearance or falls back to the System default. */+export function resolveStoredAppearance(value: string | null): Appearance {+ if (value === null) return defaultAppearance- </ReducedMotion>+ try {+ return parseAppearance(JSON.parse(value))+ }+ catch {+ return defaultAppearance+ }}diff --git a/source/client/view/appearance/surface-presence.ts b/source/client/view/appearance/surface-presence.tsindex a7feda8..0423bfa 100644--- a/source/client/view/appearance/surface-presence.ts+++ b/source/client/view/appearance/surface-presence.ts@@ -7,6 +7,12 @@ export const surfacePresencePose = Object.freeze({entering: { scale: 0.96, y: 8, opacity: 0 }}) satisfies Record<string, DOMKeyframesDefinition>+/** Shared appearance and disappearance of one complete interactive surface. */+export const surfaceLifecyclePose = Object.freeze({+ visible: { scale: 1, y: 0, opacity: 1 },+ hidden: { scale: 1.05, y: 0, opacity: 0 }+}) satisfies Record<string, DOMKeyframesDefinition>+/** One shared presence transition owned by Appearance. */export function surfacePresenceTransition(reducedMotion: boolean, transaction: AppearanceTransaction): Transition {diff --git a/source/client/view/components/desktop-host/client-host.ts b/source/client/view/components/desktop-host/client-host.tsindex d2091e0..d5ddddb 100644--- a/source/client/view/components/desktop-host/client-host.ts+++ b/source/client/view/components/desktop-host/client-host.ts@@ -31,10 +31,10 @@ export default function useClientHost(authManager: AuthManager, desktop: RefObjeconst desktopViewport = useCallback(function (): DesktopViewportSnapshot {- const bounds = desktop.current?.getBoundingClientRect()+ const element = desktop.current- return bounds- ? { size: { width: Math.round(bounds.width), height: Math.round(bounds.height) } }+ return element+ ? { size: measureElement(element) }: latestDesktopViewport.current}, [desktop])@@ -73,11 +73,11 @@ export default function useClientHost(authManager: AuthManager, desktop: RefObjesetWindowSurfaceSize(current => current.width === width && current.height === height ? current : { width, height })}- const initialDesktop = measure(desktop.current.getBoundingClientRect())+ const initialDesktop = measureElement(desktop.current)latestDesktopViewport.current = { size: initialDesktop }- const initialWindowSurface = windowSurfaceRef.current.getBoundingClientRect()+ const initialWindowSurface = measureElement(windowSurfaceRef.current)rememberWindowSurfaceSize(initialWindowSurface)@@ -312,3 +312,7 @@ export interface SurfaceSize {height: number}++function measureElement(element: HTMLElement): DesktopSize {+ return { width: element.clientWidth, height: element.clientHeight }+}diff --git a/source/client/view/components/loading.tsx b/source/client/view/components/loading.tsxindex d696d6c..b96520d 100644--- a/source/client/view/components/loading.tsx+++ b/source/client/view/components/loading.tsx@@ -1,29 +1,24 @@-import { type ComponentProps } from "react"+import { Surface, type SurfaceProps } from "@phreshos/react-ui"import Spinner from "./spinner"-const loadingBackground = "bg-white/10"+type LoadingProps = Omit<SurfaceProps, "material">-/** The shared treatment for content obscured by an unresolved system state. */-export const obscuredBackground = `${loadingBackground} backdrop-blur-md`+/** A complete loading surface for unresolved content. */+export default function ({ className, style, ...props }: LoadingProps) {-interface LoadingProps extends ComponentProps<"div"> {+ return <Surface- /** Whether content behind the loading layer is blurred. */- blur?: boolean-}--/** A loading surface that obscures unresolved content. Blur is explicitly opt-in. */-export default function ({ blur = false, className, ...props }: LoadingProps) {+ {...props}- return <div+ material={{ opacity: 1 }}- className={`absolute inset-0 z-10 grid rounded-[inherit] ${blur ? obscuredBackground : loadingBackground} ${className ?? ""}`}+ className={`inset-0 z-10 grid ${className ?? ""}`}- {...props}+ style={{ ...style, position: "absolute", borderRadius: style?.borderRadius ?? "inherit" }}>- <Spinner className="m-auto size-6 text-slate-700" />+ <Spinner className="m-auto size-6" />- </div>+ </Surface>}diff --git a/source/client/view/structure/desktop/desktop-scale.tsx b/source/client/view/structure/desktop/desktop-scale.tsxnew file mode 100644index 0000000..12a5fb6--- /dev/null+++ b/source/client/view/structure/desktop/desktop-scale.tsx@@ -0,0 +1,19 @@+import { defaultDesktopScale } from "@phreshos/core"+import { createContext, type ReactNode, useContext } from "react"++const DesktopScaleContext = createContext(defaultDesktopScale)++/** Establishes the ratio between physical browser pixels and Desktop pixels. */+export function DesktopScaleProvider({ children, scale }: Readonly<{ children: ReactNode, scale: number }>) {+ return <DesktopScaleContext.Provider value={scale}>{children}</DesktopScaleContext.Provider>+}++/** Returns the effective scale of the containing Desktop representation. */+export function useDesktopScale() {+ return useContext(DesktopScaleContext)+}++/** Converts one physical browser distance into the Desktop coordinate space. */+export function physicalToDesktopPixels(value: number, scale: number) {+ return value / scale+}diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsxindex 7747731..9efc12a 100644--- a/source/client/view/structure/desktop/desktop.tsx+++ b/source/client/view/structure/desktop/desktop.tsx@@ -112,6 +112,8 @@ export default function Workspace() {function renderWindows(layer: Layer) {+ const animateLifecycle = !isDesktopReplacementLayer(layer)+return windows.panesByLayer[layer].map(({ identity, record, client, local, closing, entering, stopping }) => <ProcessWindowkey={identity}@@ -152,6 +154,8 @@ export default function Workspace() {bare={layer !== "window"}+ animateLifecycle={animateLifecycle}+minimized={local.minimized}maximized={local.maximized}@@ -160,7 +164,7 @@ export default function Workspace() {stopping={stopping}- entering={isDesktopReplacementLayer(layer) ? false : entering}+ entering={animateLifecycle && entering}door={application.doors.program}diff --git a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsxindex 28e9faf..25a279d 100644--- a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx+++ b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx@@ -1,5 +1,5 @@import { type ComponentPropsWithoutRef, ReactNode, useCallback, useEffect, useId, useRef, useState } from "react"-import { surfacePresenceTransition } from "@client/view/appearance/surface-presence"+import { surfaceLifecyclePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"import { cssEasing } from "@client/view/appearance/motion"import { useReducedMotion } from "@libs/react-motion"import { motion } from "motion/react"@@ -124,7 +124,7 @@ export default function ({ label, trigger, children, className, style, ...propsinitial={false}- animate={open ? { scale: 1, opacity: 1 } : { scale: 1.05, opacity: 0 }}+ animate={open ? surfaceLifecyclePose.visible : surfaceLifecyclePose.hidden}transition={surfacePresenceTransition(reducedMotion, transaction)}diff --git a/source/client/view/structure/desktop/windows/process-window.tsx b/source/client/view/structure/desktop/windows/process-window.tsxindex 2f93983..ad7d6b2 100644--- a/source/client/view/structure/desktop/windows/process-window.tsx+++ b/source/client/view/structure/desktop/windows/process-window.tsx@@ -17,7 +17,7 @@ const settleDelay = 80* props so memoization can see which process actually changed even though* the peer deliberately keeps each Process instance alive and mutates it.*/-export default memo(function ({ identity, record, assetId, client, title, icon, position, size, localSurface, geometryAnimation, minimizeAnimation, onLocalAnimationComplete, onLocalRepresentation, paintSurfaceSize, depth, active, minimized, maximized, closing, stopping, entering, bare, door, programAccess, theme, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap }: ProcessWindowProps) {+export default memo(function ({ identity, record, assetId, client, title, icon, position, size, localSurface, geometryAnimation, minimizeAnimation, onLocalAnimationComplete, onLocalRepresentation, paintSurfaceSize, depth, active, minimized, maximized, closing, stopping, entering, bare, animateLifecycle, door, programAccess, theme, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap }: ProcessWindowProps) {const activate = useCallback(() => onRaise(record), [onRaise, record])@@ -114,6 +114,8 @@ export default memo(function ({ identity, record, assetId, client, title, icon,bare={bare}+ animateLifecycle={animateLifecycle}+minimized={minimized}maximized={maximized}@@ -150,7 +152,7 @@ export default memo(function ({ identity, record, assetId, client, title, icon,{/* A launch names one of its client half's own pages; joining itto the program asset route remains the view's responsibility. */}- {!stopping && !closing && <ProgramFrame+ {(!stopping && !closing || bare && animateLifecycle) && <ProgramFramerecord={record}@@ -240,6 +242,8 @@ interface ProcessWindowProps {bare: boolean+ animateLifecycle: boolean+door: stringprogramAccess: ProgramAccessdiff --git a/source/client/view/structure/desktop/windows/shared-resize-boundaries.tsx b/source/client/view/structure/desktop/windows/shared-resize-boundaries.tsxindex c143eb2..16bc5c2 100644--- a/source/client/view/structure/desktop/windows/shared-resize-boundaries.tsx+++ b/source/client/view/structure/desktop/windows/shared-resize-boundaries.tsx@@ -1,12 +1,14 @@import { type PointerEvent as ReactPointerEvent, useState } from "react"import { resizeSharedBoundary, sharedResizeBoundaries, type SharedResizeBoundary, type SharedResizeWindow } from "@client/view/components/window-manager/shared-resize"import { type WindowRegion } from "@client/view/components/window-manager/window-geometry"+import { physicalToDesktopPixels, useDesktopScale } from "../desktop-scale"const thickness = 4export default function SharedResizeBoundaries({ windows, begin, present, commit, finish, cancel }: SharedResizeBoundariesProps) {const boundaries = sharedResizeBoundaries(windows)+ const desktopScale = useDesktopScale()const [active, setActive] = useState<ActiveBoundary | null>(null)@@ -32,7 +34,7 @@ export default function SharedResizeBoundaries({ windows, begin, present, commitconst coordinate = boundary.orientation === "vertical" ? pointer.clientX : pointer.clientY- const requestedDelta = coordinate - start+ const requestedDelta = physicalToDesktopPixels(coordinate - start, desktopScale)if (requestedDelta === 0) returndiff --git a/source/client/view/structure/desktop/windows/window-geometry-motion.ts b/source/client/view/structure/desktop/windows/window-geometry-motion.tsindex 38af2c3..5f584db 100644--- a/source/client/view/structure/desktop/windows/window-geometry-motion.ts+++ b/source/client/view/structure/desktop/windows/window-geometry-motion.ts@@ -108,7 +108,7 @@ export default function useWindowGeometryMotion({ position, size, animation, immconst parent = frame.current?.parentElement- return parent ? resolveWindowGeometry(values.current.position, values.current.size, parent.getBoundingClientRect()) : null+ return parent ? resolveWindowGeometry(values.current.position, values.current.size, logicalSize(parent)) : null}useLayoutEffect(function () {@@ -139,11 +139,11 @@ export default function useWindowGeometryMotion({ position, size, animation, immif (!parent) return- let bounds = parent.getBoundingClientRect()+ let bounds = logicalSize(parent)const observer = new ResizeObserver(function () {- const next = parent.getBoundingClientRect()+ const next = logicalSize(parent)if (next.width === bounds.width && next.height === bounds.height) return@@ -178,7 +178,12 @@ export default function useWindowGeometryMotion({ position, size, animation, immgesturing.current = truestop()- return { bounds: parent.getBoundingClientRect(), region: read() }+ const physical = parent.getBoundingClientRect()++ return {+ bounds: { left: physical.left, top: physical.top, ...logicalSize(parent) },+ region: read()+ }}function updateGesture(region: WindowRegion) {@@ -243,3 +248,7 @@ export default function useWindowGeometryMotion({ position, size, animation, immcancelGesture}}++function logicalSize(element: HTMLElement) {+ return { width: element.clientWidth, height: element.clientHeight }+}diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsxindex 95b089f..1bc08eb 100644--- a/source/client/view/structure/desktop/windows/window.tsx+++ b/source/client/view/structure/desktop/windows/window.tsx@@ -1,6 +1,6 @@import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useEffect, useLayoutEffect, useRef, useState } from "react"import { useReducedMotion } from "@libs/react-motion"-import { surfacePresencePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"+import { surfaceLifecyclePose, surfacePresencePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"import WindowPanel from "./window-panel"import { absoluteWindowGeometry, minimumWindowSize, resolveWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"import { type Position, type Size } from "@phreshos/core"@@ -14,6 +14,7 @@ import { useAppearance } from "@phreshos/react-ui"import SnapPreview, { type SnapTarget } from "./snap-preview"import { windowPaintInset } from "../geometry"import useWindowGeometryMotion from "./window-geometry-motion"+import { physicalToDesktopPixels, useDesktopScale } from "../desktop-scale"/*** A window: a pure function of the record it is given. Every render@@ -47,16 +48,13 @@ const edges: { edge: WindowEdge, className: string }[] = [{ edge: "se", className: "bottom-0 right-0 size-4 cursor-nwse-resize" }]-const surfacePose = {- resting: { scale: 1, y: 0, opacity: 1 },- minimized: { scale: 0.86, y: 28, opacity: 0 },- closing: { scale: 0.86, y: 12, opacity: 0 }-}+const minimizedSurfacePose = { scale: 0.86, y: 28, opacity: 0 }-export default function ({ title, icon, children, onClose, onClosed, onMinimize, onMaximize, onActivate, onUnavailable, onMove, onResize, onSnap, onLocalAnimationComplete, onLocalRepresentation, onFocusCapture, active = false, bare = false, closing = false, stopping = false, minimized = false, maximized = false, animateEntrance = true, position = { x: 0, y: 0 }, size = { width: 520, height: 340 }, localSurface, geometryAnimation, minimizeAnimation, paintSurfaceSize = { width: 0, height: 0 }, minWidth = minimumWindowSize.width, minHeight = minimumWindowSize.height, className, style, ...props }: WindowProps) {+export default function ({ title, icon, children, onClose, onClosed, onMinimize, onMaximize, onActivate, onUnavailable, onMove, onResize, onSnap, onLocalAnimationComplete, onLocalRepresentation, onFocusCapture, active = false, bare = false, closing = false, stopping = false, minimized = false, maximized = false, animateEntrance = true, animateLifecycle = !bare, position = { x: 0, y: 0 }, size = { width: 520, height: 340 }, localSurface, geometryAnimation, minimizeAnimation, paintSurfaceSize = { width: 0, height: 0 }, minWidth = minimumWindowSize.width, minHeight = minimumWindowSize.height, className, style, ...props }: WindowProps) {const reducedMotion = useReducedMotion()const appearanceTransaction = useAppearance().transaction+ const desktopScale = useDesktopScale()// Hidden windows retain their last presentation while lower-priority state changes.const presented = useRef({ position, size })@@ -113,6 +111,10 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,const [presenceHidden, setPresenceHidden] = useState(minimized)+ const mounting = useRef(true)++ useEffect(() => { mounting.current = false }, [])+const minimizeTransaction = minimizeAnimation?.transactionuseLayoutEffect(function () {@@ -135,11 +137,9 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,onUnavailable?.("close")- // Bare layers have no system presence animation, and reduced motion- // has no duration to wait for. The close handshake still completes.- if (bare || reducedMotion) completeClosure()+ if (!animateLifecycle || reducedMotion) completeClosure()- }, [closing, bare, reducedMotion])+ }, [closing, animateLifecycle, reducedMotion])useEffect(function () {@@ -151,27 +151,31 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,}, [bare, minimizeAnimation?.revision, reducedMotion])- const initialPresence = bare || reducedMotion || !animateEntrance- ? surfacePresencePose.entered- : surfacePresencePose.entering+ const initialPresence = !animateLifecycle || reducedMotion || !animateEntrance+ ? surfaceLifecyclePose.visible+ : surfaceLifecyclePose.hidden- const presencePose = closing && !bare- ? surfacePose.closing+ const presencePose = closing && animateLifecycle+ ? surfaceLifecyclePose.hidden: minimized- ? bare ? surfacePresencePose.entering : surfacePose.minimized- : surfacePose.resting+ ? bare ? surfacePresencePose.entering : minimizedSurfacePose+ : surfaceLifecyclePose.visibleconst presenceTransition = reducedMotion? { duration: 0 }- : bare+ : closing && animateLifecycle+ ? surfacePresenceTransition(false, appearanceTransaction)+ : bare? minimizeTransaction? surfacePresenceTransition(false, minimizeTransaction)- : { duration: 0 }- : motionTransition(closing ? appearanceTransaction : minimizeTransaction ?? appearanceTransaction)+ : animateLifecycle && animateEntrance && mounting.current+ ? surfacePresenceTransition(false, appearanceTransaction)+ : { duration: 0 }+ : motionTransition(minimizeTransaction ?? appearanceTransaction)function completePresence() {- if (closing && !bare) completeClosure()+ if (closing && animateLifecycle) completeClosure()if (minimized) setPresenceHidden(true)@@ -246,9 +250,9 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,// its own space.function snapTerm(motion: globalThis.PointerEvent): Snap | null {- const pointerX = motion.clientX - bounds!.left+ const pointerX = physicalToDesktopPixels(motion.clientX - bounds!.left, desktopScale)- const pointerY = motion.clientY - bounds!.top+ const pointerY = physicalToDesktopPixels(motion.clientY - bounds!.top, desktopScale)const west = pointerX <= 16@@ -270,26 +274,30 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,function move(motion: globalThis.PointerEvent) {- const dx = motion.clientX - start.pointerX+ const physicalX = motion.clientX - start.pointerX- const dy = motion.clientY - start.pointerY+ const physicalY = motion.clientY - start.pointerY++ const dx = physicalToDesktopPixels(physicalX, desktopScale)++ const dy = physicalToDesktopPixels(physicalY, desktopScale)// A click is not a drag: without this, releasing a stationary// press inside a snap zone would snap the window.- if (Math.hypot(dx, dy) >= 4) moved = true+ if (Math.hypot(physicalX, physicalY) >= 4) moved = trueif (restoring) {- if (Math.hypot(dx, dy) < 8) return+ if (Math.hypot(physicalX, physicalY) < 8) returnrestoring = false// The window returns to its floating size placed so the// pointer keeps its proportional position across the// header, and the same gesture carries on dragging.- const pointerX = motion.clientX - bounds!.left+ const pointerX = physicalToDesktopPixels(motion.clientX - bounds!.left, desktopScale)- const pointerY = motion.clientY - bounds!.top+ const pointerY = physicalToDesktopPixels(motion.clientY - bounds!.top, desktopScale)const ratio = Math.min(Math.max((pointerX - origin.x) / origin.width, 0), 1)@@ -592,6 +600,9 @@ interface WindowProps extends Omit<ComponentProps<"div">, "onAnimationStart" | "// Whether mounting this element represents a newly opened window.animateEntrance?: boolean+ /** Whether creation and departure animate this complete Window representation. */+ animateLifecycle?: boolean+position?: Positionsize?: Sizediff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsxindex 794fcd7..bbb2a7e 100644--- a/source/client/view/structure/structure.tsx+++ b/source/client/view/structure/structure.tsx@@ -2,21 +2,23 @@ import { ReactTunnel } from "@the-link/react"import { useProperty } from "@the-link/react"import { LinkManagerSnapshot } from "@server/core/link-manager/link-manager"import LinkManager from "@client/core/link-manager/link-manager"-import { UIProvider, useThemedValue } from "@phreshos/react-ui"+import { useAppearance } from "@phreshos/react-ui"import Loading from "../components/loading"import Alert from "../components/alert"import { ApplicationContext, LinkManagerContext } from "../contexts"import usePromise from "@libs/react-promise"-import { useDesktopPreferences, useDesktopThemeTransaction } from "../appearance/desktop-preferences"+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 { defaultAppearance, type DesktopPreferencesUpdate } from "@phreshos/core"+import { type DesktopPreferencesUpdate } from "@phreshos/core"import { cssEasing } from "../appearance/motion"const startupRequirements = ["connection", "session", "wallpaper"] as constexport default function () {+ const appearance = useAppearance()return <Readiness requirements={startupRequirements}>@@ -32,9 +34,8 @@ export default function () {className={pending.length ? "opacity-100" : "pointer-events-none opacity-0"}style={{- backgroundColor: defaultAppearance.colors.light.background,- transitionDuration: String(defaultAppearance.transaction.duration) + "ms",- transitionTimingFunction: cssEasing(defaultAppearance.transaction.easing),+ transitionDuration: String(appearance.transaction.duration) + "ms",+ transitionTimingFunction: cssEasing(appearance.transaction.easing),transitionProperty: "opacity"}}/>}@@ -115,7 +116,7 @@ function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {const appearance = useProperty(linkManager.appearance)- useDesktopThemeTransaction(appearance.transaction)+ useRememberSystemAppearance(appearance)useEffect(function () {void linkManager.updateDesktopPreferences(preferences)@@ -123,22 +124,7 @@ function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {return <LinkManagerContext.Provider value={linkManager}>- <UIProvider appearance={appearance} preferences={preferences}>-- <ConnectedAppearance>-- <Authentication />-- </ConnectedAppearance>-- </UIProvider>+ <Authentication /></LinkManagerContext.Provider>}--function ConnectedAppearance({ children }: { children: React.ReactNode }) {-- const background = useThemedValue(LinkManagerContext.useValue().appearance.value.colors).background-- return <div className="grid min-h-0" style={{ backgroundColor: background }}>{children}</div>-}diff --git a/tests/client-appearance.test.ts b/tests/client-appearance.test.tsnew file mode 100644index 0000000..9c0e4d7--- /dev/null+++ b/tests/client-appearance.test.ts@@ -0,0 +1,18 @@+import { defaultAppearance } from "@phreshos/core"+import { describe, expect, it } from "vitest"+import { resolveStoredAppearance } from "../source/client/view/appearance/appearance.js"++describe("Desktop Appearance bootstrap", () => {+ it("restores one complete cached System Appearance", () => {+ const stored = {+ ...defaultAppearance,+ spacing: 15+ }++ expect(resolveStoredAppearance(JSON.stringify(stored))).toEqual(stored)+ })++ it.each([null, "not json", "{}"])("uses the System default when the cached value is %s", value => {+ expect(resolveStoredAppearance(value)).toBe(defaultAppearance)+ })+})diff --git a/tests/desktop-replacements.test.tsx b/tests/desktop-replacements.test.tsxindex 798068f..d078a18 100644--- a/tests/desktop-replacements.test.tsx+++ b/tests/desktop-replacements.test.tsx@@ -71,7 +71,7 @@ test("Desktop replaces its default wallpaper with the running Client and restoreexpect(running).not.toContain("data-default-wallpaper")expect(fixture.fallback).not.toHaveBeenCalled()expect(fixture.pane.mock.lastCall?.[0]).toMatchObject({- bare: true, minimized: false, maximized: true, entering: false, localSurface: null,+ bare: true, animateLifecycle: false, minimized: false, maximized: true, entering: false, localSurface: null,position: { x: 0, y: 0 }, size: { width: "100%", height: "100%" }, depth: 0})@@ -102,7 +102,7 @@ test("Desktop replaces the built-in Start Menu in its existing host and restoresexpect(running).toContain('title="start-menu Client"')expect(running).not.toContain("data-default-start-menu")expect(fixture.pane.mock.lastCall?.[0]).toMatchObject({- bare: true, minimized: false, maximized: true, entering: false, localSurface: null,+ bare: true, animateLifecycle: false, minimized: false, maximized: true, entering: false, localSurface: null,position: { x: 0, y: 0 }, size: { width: "100%", height: "100%" }, depth: 0})diff --git a/tests/desktop-scale.test.ts b/tests/desktop-scale.test.tsnew file mode 100644index 0000000..4ae30ea--- /dev/null+++ b/tests/desktop-scale.test.ts@@ -0,0 +1,9 @@+import { describe, expect, it } from "vitest"+import { physicalToDesktopPixels } from "../source/client/view/structure/desktop/desktop-scale.js"++describe("Desktop scale", () => {+ it("converts physical movement into Desktop pixels", () => {+ expect(physicalToDesktopPixels(125, 1.25)).toBe(100)+ expect(physicalToDesktopPixels(40, 0.5)).toBe(80)+ })+})