An open-source, self-hosted system for apps built with web technologies.
Start Menu laid out as Files: sidebar of views and categories, search and view switch, recessed Programs or Processes, a status line, a drawer when narrow, and Settings at the sidebar's foot
zohayrslileh49e5b1381bf5
diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/empty.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/empty.tsxnew file mode 100644index 0000000..67efb2c--- /dev/null+++ b/source/client/view/structure/desktop/layers/shell/start-menu/empty.tsx@@ -0,0 +1,12 @@+import { Text, useAppearance, useScale } from "@phreshos/react-ui"++/**+ * A quiet line where a list has nothing to show, in the middle of the content: the content is a size+ * container, and the line fills its height less the content's padding above and below.+ */+export default function Empty({ children }: Readonly<{ children: string }>) {++ const space = useScale(useAppearance().spacing)++ return <Text tone="secondary" size="small" className="grid place-items-center text-center" style={{ minHeight: `calc(100cqh - ${space.large * 2}px)` }}>{children}</Text>+}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/live.ts b/source/client/view/structure/desktop/layers/shell/start-menu/live.tsnew file mode 100644index 0000000..0ea52c2--- /dev/null+++ b/source/client/view/structure/desktop/layers/shell/start-menu/live.ts@@ -0,0 +1,20 @@+import { AuthManagerContext } from "@client/view/contexts"+import { useLayoutEffect, useState } from "react"++/** Every live Process, including those without a Client window, and every Program they belong to. */+export default function useLive() {++ const manager = AuthManagerContext.useValue().processManager++ const programManager = manager.authManager.programManager++ const [processes, setProcesses] = useState(() => [...manager.processes.values()])++ const [programs, setPrograms] = useState(() => [...programManager.programs.values()])++ useLayoutEffect(() => manager.subscribeProcesses(setProcesses), [manager])++ useLayoutEffect(() => programManager.subscribePrograms(setPrograms), [programManager])++ return { processes, programs: new Map(programs.map(program => [program.identity, program])) }+}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/processes/process-item.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/processes/process-item.tsxindex 4f40fb9..c0fe22e 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/processes/process-item.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/processes/process-item.tsx@@ -7,7 +7,7 @@ import { ApplicationContext } from "@client/view/contexts"import programIcon from "@client/view/structure/desktop/programs/program-icon"/**- * One live Process as a table row: its Program and name, a mark for each+ * One live Process as a table row: its name, its Program, a mark for each* running Endpoint, colored only while it is still starting, and a quiet action* to end it. The live list owns removal.*/@@ -35,14 +35,14 @@ export default function ProcessRow({ process, program, server, client }: Readonl<Table.Cell><span className="flex min-w-0 items-center" style={{ gap: space.small, maxWidth: "100%" }}>{program ? <img src={programIcon(application.doors.program, program.assetId)} alt="" draggable={false} style={{ width: space.medium, height: space.medium }} className="shrink-0 object-contain" /> : null}- <span className="min-w-0 truncate" title={`${program?.name ?? process.program} · ${process.identity}`}>- {program?.name ?? process.program} <Text tone="secondary">· {label}</Text>- </span>+ <span className="min-w-0 truncate" title={process.identity}>{label}</span>{/* A failure to end stays beside the Process it belongs to. */}{failure && <span role="alert" className="min-w-0 truncate" title={failure} style={{ color: danger }}>{failure}</span>}</span></Table.Cell>+ <Table.Cell><Text tone="secondary" className="block truncate">{program?.name ?? process.program}</Text></Table.Cell>+<Table.Cell><span className="flex" style={{ gap: space.xsmall }}>{/* Color marks only what needs attention: a running Endpoint is neutral, one still starting is not. */}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsxindex 370f790..577b6c1 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsx@@ -1,51 +1,35 @@-import { AuthManagerContext } from "@client/view/contexts"+import type Process from "@client/core/link-manager/auth-manager/process-manager/process"+import type Program from "@client/core/link-manager/auth-manager/program-manager/program"import ProcessRow from "./process-item"-import { matchesProcess } from "../search"-import Section from "../section"import { Table, useAppearance, useScale } from "@phreshos/react-ui"-import { useLayoutEffect, useState } from "react"+import Empty from "../empty"-/** All live Processes, including those without a Client window, as a small table. */-export default function Processes({ terms }: Readonly<{ terms: readonly string[] }>) {-- const manager = AuthManagerContext.useValue().processManager-- const [processes, setProcesses] = useState(() => [...manager.processes.values()])-- const programManager = manager.authManager.programManager-- const [programs, setPrograms] = useState(() => [...programManager.programs.values()])-- useLayoutEffect(() => manager.subscribeProcesses(setProcesses), [manager])-- useLayoutEffect(() => programManager.subscribePrograms(setPrograms), [programManager])-- const programsByIdentity = new Map(programs.map(program => [program.identity, program]))+/** Live Processes, including those without a Client window, as a table. */+export default function Processes({ processes, programs, empty }: Readonly<{+ processes: readonly Process[]+ programs: ReadonlyMap<string, Program>+ empty: string+}>) {const space = useScale(useAppearance().spacing)- const matching = processes.filter(process => matchesProcess(process.name, programsByIdentity.get(process.program), terms))-- return <Section label="Processes" count={matching.length} empty={terms.length ? "No matching Processes" : "No Processes"}>-- {/* A fixed layout keeps the table in its well: a long Process name is cut short instead of widening it. */}- {/* Without a heading, the first row has nothing above it to be set apart from; the lines between rows stay faint. */}- <Table aria-label="Processes" size="small" className="[&_tbody>tr:first-child>*]:!border-t-0 [&_tbody>tr>*]:![border-top-color:color-mix(in_oklab,currentColor_6%,transparent)]" style={{ minWidth: 0, tableLayout: "fixed" }}>+ if (!processes.length) return <Empty>{empty}</Empty>- {/* The columns stay for their widths and names, but the rows need no heading: each row says what it is. */}- <Table.Header style={{ visibility: "collapse" }}>- <Table.Column id="process" rowHeader>Process</Table.Column>- <Table.Column id="endpoints" style={{ width: space.xlarge * 5 }}>Running</Table.Column>- <Table.Column id="end" aria-label="End" style={{ width: space.xlarge * 2 }}> </Table.Column>- </Table.Header>+ // A fixed layout keeps the table within the content: a long Process name is cut short instead of widening it.+ return <Table aria-label="Processes" size="small" style={{ minWidth: 0, tableLayout: "fixed" }}>- <Table.Body>- {/* Endpoint state is passed as values: the Process handle is updated in place, so the row must see what changed. */}- {matching.map(process => <ProcessRow key={process.identity} process={process} program={programsByIdentity.get(process.program)}- server={process.server ? process.server.ready ? "ready" : "starting" : null} client={process.client !== null} />)}- </Table.Body>+ <Table.Header>+ <Table.Column id="process" rowHeader>Process</Table.Column>+ <Table.Column id="program" style={{ width: space.xlarge * 6 }}>Program</Table.Column>+ <Table.Column id="endpoints" style={{ width: space.xlarge * 5 }}>Endpoints</Table.Column>+ <Table.Column id="end" aria-label="End" style={{ width: space.xlarge * 2 }}> </Table.Column>+ </Table.Header>- </Table>+ <Table.Body>+ {/* Endpoint state is passed as values: the Process handle is updated in place, so the row must see what changed. */}+ {processes.map(process => <ProcessRow key={process.identity} process={process} program={programs.get(process.program)}+ server={process.server ? process.server.ready ? "ready" : "starting" : null} client={process.client !== null} />)}+ </Table.Body>- </Section>+ </Table>}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/programs/categories.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/programs/categories.tsxindex 0b3e2ee..2fd1590 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/programs/categories.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/programs/categories.tsx@@ -1,24 +1,20 @@import { Bot, Code, Globe, Layers, Settings2, SquareKanban, type LucideIcon } from "@phreshos/react-ui/icons"-import { Text, useAppearance, useScale } from "@phreshos/react-ui"import type Program from "@client/core/link-manager/auth-manager/program-manager/program"-/**- * Groups Programs by their first category, so each appears once, in the order- * the categories first appear. A Program without a category is under "Other",- * as in the first-run Program's catalog.- */-export function categorized(programs: readonly Program[]) {+/** The category a Program is listed under: its first, or "Other" without one, as in the first-run Program's catalog. */+export function categoryOf(program: Pick<Program, "categories">) {- const grouped = new Map<string, Program[]>()+ return program.categories[0] ?? "Other"+}- for (const program of programs) {+/** Each category with how many Programs it holds, in the order the categories first appear. */+export function categories(programs: readonly Pick<Program, "categories">[]) {- const category = program.categories[0] ?? "Other"+ const counted = new Map<string, number>()- grouped.set(category, [...grouped.get(category) ?? [], program])- }+ for (const program of programs) counted.set(categoryOf(program), (counted.get(categoryOf(program)) ?? 0) + 1)- return [...grouped].map(([category, members]) => ({ category, members }))+ return [...counted].map(([category, count]) => ({ category, count }))}/** An icon for each category a Program may declare; any other category takes a general one. */@@ -30,16 +26,7 @@ const categoryIcons: Readonly<Record<string, LucideIcon>> = {AI: Bot}-/** A category's heading across the whole grid: its icon and its name. */-export function CategoryHeading({ category }: Readonly<{ category: string }>) {-- const space = useScale(useAppearance().spacing)-- const Icon = categoryIcons[category] ?? Layers-- return <Text tone="secondary" size="small" className="flex items-center" style={{ gridColumn: "1 / -1", gap: space.small, paddingTop: space.small, fontWeight: 500 }}>-- <Icon aria-hidden />{category}+export function categoryIcon(category: string): LucideIcon {- </Text>+ return categoryIcons[category] ?? Layers}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/programs/launcher-item.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/programs/launcher-item.tsxdeleted file mode 100644index db5b667..0000000--- a/source/client/view/structure/desktop/layers/shell/start-menu/programs/launcher-item.tsx+++ /dev/null@@ -1,41 +0,0 @@-import { Button, Text, useAppearance, useScale, type ButtonActionProps } from "@phreshos/react-ui"-import { type ReactNode } from "react"--/**- * One Program in the Start Menu's grid: a small card on the Programs well,- * flat in a light tint of the secondary color, like the catalog cards of the first-run Program,- * its icon above its name in small text, cut short when it is long. The- * description is its tooltip.- */-export default function LauncherItem({ icon, description, children, ...props }: LauncherItemProps) {-- const space = useScale(useAppearance().spacing)-- // The cell carries the description as its tooltip; the card fills it.- return <div className="grid min-w-0" title={description ?? undefined}><Button-- {...props}-- depth="flat"-- color="secondary:subtle"-- style={{ display: "grid", justifyItems: "center", alignContent: "start", rowGap: space.small, width: "100%", height: "auto", minWidth: 0, paddingBlock: space.medium, paddingInline: space.small }}-- >-- <img src={icon} alt="" draggable={false} style={{ width: space.xlarge, height: space.xlarge }} className="object-contain" />-- <Text size="small" className="w-full truncate text-center">{children}</Text>-- </Button></div>-}--export interface LauncherItemProps extends Omit<ButtonActionProps, "children" | "color" | "style"> {-- icon: string-- description?: string | null-- children: ReactNode-}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsxindex e8c9c8a..f99f372 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsx@@ -1,99 +1,102 @@-import LauncherItem from "./launcher-item"import programIcon from "@client/view/structure/desktop/programs/program-icon"-import usePrograms from "@client/view/structure/desktop/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"-import { matchesProgram } from "../search"+import type Program from "@client/core/link-manager/auth-manager/program-manager/program"import { useLaunchPlacement } from "@client/view/structure/desktop/launch-placement"-import Section from "../section"-import { categorized, CategoryHeading } from "./categories"-import { Fragment, useRef } from "react"+import { Badge, GridList, Table, Text, useAppearance, useScale } from "@phreshos/react-ui"+import { useRef } from "react"+import Empty from "../empty"++export type ProgramsLayout = "grid" | "list"++/** The Programs the Start Menu shows, as icons or as a table, each opened by a press. */+export default function Programs({ programs, layout, running, empty, onLaunch }: Readonly<{+ programs: readonly Program[]+ layout: ProgramsLayout+ /** How many live Processes each Program has, by its identity. */+ running: ReadonlyMap<string, number>+ empty: string+ onLaunch: (program: Program) => void+}>) {-interface ProgramsProps {+ const application = ApplicationContext.useValue()- onChoose: () => void+ const space = useScale(useAppearance().spacing)- terms: readonly string[]-}+ if (!programs.length) return <Empty>{empty}</Empty>-/** The installed-program section of the Start Menu, grouped by category. */-export default function Programs({ onChoose, terms }: ProgramsProps) {+ const byIdentity = new Map(programs.map(program => [program.identity, program]))- const application = ApplicationContext.useValue()+ const launch = (identity: string) => { const program = byIdentity.get(identity); if (program) onLaunch(program) }++ const icon = (program: Program) => programIcon(application.doors.program, program.assetId)- const programs = usePrograms().filter(program => matchesProgram(program, terms))+ if (layout === "grid") return <GridList aria-label="Programs" selectionMode="none" itemWidth={space.xlarge * 3.5} style={{ alignContent: "start", outline: "none" }} onAction={key => launch(String(key))}>- return <Section label="Programs" columns={3} count={programs.length} empty={terms.length ? "No matching Programs" : "No installed programs"}>+ {programs.map(program => <GridList.Item key={program.identity} id={program.identity} textValue={program.name}>- {categorized(programs).map(({ category, members }) => <Fragment key={category}>+ {/* The description is the tooltip. */}+ <span className="grid min-w-0 justify-items-center text-center" title={program.description ?? undefined} style={{ gap: space.small, paddingBlock: space.small }}>- <CategoryHeading category={category} />+ <img src={icon(program)} alt="" draggable={false} className="object-contain" style={{ width: space.xlarge * 1.25, height: space.xlarge * 1.25 }} />- {members.map(record => <ProgramItem+ <Text size="small" className="w-full truncate">{program.name}</Text>- key={record.identity}+ </span>- icon={programIcon(application.doors.program, record.assetId)}+ </GridList.Item>)}- record={record}+ </GridList>- onChoose={onChoose}+ return <Table aria-label="Programs" size="small" onAction={launch} style={{ minWidth: 0, tableLayout: "fixed" }}>- />)}+ <Table.Header>+ <Table.Column id="name" rowHeader>Name</Table.Column>+ <Table.Column id="version" style={{ width: space.xlarge * 3 }}>Version</Table.Column>+ <Table.Column id="category" style={{ width: space.xlarge * 4.5 }}>Category</Table.Column>+ <Table.Column id="state" style={{ width: space.xlarge * 3.5 }}>State</Table.Column>+ </Table.Header>- </Fragment>)}+ <Table.Body>+ {programs.map(program => <Table.Row key={program.identity} id={program.identity} textValue={program.name}>+ <Table.Cell>+ <span className="flex min-w-0 items-center" title={program.description ?? undefined} style={{ gap: space.small }}>+ <img src={icon(program)} alt="" draggable={false} className="shrink-0 object-contain" style={{ width: space.medium * 1.5, height: space.medium * 1.5 }} />+ <span className="min-w-0 truncate">{program.name}</span>+ </span>+ </Table.Cell>+ <Table.Cell><Text tone="secondary" className="tabular-nums">{program.version}</Text></Table.Cell>+ <Table.Cell><Text tone="secondary">{program.categories[0] ?? "Other"}</Text></Table.Cell>+ <Table.Cell>{running.get(program.identity) ? <Badge size="xsmall" color="success" dot>{running.get(program.identity)} running</Badge> : null}</Table.Cell>+ </Table.Row>)}+ </Table.Body>- </Section>+ </Table>}-function ProgramItem({ icon, record, onChoose }: { icon: string, record: Program, onChoose: () => void }) {+/**+ * Opens a Program. A Program that declares where its Window goes keeps it; otherwise the Window opens+ * where this Desktop looks, with a square size of this Desktop's choosing when the Program declares none.+ */+export function useLaunch() {- // Read when the launch happens, not when this item first rendered: the view may have moved since.+ // Read when the launch happens, not when the menu first rendered: the view may have moved since.const currentPlacement = useLaunchPlacement()const placement = useRef(currentPlacement)placement.current = currentPlacement- // A Program that declares where its Window goes keeps it; otherwise the Window opens where this Desktop- // looks, with a square size of this Desktop's choosing when the Program declares none.- const launch = usePromise(async function () {+ return async function (program: Program) {- onChoose()+ const declared = program.client?.position ?? null- const declared = record.client?.position ?? null-- const size = record.client?.size ?? null+ const size = program.client?.size ?? nullconst placed = placement.current.place(size)// A Window that opens where its Program declares is brought into view.if (declared) placement.current.reveal(declared, placed.size ?? size)- await record.createProcess({ client: declared ? (placed.size ? { size: placed.size } : {}) : placed })- })-- return <>-- <LauncherItem-- icon={icon}-- description={record.description}-- pending={launch.isPending}-- onPress={() => void launch.safeExecute()}-- >-- {record.name}-- </LauncherItem>-- {launch.exception && <Alert className="text-sm">{String(launch.exception.current)}</Alert>}-- </>+ await program.createProcess({ client: declared ? (placed.size ? { size: placed.size } : {}) : placed })+ }}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/search-bar.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/search-bar.tsxdeleted file mode 100644index b36fa0e..0000000--- a/source/client/view/structure/desktop/layers/shell/start-menu/search-bar.tsx+++ /dev/null@@ -1,13 +0,0 @@-import { Input } from "@phreshos/react-ui"-import { wellMaterial } from "./start-menu-panel"--export default function SearchBar({ query, onChange }: Readonly<{ query: string, onChange: (query: string) => void }>) {-- return <Input- aria-label="Search Programs and Processes"- placeholder="Search Programs and Processes…"- material={wellMaterial}- value={query}- onChange={onChange}- />-}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/section.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/section.tsxdeleted file mode 100644index ceed393..0000000--- a/source/client/view/structure/desktop/layers/shell/start-menu/section.tsx+++ /dev/null@@ -1,32 +0,0 @@-import { type ReactNode } from "react"-import { ScrollArea, Text, useAppearance, useScale } from "@phreshos/react-ui"--/** One titled list of the Start Menu, scrolling on its own, or a quiet line when it is empty. */-export default function Section({ label, count, empty, columns = 1, children }: Readonly<{- label: string- count: number- empty: string- /** Items laid out in this many equal columns. */- columns?: number- children: ReactNode-}>) {-- const space = useScale(useAppearance().spacing)-- return <div role="group" aria-label={label} className="grid h-full min-h-0 grid-rows-[auto_minmax(0,1fr)]">-- <Text tone="secondary" size="small" style={{ paddingInline: space.medium, paddingTop: space.medium, paddingBottom: space.medium - space.xsmall, fontWeight: 500 }}>{label} · {count}</Text>-- {count === 0-- ? <Text tone="secondary" size="small" className="grid place-items-center text-center" style={{ padding: space.large }}>{empty}</Text>-- : <ScrollArea className="h-full min-h-0">-- {/* The smallest step above the items keeps their edge clear of the scroll area's top. */}- <div className="grid content-start" style={{ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`, gap: space.small, padding: space.medium, paddingTop: space.xsmall }}>{children}</div>-- </ScrollArea>}-- </div>-}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu-panel.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu-panel.tsxindex 0e2f0ed..7eadc6e 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu-panel.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu-panel.tsx@@ -1,53 +1,234 @@-import { type ReactNode } from "react"-import { Panel, Surface, useAppearance, useScale } from "@phreshos/react-ui"-import SystemHeader from "@client/view/components/system-header"+import { useLayoutEffect, useRef, useState, type ReactNode, type RefObject } from "react"+import { AppLayout, Button, Drawer, Panel, SearchField, SegmentedControl, Text, Tree, useAppearance, useColor, useScale } from "@phreshos/react-ui"+import { Activity, LayoutGrid, List, PanelLeft, Settings as SettingsIcon } from "@phreshos/react-ui/icons"+import logo from "@/assets/bundled/logo.png"+import { floatingShadow } from "@client/view/appearance/floating-shadow"+import usePrograms from "@client/view/structure/desktop/programs/programs"+import Programs, { useLaunch, type ProgramsLayout } from "./programs/programs"+import Processes from "./processes/processes"+import { categories, categoryIcon, categoryOf } from "./programs/categories"+import { matchesProcess, matchesProgram, searchTerms } from "./search"+import useLive from "./live"+import type Program from "@client/core/link-manager/auth-manager/program-manager/program"++type Show = "programs" | "processes"++/** Every category at once. Not "all", which a collection reads as every item chosen. */+const all = "every-category"/**- * The built-in Start Menu content shown by the default Shell: a frosted Panel- * whose header is the same row as a Window's, holding three wells recessed into- * it, the Programs, the Processes, and the search field below them. Every space- * is the Appearance spacing, the same as the header's side padding, so the wells- * line up with the header's content.+ * The built-in Start Menu content, laid out as a Program is: the System's name above a sidebar that+ * chooses between the Programs and the Processes and among the Programs' categories; beside it, the+ * search and the way the Programs are shown, the list recessed below them, and a status line under it.*/-export default function StartMenuPanel({ labelId, name, version, left, right, footer, stacked = false }: Readonly<{+export default function StartMenuPanel({ labelId, name, version, onChoose }: Readonly<{labelId: stringname: stringversion: string- left: ReactNode- right: ReactNode- footer: ReactNode- /** On a tall menu, the Programs sit above the Processes instead of beside them. */- stacked?: boolean+ /** Called when a Program is chosen, before it opens. */+ onChoose: () => void}>) {const space = useScale(useAppearance().spacing)- return <Panel style={{ height: "100%", maxHeight: "inherit" }}>+ const danger = useColor("danger").base++ const [show, setShow] = useState<Show>("programs")++ const [category, setCategory] = useState(all)++ const [layout, setLayout] = useState<ProgramsLayout>("grid")++ const [query, setQuery] = useState("")++ const [problem, setProblem] = useState<string | null>(null)++ const frame = useRef<HTMLDivElement>(null)++ const narrow = useNarrow(frame)++ const [drawer, setDrawer] = useState(false)++ const launch = useLaunch()++ const installed = usePrograms()++ const live = useLive()++ const terms = searchTerms(query)++ const inCategory = category === all ? installed : installed.filter(program => categoryOf(program) === category)++ const programs = inCategory.filter(program => matchesProgram(program, terms))++ const processes = live.processes.filter(process => matchesProcess(process.name, live.programs.get(process.program), terms))++ const running = new Map<string, number>()++ for (const process of live.processes) running.set(process.program, (running.get(process.program) ?? 0) + 1)++ const starting = processes.filter(process => process.server && !process.server.ready).length++ const status = problem ?? (show === "programs"+ ? [programs.length === installed.length ? count(installed.length, "Program") : `${programs.length} of ${count(installed.length, "Program")}`,+ programs.some(program => running.has(program.identity)) ? `${programs.filter(program => running.has(program.identity)).length} running` : null]+ : [count(processes.length, "Process"), starting ? `${starting} starting` : null]).filter(Boolean).join(" · ")++ function choose(next: Show, nextCategory = category) {++ setShow(next)++ setCategory(nextCategory)++ setProblem(null)++ setDrawer(false)+ }++ const identity = <>++ <img src={logo} alt="" draggable={false} className="shrink-0 rounded-sm object-contain" style={{ width: space.xlarge, height: space.xlarge }} />++ {/* The version sits on the name's baseline, below its middle. */}+ <span className="flex min-w-0 items-baseline" style={{ gap: space.small }}>++ <span className="truncate">{name}</span>++ {/* The same size as the status line, not a share of the name's. */}+ <Text tone="secondary" className="shrink-0 tabular-nums" aria-label={`System version ${version}`} style={{ fontSize: "0.75rem", fontWeight: 400 }}>v{version}</Text>++ </span>++ </>++ const navigation = <>++ <Heading first>Show</Heading>++ <Tree aria-label="Show" selectionMode="single" value={show} onChange={value => { if (value) choose(value as Show) }}>+ <Place id="programs" icon={<LayoutGrid />} label="Programs" count={installed.length} />+ <Place id="processes" icon={<Activity />} label="Processes" count={live.processes.length} />+ </Tree>- <Panel.Header><SystemHeader labelId={labelId} name={name} version={version} /></Panel.Header>+ <Heading>Categories</Heading>- <div className="grid min-h-0 min-w-0" style={{ gridTemplateRows: "minmax(0, 1fr) auto", gap: space.medium, padding: space.medium, paddingTop: 0 }}>+ {/* A category shows the Programs in it, so it is chosen only while the Programs are shown. */}+ <Tree aria-label="Categories" selectionMode="single" value={show === "programs" ? category : null} onChange={value => { if (value) choose("programs", value) }}>+ <Place id={all} icon={<LayoutGrid />} label="All" count={installed.length} />+ {categories(installed).map(({ category, count }) => {+ const Icon = categoryIcon(category)+ return <Place key={category} id={category} icon={<Icon />} label={category} count={count} />+ })}+ </Tree>- <div className={`grid min-h-0 min-w-0 ${stacked ? "grid-rows-2" : "grid-cols-2"}`} style={{ gap: space.medium }}>+ </>- <Well>{left}</Well>+ function open(program: Program) {- <Well>{right}</Well>+ onChoose()- </div>+ launch(program).catch(error => setProblem(error instanceof Error ? error.message : `${program.name} could not open.`))+ }- {footer}+ // The System's settings, at the foot of the sidebar as in Files, while the Settings Program is installed.+ const settings = installed.find(program => program.identity === "settings")- </div>+ const settingsEntry = settings ? <Button depth="none" size="small" onPress={() => open(settings)}><SettingsIcon />{settings.name}</Button> : null++ // As in Files, a narrow menu gives the sidebar up to the Programs and keeps it one press away, in a drawer.+ return <Panel ref={frame} shadow={floatingShadow} style={{ position: "relative", height: "100%", maxHeight: "inherit" }}>++ {/* The Appearance spacing all around the frame. */}+ <AppLayout sidebarWidth={narrow ? 0 : undefined} style={{ padding: space.medium, paddingTop: space.small, ...(narrow ? { columnGap: 0 } : {}) }}>++ {!narrow && <AppLayout.Title id={labelId} style={{ gap: space.small, paddingInline: space.small, fontSize: "1.25rem" }}>{identity}</AppLayout.Title>}++ {!narrow && <AppLayout.Sidebar aria-label="Start" footer={settingsEntry}>{navigation}</AppLayout.Sidebar>}++ <AppLayout.Header style={{ paddingInline: space.small, marginBottom: space.small }}>++ {narrow && <>+ <span id={labelId} className="sr-only">{name}</span>+ <Button iconOnly depth="flat" size="small" aria-label="Show and categories" aria-expanded={drawer} onPress={() => setDrawer(!drawer)}><PanelLeft /></Button>+ </>}++ <Text size="xlarge" className="min-w-0 flex-1 truncate" style={{ fontWeight: 600 }}>{show === "processes" ? "Processes" : category === all ? "All Programs" : category}</Text>++ <SearchField aria-label={show === "programs" ? "Search Programs" : "Search Processes"} placeholder="Search" size="small" value={query} onChange={setQuery} style={{ width: space.xlarge * 8 }} />++ {show === "programs" && <SegmentedControl aria-label="View" size="small" value={layout} onChange={value => setLayout(value as ProgramsLayout)}>+ <SegmentedControl.Item id="list" aria-label="List"><List /></SegmentedControl.Item>+ <SegmentedControl.Item id="grid" aria-label="Icons"><LayoutGrid /></SegmentedControl.Item>+ </SegmentedControl>}++ </AppLayout.Header>++ {/* A size container, so a quiet line can stand in its middle. */}+ <AppLayout.Content style={{ containerType: "size" }}>++ {show === "programs"+ ? <Programs programs={programs} layout={layout} running={running}+ empty={terms.length ? "No matching Programs" : category === all ? "No installed Programs" : `No Programs in ${category}`}+ onLaunch={open} />+ : <Processes processes={processes} programs={live.programs} empty={terms.length ? "No matching Processes" : "No Processes"} />}++ </AppLayout.Content>++ <AppLayout.Footer style={{ paddingInline: space.small, paddingTop: space.medium }}>++ <span role="status" className="min-w-0 truncate"><Text tone={problem ? undefined : "secondary"} size="small" className="tabular-nums" style={problem ? { color: danger } : undefined}>{status}</Text></span>++ </AppLayout.Footer>++ </AppLayout>++ {narrow && <Drawer open={drawer} onClose={() => setDrawer(false)} aria-label="Start"+ title={<span className="flex min-w-0 items-center" style={{ gap: space.small }}>{identity}</span>} style={{ display: "flex", flexDirection: "column" }}>+ {navigation}{settingsEntry && <div style={{ marginTop: "auto" }}>{settingsEntry}</div>}+ </Drawer>}</Panel>}-/** A list recessed into the menu, painted as the search field is. */-function Well({ children }: Readonly<{ children: ReactNode }>) {+/** One choice in the sidebar: its icon, its name, and how many it holds. */+function Place({ id, icon, label, count }: Readonly<{ id: string, icon: ReactNode, label: string, count: number }>) {- return <Surface depth="recessed" color="background" material={wellMaterial} className="min-h-0 min-w-0 overflow-hidden">{children}</Surface>+ return <Tree.Item id={id} textValue={label}>+ <Tree.Content>{icon}<span className="min-w-0 flex-1 truncate">{label}</span><Text tone="secondary" size="small" className="tabular-nums">{count}</Text></Tree.Content>+ </Tree.Item>}-/** The wells, the lists and the search field alike, take the Appearance material's opacity. */-export const wellMaterial = "extended"+/** A group's name in the sidebar. */+function Heading({ first = false, children }: Readonly<{ first?: boolean, children: ReactNode }>) {++ const space = useScale(useAppearance().spacing)++ return <Text tone="secondary" size="xsmall" className="block" style={{ paddingInline: space.small, marginTop: first ? space.xsmall : space.large, marginBottom: space.xsmall }}>{children}</Text>+}++function count(amount: number, noun: string) {++ return `${amount} ${noun}${amount === 1 ? "" : noun.endsWith("s") ? "es" : "s"}`+}++/** Narrow enough that the sidebar would crowd the Programs out: the width at which Files gives up its places. */+function useNarrow(frame: RefObject<HTMLElement | null>) {++ const [narrow, setNarrow] = useState(false)++ useLayoutEffect(function () {++ const element = frame.current++ if (!element) return++ const observer = new ResizeObserver(([entry]) => setNarrow((entry?.contentRect.width ?? Infinity) <= 640))++ observer.observe(element)++ return () => observer.disconnect()++ }, [frame])++ return narrow+}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsxindex 7acd5ed..0d7d989 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx@@ -1,11 +1,7 @@import PhreshOSIcon from "@client/view/components/phreshos-icon"import { createContext, memo, useCallback, useContext, useEffect, useId, useRef, useState, type CSSProperties, type PropsWithChildren, type RefObject } from "react"-import Programs from "./programs/programs"-import Processes from "./processes/processes"import StartMenuPanel from "./start-menu-panel"import { ApplicationContext } from "@client/view/contexts"-import SearchBar from "./search-bar"-import { searchTerms } from "./search"import { type AppearanceTaskbar } from "@phreshos/core"import { useReducedMotion } from "@libs/react-motion"import { motion } from "motion/react"@@ -118,12 +114,8 @@ export default memo(function StartMenu() {const transaction = useAppearance().transaction- const [query, setQuery] = useState("")-const portrait = usePortrait()- const terms = searchTerms(query)-return <motion.divref={control.surface}id={control.id}@@ -147,7 +139,8 @@ export default memo(function StartMenu() {if (event.newState !== "open") return- const focusTarget = event.currentTarget.querySelector<HTMLElement>("button:not(:disabled),a[href]") ?? event.currentTarget+ // The search comes first: a Program is usually one it names.+ const focusTarget = event.currentTarget.querySelector<HTMLElement>("input[type=search],button:not(:disabled),a[href]") ?? event.currentTargetfocusTarget.focus()}}@@ -157,10 +150,7 @@ export default memo(function StartMenu() {labelId={`${control.id}-label`}name={application.displayName}version={application.version}- left={<Programs onChoose={control.close} terms={terms} />}- right={<Processes terms={terms} />}- footer={<SearchBar query={query} onChange={setQuery} />}- stacked={portrait}+ onChoose={control.close}/></motion.div>diff --git a/tests/panel.test.tsx b/tests/panel.test.tsxindex 4bd44ed..cfd1519 100644--- a/tests/panel.test.tsx+++ b/tests/panel.test.tsx@@ -6,7 +6,6 @@ import { resolveRadius, UIProvider } from "@phreshos/react-ui"import CredentialsForm from "@client/view/structure/authentication/credentials-form"import ShellSurface, { shellSurfaceClassName } from "@client/view/structure/desktop/layers/shell/shell-surface"import Window from "@client/view/structure/desktop/windows/window"-import StartMenuPanel from "@client/view/structure/desktop/layers/shell/start-menu/start-menu-panel"import Taskbar from "@client/view/structure/desktop/layers/shell/taskbar/taskbar"import { ApplicationContext } from "@client/view/contexts"import Application from "@client/core/application"@@ -86,21 +85,6 @@ test("panel contract", async () => {assert.match(authenticationFailure, /role="alert"/)assert.match(authenticationFailure, /The request failed\./)- const launcher = markup(<StartMenuPanel labelId="start-menu-label" name="Example System" version="1.2.3" left={<button>Programs</button>} right={<p>Processes</p>} footer={<input type="search" aria-label="Search Programs and Processes" />} />)- assert.equal(launcher.match(/class="[^"]*phreshos-surface[^"]*"/g)?.length, 3)- assert.match(launcher, /grid-cols-2/)- // A Panel with its Window-height header; the wells sit the Appearance spacing apart, aligned with the header.- assert.match(launcher, /grid-template-rows:auto minmax\(0, 1fr\)/)- assert.match(launcher, /min-height:40px/)- assert.match(launcher, /grid-template-rows:minmax\(0, 1fr\) auto;gap:12px;padding:12px;padding-top:0/)- assert.match(launcher, /grid-cols-2" style="gap:12px"/)- assert.match(launcher, /<button>Programs<\/button>/)- assert.match(launcher, /<p>Processes<\/p>/)- assert.match(launcher, /<h2[^>]*>Example System<\/h2>/)- assert.match(launcher, /System version 1.2.3/)- assert.match(launcher, /type="search"/)- assert.doesNotMatch(launcher, /<(?:main|section|article|aside|nav|header|footer)\b/)- assert.match(launcher, /size-4 rounded-sm object-contain/)// Independent Shell overlays share a non-clipping host for outer effects.assert(shellSurfaceClassName.split(" ").includes("overflow-visible"))diff --git a/tests/start-menu-search.test.tsx b/tests/start-menu-search.test.tsxindex 45acc69..b77277d 100644--- a/tests/start-menu-search.test.tsx+++ b/tests/start-menu-search.test.tsx@@ -1,9 +1,6 @@import assert from "node:assert/strict"-import { renderToStaticMarkup } from "react-dom/server"-import { UIProvider } from "@phreshos/react-ui"-import { defaultAppearance } from "@phreshos/core"import Program from "@server/core/link-manager/auth-manager/program-manager/program"-import SearchBar from "@client/view/structure/desktop/layers/shell/start-menu/search-bar"+import { categories, categoryOf } from "@client/view/structure/desktop/layers/shell/start-menu/programs/categories"import { matchesProcess, matchesProgram, searchTerms } from "@client/view/structure/desktop/layers/shell/start-menu/search"import { test } from "vitest"@@ -38,13 +35,12 @@ test("start menu search contract", async () => {assert(!matchesProcess(null, undefined, searchTerms("notes")))assert(!matchesProcess("daily draft", program, searchTerms("missing")))- const footer = renderToStaticMarkup(<UIProvider appearance={defaultAppearance} preferences={{ theme: "light", animations: true }}><SearchBar query="notes" onChange={() => {}} /></UIProvider>)-- assert.match(footer, /<div class="react-aria-TextField"/)- assert.match(footer, /<input\b/)- assert.match(footer, /value="notes"/)- assert.match(footer, /aria-label="Search Programs and Processes"/)- assert.equal(footer.match(/class="[^"]*phreshos-surface[^"]*"/g)?.length, 1)- assert.doesNotMatch(footer, /<(?:main|section|article|aside|nav|header|footer)\b/)- assert.doesNotMatch(footer, /Signed in as/)+ // Each category holds its Programs once, in the order the categories first appear; none is "Other".+ const tool = new Program({ identity: "tool", categories: ["Development", "Productivity"], client: { location: "." } }).record()+ assert.equal(categoryOf(empty), "Other")+ assert.deepEqual(categories([program, tool, empty, program]), [+ { category: "Productivity", count: 2 },+ { category: "Development", count: 1 },+ { category: "Other", count: 1 }+ ])}, 120_000)