An open-source, self-hosted system for apps built with web technologies.
Refine window panels and add Start menu process management
zohayrslileheb471fb0a6c2
diff --git a/scripts/contracts/panel.tsx b/scripts/contracts/panel.tsxindex 6870286..c6f9010 100644--- a/scripts/contracts/panel.tsx+++ b/scripts/contracts/panel.tsx@@ -7,6 +7,7 @@ import CredentialsForm from "@client/view/structure/authentication/credentials-fimport TaskbarSurface from "@client/view/structure/desktop/taskbar/taskbar-surface"import Launcher from "@client/view/structure/desktop/taskbar/launcher/launcher"import Window from "@client/view/structure/desktop/windows/window"+import StartMenuPanel from "@client/view/structure/desktop/taskbar/launcher/start-menu-panel"function markup(children: ReactNode) {return renderToStaticMarkup(<AppearanceProvider appearance={standardAppearance} theme="light">{children}</AppearanceProvider>)@@ -24,7 +25,11 @@ assert.match(taskbar, /<h2 id="title"/)assert.match(taskbar, /<button>Action<\/button>/)const window = markup(<Window icon="/icon.svg" title="Window"><iframe title="Content" /></Window>)-panel(window)+assert.equal(window.match(/data-surface-material=""/g)?.length, 1)+assert.match(window, /grid-template-rows:auto minmax\(0, 1fr\)/)+assert.match(window, /data-window-content="true"/)+assert.doesNotMatch(window, /border-top:1px solid yellow/)+assert.doesNotMatch(window, /margin:6px;margin-top:0/)assert.match(window, /data-window-container/)assert.match(window, /<iframe title="Content"/)assert.doesNotMatch(window, /class="p-px"/)@@ -41,8 +46,14 @@ assert.match(authentication, /name="username"/)assert.match(authentication, /name="password"/)assert.match(authentication, /type="submit"/)-const launcher = markup(<Launcher label="Menu" trigger="Open">{() => <button>Action</button>}</Launcher>)-panel(launcher)+const launcher = markup(<Launcher label="PhreshOS" trigger="Open">{(_close, labelId) => <StartMenuPanel labelId={labelId} version="1.2.3" left={<button>Programs</button>} right={<p>Processes</p>} />}</Launcher>)+assert.equal(launcher.match(/data-surface-material=""/g)?.length, 3)+assert.match(launcher, /grid-cols-2/)+assert.match(launcher, /<button>Programs<\/button>/)+assert.match(launcher, /<p>Processes<\/p>/)+assert.match(launcher, /<h2[^>]*>PhreshOS<\/h2>/)+assert.match(launcher, /System version 1.2.3/)+assert.match(launcher, /size-4 rounded-sm object-contain/)// Native popover visibility belongs to the outer host, not Panel's grid.const popover = launcher.match(/<div[^>]*popover="auto"[^>]*>/)?.[0]assert(popover)diff --git a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsxindex f198809..e072f01 100644--- a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx+++ b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx@@ -1,7 +1,7 @@import { type ComponentPropsWithoutRef, ReactNode, useCallback, useEffect, useId, useRef, useState } from "react"import { enterSurface, prepareSurfaceEntrance, restSurface } from "@client/view/appearance/surface-presence"import { useReducedMotion } from "@libs/react-motion"-import TaskbarSurface, { taskbarSurfaceClassName } from "../taskbar-surface"+import { taskbarSurfaceClassName } from "../taskbar-surface"import TaskbarButton from "../taskbar-button"/**@@ -111,11 +111,7 @@ export default function ({ label, trigger, children, className, ...props }: Laun>- <TaskbarSurface label={label} labelId={`${id}-label`}>-- {children(close)}-- </TaskbarSurface>+ {children(close, `${id}-label`)}</div>@@ -128,5 +124,5 @@ export interface LauncherProps extends Omit<ComponentPropsWithoutRef<"div">, "chtrigger: ReactNode- children: (close: () => void) => ReactNode+ children: (close: () => void, labelId: string) => ReactNode}diff --git a/source/client/view/structure/desktop/taskbar/launcher/processes/process-item.tsx b/source/client/view/structure/desktop/taskbar/launcher/processes/process-item.tsxnew file mode 100644index 0000000..854c882--- /dev/null+++ b/source/client/view/structure/desktop/taskbar/launcher/processes/process-item.tsx@@ -0,0 +1,47 @@+import { Button } from "@phreshos/react-ui"+import type Process from "@client/core/link-manager/auth-manager/process-manager/process"+import usePromise from "@libs/react-promise"+import type Program from "@client/core/link-manager/auth-manager/program-manager/program"+import { ApplicationContext } from "@client/view/contexts"+import programIcon from "../../../programs/program-icon"++/** The exit action requests authority; the live list owns removal. */+export default function ProcessItem({ process, program }: Readonly<{ process: Process, program: Program | undefined }>) {++ const application = ApplicationContext.useValue()++ const ending = usePromise(() => process.exit())++ const status = [+ process.server ? process.server.ready ? "Server ready" : "Server starting" : null,+ process.client ? "Client running" : null+ ].filter(Boolean).join(" · ") || "No active endpoints"++ return <li className="grid min-w-0 grid-cols-[1.5rem_minmax(0,1fr)_auto] items-center gap-x-2 gap-y-1 border-b border-current/10 px-3 py-1.5 last:border-b-0">++ {program ? <img src={programIcon(application.doors.program, program.assetId)} alt="" draggable={false} className="size-6 object-contain" /> : <span aria-hidden="true" />}++ <div className="min-w-0">++ <p className="m-0 truncate text-sm font-medium" title={`${program?.name ?? process.program} · ${process.identity}`}>+ {program?.name ?? process.program} <span className="text-xs font-normal opacity-60">· {process.name ?? process.identity}</span>+ </p>++ <p className="m-0 truncate text-xs opacity-50" title={status}>{status}</p>++ </div>++ <Button+ size="xsmall"+ color="danger"+ pending={ending.isPending}+ aria-label={`End process ${process.name ?? process.identity}`}+ onPress={() => void ending.safeExecute()}+ >{ending.isPending ? "Ending…" : "End"}</Button>++ {ending.exception && <p role="alert" className="col-span-3 m-0 text-xs">+ {ending.exception.current instanceof Error ? ending.exception.current.message : "Could not end this Process."}+ </p>}++ </li>+}diff --git a/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsx b/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsxnew file mode 100644index 0000000..f738cd1--- /dev/null+++ b/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsx@@ -0,0 +1,33 @@+import { ReactTunnel } from "@the-link/react"+import { AuthManagerContext } from "@client/view/contexts"+import ProcessItem from "./process-item"++/** All live Processes, including those without a Client window. */+export default function Processes() {++ const manager = AuthManagerContext.useValue().processManager++ const inbound = ReactTunnel.useFactory(manager.$inbound)++ const processes = inbound.useFirstState("/processes", [...manager.processes.values()])++ const programManager = manager.authManager.programManager++ const programsInbound = ReactTunnel.useFactory(programManager.$inbound)++ const programs = programsInbound.useFirstState("/programs", [...programManager.programs.values()])++ const programsByIdentity = new Map(programs.map(program => [program.identity, program]))++ return <div role="group" aria-label="Processes" className="grid h-full min-h-0 grid-rows-[auto_minmax(0,1fr)] p-2">++ <h3 className="px-3 py-2 text-xs font-medium opacity-60">Processes · {processes.length}</h3>++ {processes.length ? <ul className="m-0 min-h-0 list-none overflow-y-auto p-0">++ {processes.map(process => <ProcessItem key={process.identity} process={process} program={programsByIdentity.get(process.program)} />)}++ </ul> : <p className="m-0 grid min-h-32 place-items-center px-3 py-8 text-center text-sm opacity-50">No Processes</p>}++ </div>+}diff --git a/source/client/view/structure/desktop/taskbar/launcher/launcher-item.tsx b/source/client/view/structure/desktop/taskbar/launcher/programs/launcher-item.tsxsimilarity index 94%rename from source/client/view/structure/desktop/taskbar/launcher/launcher-item.tsxrename to source/client/view/structure/desktop/taskbar/launcher/programs/launcher-item.tsxindex 50a6507..3579531 100644--- a/source/client/view/structure/desktop/taskbar/launcher/launcher-item.tsx+++ b/source/client/view/structure/desktop/taskbar/launcher/programs/launcher-item.tsx@@ -1,6 +1,6 @@import { ComponentProps, ReactNode } from "react"-/** One action in a launcher, without knowing what it launches. */+/** One action in the Programs half of the launcher. */export default function ({ icon, label, description, children, className, ...props }: LauncherItemProps) {return <buttondiff --git a/source/client/view/structure/desktop/taskbar/launcher/programs-section.tsx b/source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsxsimilarity index 84%rename from source/client/view/structure/desktop/taskbar/launcher/programs-section.tsxrename to source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsxindex 687f698..338ce14 100644--- a/source/client/view/structure/desktop/taskbar/launcher/programs-section.tsx+++ b/source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsx@@ -1,18 +1,18 @@import LauncherItem from "./launcher-item"-import programIcon from "../../programs/program-icon"-import usePrograms from "../../programs/programs"+import programIcon from "../../../programs/program-icon"+import usePrograms from "../../../programs/programs"import { ApplicationContext } from "@client/view/contexts"import Program from "@client/core/link-manager/auth-manager/program-manager/program"import usePromise from "@libs/react-promise"import Alert from "@client/view/components/alert"-interface ProgramsSectionProps {+interface ProgramsProps {onChoose: () => void}/** The installed-program section of the Start Menu. */-export default function ProgramsSection({ onChoose }: ProgramsSectionProps) {+export default function Programs({ onChoose }: ProgramsProps) {const application = ApplicationContext.useValue()@@ -20,6 +20,8 @@ export default function ProgramsSection({ onChoose }: ProgramsSectionProps) {return <div role="group" aria-label="Programs" className="grid min-h-0 max-h-full gap-1 overflow-y-auto p-2">+ <h3 className="px-3 py-2 text-xs font-medium opacity-60">Programs · {programs.length}</h3>+{programs.length? programs.map(record => <ProgramItemdiff --git a/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsx b/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsxnew file mode 100644index 0000000..71b7dc1--- /dev/null+++ b/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsx@@ -0,0 +1,33 @@+import { type ReactNode } from "react"+import { Surface, useAppearance, useResolveTheme, useScale } from "@phreshos/react-ui"+import logo from "@/assets/bundled/logo.png"++/** Start menu shell: one outer material and two independently scrolling halves. */+export default function StartMenuPanel({ labelId, version, left, right }: Readonly<{ labelId: string, version: string, left: ReactNode, right: ReactNode }>) {++ const appearance = useAppearance()++ const spacing = useScale(useResolveTheme(appearance.spacing)).small++ return <Surface style={{ display: "grid", gridTemplateRows: "auto minmax(0, 1fr)", minHeight: 0, maxHeight: "inherit", overflow: "hidden" }}>++ <header className="relative grid h-10 shrink-0 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 px-3.5 select-none">++ <img src={logo} alt="" draggable={false} className="size-4 rounded-sm object-contain" />++ <h2 id={labelId} className="m-0 truncate text-window-title font-medium">PhreshOS</h2>++ <span className="text-xs tabular-nums opacity-60" aria-label={`System version ${version}`}>v{version}</span>++ </header>++ <div className="grid min-h-0 grid-cols-2" style={{ gap: spacing, padding: spacing, paddingTop: 0 }}>++ <Surface className="min-h-0 min-w-0 overflow-hidden">{left}</Surface>++ <Surface className="min-h-0 min-w-0 overflow-hidden">{right}</Surface>++ </div>++ </Surface>+}diff --git a/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx b/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsxindex ac623f0..82a44f7 100644--- a/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx+++ b/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx@@ -1,28 +1,38 @@import logo from "@/assets/bundled/logo.png"import { memo } from "react"import Launcher from "./launcher"-import ProgramsSection from "./programs-section"+import Programs from "./programs/programs"+import Processes from "./processes/processes"+import StartMenuPanel from "./start-menu-panel"+import { ApplicationContext } from "@client/view/contexts"/** The taskbar entry point for current and future desktop actions. */export default memo(function StartMenu() {+ const application = ApplicationContext.useValue()+return <Launcher- label="Start Menu"+ label="PhreshOS"trigger={<><img src={logo} alt="" className="size-5 shrink-0" />- <span className="hidden text-xs font-semibold sm:inline">Start Menu</span>+ <span className="hidden text-xs font-semibold sm:inline">PhreshOS</span></>}- className="inset-auto inset-be-[calc(anchor(top)+var(--desktop-gutter))] inset-s-[anchor(start)] max-h-[min(32rem,calc(100vh-var(--spacing-taskbar)-var(--desktop-gutter)*3))] w-[min(22rem,calc(100vw-var(--desktop-gutter)*2))] [position-anchor:--desktop-taskbar]"+ className="inset-auto inset-be-[calc(anchor(top)+var(--desktop-gutter))] inset-s-[anchor(start)] max-h-[min(32rem,calc(100vh-var(--spacing-taskbar)-var(--desktop-gutter)*3))] w-[min(44rem,calc(100vw-var(--desktop-gutter)*2))] [position-anchor:--desktop-taskbar]">- {close => <ProgramsSection onChoose={close} />}+ {(close, labelId) => <StartMenuPanel+ labelId={labelId}+ version={application.version}+ left={<Programs onChoose={close} />}+ right={<Processes />}+ />}</Launcher>})diff --git a/source/client/view/structure/desktop/windows/window-panel.tsx b/source/client/view/structure/desktop/windows/window-panel.tsxnew file mode 100644index 0000000..1f1f6aa--- /dev/null+++ b/source/client/view/structure/desktop/windows/window-panel.tsx@@ -0,0 +1,28 @@+import { forwardRef, type ReactNode } from "react"+import { Surface, type SurfaceProps } from "@phreshos/react-ui"++/** Temporary standard-window test: header and unpadded content, without an inner Surface. */+const WindowPanel = forwardRef<HTMLDivElement, SurfaceProps & { header: ReactNode }>(function WindowPanel(+ { header, children, style, ...properties },+ ref+) {+ return <Surface+ {...properties}+ ref={ref}+ style={{+ display: "grid",+ gridTemplateRows: "auto minmax(0, 1fr)",+ minWidth: 0,+ minHeight: 0,+ overflow: "hidden",+ ...style+ }}+ >+ {header}+ <div data-window-content style={{ position: "relative", minWidth: 0, minHeight: 0, overflow: "hidden" }}>+ {children}+ </div>+ </Surface>+})++export default WindowPaneldiff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsxindex bf78283..90b2fa4 100644--- a/source/client/view/structure/desktop/windows/window.tsx+++ b/source/client/view/structure/desktop/windows/window.tsx@@ -1,7 +1,7 @@import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useLayoutEffect, useRef, useState } from "react"import { useReducedMotion } from "@libs/react-motion"import { enterSurface, prepareSurfaceEntrance, restSurface } from "@client/view/appearance/surface-presence"-import { Panel } from "@phreshos/react-ui"+import WindowPanel from "./window-panel"import { absoluteWindowGeometry, resolveWindowGeometry, resolveWindowValue, wholeWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"import { type Position, type Size, type WindowGeometry } from "@phreshos/core"import WindowHeader from "./window-header"@@ -30,8 +30,8 @@ import { windowPaintInset } from "../geometry"* GSAP owns every structural interpolation: frame geometry, local Surface* replacement, and the scale and drift of presence. It never owns state.*- * The chrome uses the shared system material and content sits on an inset- * sheet. The close control requests — the window leaves only when the truth+ * The chrome uses the shared system material. Content currently uses the+ * plain WindowPanel test. The close control requests — the window leaves only when the truth* drops its process.*/const edges: { edge: WindowEdge, className: string }[] = [@@ -711,7 +711,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,<div data-window-content className="relative min-h-0">{children}</div>- </div> : <Panel+ </div> : <WindowPaneldata-window-containerref={surfaceElement}style={paintedInsets}@@ -739,7 +739,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,stopping={stopping || closing}/>}- >{children}</Panel>}+ >{children}</WindowPanel>}{!bare && edges.map(handle => <div