Skip to content

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

Own Program iframe color scheme

zohayrslileh1e27731024d8
diff --git a/scripts/contracts/program-frame.tsx b/scripts/contracts/program-frame.tsx
new file mode 100644
index 0000000..8c83bce
--- /dev/null
+++ b/scripts/contracts/program-frame.tsx
@@ -0,0 +1,23 @@
+import assert from "node:assert/strict"
+import { renderToStaticMarkup } from "react-dom/server"
+import ProgramFrame from "@client/view/components/program-frame"
+import type Process from "@client/core/link-manager/auth-manager/process-manager/process"
+import type ClientState from "@client/core/link-manager/auth-manager/process-manager/client-state"
+
+const record = { identity: "process", assetId: "asset" } as Process
+const client = { window: { url: null, location: "/" } } as ClientState
+const common = {
+ record,
+ client,
+ title: "Program",
+ door: "/program",
+ access: "available" as const,
+ onFrame() {},
+ onLoad() {}
+}
+
+const dark = renderToStaticMarkup(<ProgramFrame {...common} theme="dark" />)
+const light = renderToStaticMarkup(<ProgramFrame {...common} theme="light" />)
+
+assert.match(dark, /style="color-scheme:dark"/)
+assert.match(light, /style="color-scheme:light"/)
diff --git a/source/client/view/components/program-frame.tsx b/source/client/view/components/program-frame.tsx
index c99b13b..b4c49a7 100644
--- a/source/client/view/components/program-frame.tsx
+++ b/source/client/view/components/program-frame.tsx
@@ -1,6 +1,7 @@
import Process from "@client/core/link-manager/auth-manager/process-manager/process"
import ClientState from "@client/core/link-manager/auth-manager/process-manager/client-state"
import { blockedProgramDocument, type ProgramAccess } from "./program-access"
+import { type Theme } from "@phreshos/core"
import { type ReactEventHandler, useCallback } from "react"
export function programFrameSource(record: Process, client: ClientState, door: string) {
@@ -15,7 +16,7 @@ export function programFrameSource(record: Process, client: ClientState, door: s
}
/** The one sandboxed document representation shared by every Client role. */
-export default function ProgramFrame({ record, client, title, door, access, className = "size-full border-0", onFrame, onLoad }: ProgramFrameProps) {
+export default function ProgramFrame({ record, client, title, door, access, theme, className = "size-full border-0", onFrame, onLoad }: ProgramFrameProps) {
const source = useCallback((element: HTMLIFrameElement | null) => onFrame(record.identity, element), [onFrame, record.identity])
@@ -35,6 +36,8 @@ export default function ProgramFrame({ record, client, title, door, access, clas
return <iframe
+ style={{ colorScheme: theme }}
+
src={programFrameSource(record, client, door)}
title={title}
@@ -62,6 +65,8 @@ interface ProgramFrameProps {
access: ProgramAccess
+ theme: Theme
+
className?: string
onFrame: (identity: string, element: HTMLIFrameElement | null) => void
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsx
index 5d56db6..4719769 100644
--- a/source/client/view/structure/desktop/desktop.tsx
+++ b/source/client/view/structure/desktop/desktop.tsx
@@ -17,7 +17,7 @@ import useWindows from "../../components/window-manager/window-manager"
import { ReadyWallpaper, WallpaperBackground } from "./wallpaper/wallpaper"
import Loading from "../../components/loading"
import { useRequirement } from "@libs/readiness/main"
-import { useAppearance, useResolveTheme } from "@phreshos/react-ui"
+import { useAppearance, useResolveTheme, useTheme } from "@phreshos/react-ui"
export default function Workspace() {
@@ -27,6 +27,8 @@ export default function Workspace() {
const desktopWallpaper = useResolveTheme(useAppearance().desktopWallpaper)
+ const theme = useTheme()
+
const windows = useWindows(authManager)
const completePrograms = useRequirement("programs")
@@ -140,6 +142,8 @@ export default function Workspace() {
programAccess={programAccess}
+ theme={theme}
+
onFrame={frame}
onFrameLoad={frameLoaded}
diff --git a/source/client/view/structure/desktop/windows/process-window.tsx b/source/client/view/structure/desktop/windows/process-window.tsx
index 5fa2a09..d135906 100644
--- a/source/client/view/structure/desktop/windows/process-window.tsx
+++ b/source/client/view/structure/desktop/windows/process-window.tsx
@@ -4,7 +4,7 @@ import { type WindowSurfaceSize } from "../../../components/window-manager/windo
import { type LocalAnimation, type LocalSurfaceState } from "../../../components/desktop-host/local-window"
import { type LocalGeometryReader } from "../../../components/window-manager/local-windows"
import { type ProgramAccess } from "../../../components/program-access"
-import { type Position, type Size } from "@phreshos/core"
+import { type Position, type Size, type Theme } from "@phreshos/core"
import Spinner from "../../../components/spinner"
import Window from "./window"
import ProgramFrame, { programFrameSource } from "../../../components/program-frame"
@@ -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, client, title, icon, position, size, localSurface, geometryAnimation, onLocalAnimationComplete, onLocalRepresentation, paintSurfaceSize, depth, active, minimized, closing, stopping, entering, bare, door, programAccess, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap }: ProcessWindowProps) {
+export default memo(function ({ identity, record, client, title, icon, position, size, localSurface, geometryAnimation, onLocalAnimationComplete, onLocalRepresentation, paintSurfaceSize, depth, active, minimized, closing, stopping, entering, bare, door, programAccess, theme, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap }: ProcessWindowProps) {
const activate = useCallback(() => onRaise(record), [onRaise, record])
@@ -161,6 +161,8 @@ export default memo(function ({ identity, record, client, title, icon, position,
access={programAccess}
+ theme={theme}
+
className={`size-full border-0 ${frameLoading ? "opacity-0" : ""}`}
onFrame={onFrame}
@@ -245,6 +247,8 @@ interface ProcessWindowProps {
programAccess: ProgramAccess
+ theme: Theme
+
onFrame: (identity: string, element: HTMLIFrameElement | null) => void
onFrameLoad: (identity: string, element: HTMLIFrameElement) => void