Skip to content

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

Add unified Start menu search and preserve Surface shadows

zohayrslileh59ff6947676c
diff --git a/scripts/contracts/panel.tsx b/scripts/contracts/panel.tsx
index c6f9010..ad997f0 100644
--- a/scripts/contracts/panel.tsx
+++ b/scripts/contracts/panel.tsx
@@ -4,7 +4,7 @@ import { renderToStaticMarkup } from "react-dom/server"
import { standardAppearance } from "@phreshos/core"
import { AppearanceProvider } from "@phreshos/react-ui"
import CredentialsForm from "@client/view/structure/authentication/credentials-form"
-import TaskbarSurface from "@client/view/structure/desktop/taskbar/taskbar-surface"
+import TaskbarSurface, { taskbarSurfaceClassName } 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"
@@ -46,16 +46,24 @@ assert.match(authentication, /name="username"/)
assert.match(authentication, /name="password"/)
assert.match(authentication, /type="submit"/)
-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>)
+const launcher = markup(<Launcher label="Example System" trigger="Open">{(_close, labelId) => <StartMenuPanel labelId={labelId} 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" />} />}</Launcher>)
assert.equal(launcher.match(/data-surface-material=""/g)?.length, 3)
assert.match(launcher, /grid-cols-2/)
+assert.match(launcher, /grid-template-rows:auto minmax\(0, 1fr\);min-height:0/)
+assert.match(launcher, /grid-template-rows:minmax\(0, 1fr\) auto;gap:6px;padding:6px;padding-top:0/)
+assert.match(launcher, /grid-cols-2" style="gap:inherit"/)
assert.match(launcher, /<button>Programs<\/button>/)
assert.match(launcher, /<p>Processes<\/p>/)
-assert.match(launcher, /<h2[^>]*>PhreshOS<\/h2>/)
+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/)
// Native popover visibility belongs to the outer host, not Panel's grid.
const popover = launcher.match(/<div[^>]*popover="auto"[^>]*>/)?.[0]
assert(popover)
+assert.match(popover, /overflow-visible/)
+// Popovers and native dialogs share a non-clipping host for Surface shadows.
+assert(taskbarSurfaceClassName.split(" ").includes("overflow-visible"))
assert.doesNotMatch(popover, /style=/)
assert.match(launcher, /popovertarget=/i)
diff --git a/scripts/contracts/start-menu-search.tsx b/scripts/contracts/start-menu-search.tsx
new file mode 100644
index 0000000..f474984
--- /dev/null
+++ b/scripts/contracts/start-menu-search.tsx
@@ -0,0 +1,53 @@
+import assert from "node:assert/strict"
+import { renderToStaticMarkup } from "react-dom/server"
+import { AppearanceProvider } from "@phreshos/react-ui"
+import { standardAppearance } from "@phreshos/core"
+import Program from "@server/core/link-manager/auth-manager/program-manager/program"
+import SearchBar from "@client/view/structure/desktop/taskbar/launcher/search-bar"
+import { matchesProcess, matchesProgram, searchTerms } from "@client/view/structure/desktop/taskbar/launcher/search"
+
+const program = new Program({
+ identity: "test-editor",
+ name: "Note Studio",
+ description: "Write and organize documents",
+ categories: ["Productivity"],
+ keywords: ["markdown", "notes"],
+ client: { location: "." }
+}).record()
+
+assert.deepEqual(program.categories, ["Productivity"])
+assert.deepEqual(program.keywords, ["markdown", "notes"])
+const empty = new Program({ identity: "empty", client: { location: "." } }).record()
+
+assert.deepEqual(empty.categories, [])
+assert.deepEqual(empty.keywords, [])
+assert.deepEqual(searchTerms(" NOTE\tstudio "), ["note", "studio"])
+
+for (const query of ["", " ", "NOTE", "productivity", "markdown", "documents", "studio productivity markdown"]) {
+ assert(matchesProgram(program, searchTerms(query)), query)
+}
+
+assert(!matchesProgram(program, searchTerms("missing")))
+assert(!matchesProgram(program, searchTerms("studio missing")))
+assert(matchesProcess("daily draft", undefined, searchTerms("DAILY draft")))
+assert(matchesProcess(null, program, searchTerms("markdown productivity")))
+assert(matchesProcess("daily draft", program, searchTerms("documents")))
+assert(matchesProcess(null, undefined, searchTerms("")))
+assert(!matchesProcess(null, undefined, searchTerms("notes")))
+assert(!matchesProcess("daily draft", program, searchTerms("missing")))
+
+const footer = renderToStaticMarkup(<AppearanceProvider appearance={standardAppearance} theme="light"><SearchBar query="notes" onChange={() => {}} username="test-owner" /></AppearanceProvider>)
+
+assert.match(footer, /type="search"/)
+assert.match(footer, /value="notes"/)
+assert.match(footer, /aria-label="Search Programs and Processes"/)
+assert.match(footer, /aria-label="Signed in as test-owner"/)
+assert.match(footer, /^<div\b/)
+assert.match(footer, /grid-cols-\[minmax\(0,1fr\)_auto\]/)
+assert.match(footer, /style="gap:inherit"/)
+assert.equal(footer.match(/data-surface-material=""/g)?.length, 2)
+assert.doesNotMatch(footer, /<(?:main|section|article|aside|nav|header|footer)\b/)
+const withoutUser = renderToStaticMarkup(<AppearanceProvider appearance={standardAppearance} theme="light"><SearchBar query="" onChange={() => {}} username={null} /></AppearanceProvider>)
+
+assert.doesNotMatch(withoutUser, /Signed in as/)
+assert.equal(withoutUser.match(/data-surface-material=""/g)?.length, 1)
diff --git a/source/client/core/link-manager/auth-manager/auth-manager.ts b/source/client/core/link-manager/auth-manager/auth-manager.ts
index fc82aa9..26ed83a 100644
--- a/source/client/core/link-manager/auth-manager/auth-manager.ts
+++ b/source/client/core/link-manager/auth-manager/auth-manager.ts
@@ -18,6 +18,8 @@ export default class AuthManager extends TheLink {
public readonly authorization: string
+ public readonly username: string | null
+
public readonly programManager: ProgramManager
public readonly processManager: ProcessManager
@@ -34,6 +36,8 @@ export default class AuthManager extends TheLink {
this.authorization = authorization
+ this.username = payload.username
+
this.connectTo(this.linkManager, "/auth")
this.programManager = new ProgramManager(this, payload.programManager)
diff --git a/source/client/core/link-manager/auth-manager/program-manager/program.ts b/source/client/core/link-manager/auth-manager/program-manager/program.ts
index c796795..0a0b239 100644
--- a/source/client/core/link-manager/auth-manager/program-manager/program.ts
+++ b/source/client/core/link-manager/auth-manager/program-manager/program.ts
@@ -29,6 +29,10 @@ export default class Program {
public readonly description: string | null
+ public readonly categories: readonly string[]
+
+ public readonly keywords: readonly string[]
+
public readonly hasAgent: boolean
public readonly server: ProgramRecord["server"]
@@ -53,6 +57,10 @@ export default class Program {
this.description = payload.description
+ this.categories = payload.categories
+
+ this.keywords = payload.keywords
+
this.hasAgent = payload.hasAgent
this.server = payload.server
diff --git a/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsx b/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsx
index f738cd1..d488a53 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsx
@@ -1,9 +1,10 @@
import { ReactTunnel } from "@the-link/react"
import { AuthManagerContext } from "@client/view/contexts"
import ProcessItem from "./process-item"
+import { matchesProcess } from "../search"
/** All live Processes, including those without a Client window. */
-export default function Processes() {
+export default function Processes({ terms }: Readonly<{ terms: readonly string[] }>) {
const manager = AuthManagerContext.useValue().processManager
@@ -19,15 +20,17 @@ export default function Processes() {
const programsByIdentity = new Map(programs.map(program => [program.identity, program]))
+ const matching = processes.filter(process => matchesProcess(process.name, programsByIdentity.get(process.program), terms))
+
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>
+ <h3 className="px-3 py-2 text-xs font-medium opacity-60">Processes · {matching.length}</h3>
- {processes.length ? <ul className="m-0 min-h-0 list-none overflow-y-auto p-0">
+ {matching.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)} />)}
+ {matching.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>}
+ </ul> : <p className="m-0 grid min-h-32 place-items-center px-3 py-8 text-center text-sm opacity-50">{terms.length ? "No matching Processes" : "No Processes"}</p>}
</div>
}
diff --git a/source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsx b/source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsx
index 338ce14..c40d91c 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsx
@@ -5,18 +5,21 @@ 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"
interface ProgramsProps {
onChoose: () => void
+
+ terms: readonly string[]
}
/** The installed-program section of the Start Menu. */
-export default function Programs({ onChoose }: ProgramsProps) {
+export default function Programs({ onChoose, terms }: ProgramsProps) {
const application = ApplicationContext.useValue()
- const programs = usePrograms()
+ const programs = usePrograms().filter(program => matchesProgram(program, terms))
return <div role="group" aria-label="Programs" className="grid min-h-0 max-h-full gap-1 overflow-y-auto p-2">
@@ -36,7 +39,7 @@ export default function Programs({ onChoose }: ProgramsProps) {
/>)
- : <p className="px-3 py-8 text-center text-sm opacity-60">No installed programs</p>}
+ : <p className="px-3 py-8 text-center text-sm opacity-60">{terms.length ? "No matching Programs" : "No installed programs"}</p>}
</div>
}
diff --git a/source/client/view/structure/desktop/taskbar/launcher/search-bar.tsx b/source/client/view/structure/desktop/taskbar/launcher/search-bar.tsx
new file mode 100644
index 0000000..2e4f6ba
--- /dev/null
+++ b/source/client/view/structure/desktop/taskbar/launcher/search-bar.tsx
@@ -0,0 +1,36 @@
+import { Surface } from "@phreshos/react-ui"
+
+export default function SearchBar({ query, onChange, username }: Readonly<{ query: string, onChange: (query: string) => void, username: string | null }>) {
+
+ return <div className="grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center" style={{ gap: "inherit" }}>
+
+ <Surface className="min-w-0 focus-within:outline focus-within:outline-1 focus-within:outline-current">
+
+ <input
+
+ type="search"
+
+ aria-label="Search Programs and Processes"
+
+ placeholder="Search Programs and Processes…"
+
+ value={query}
+
+ onChange={event => onChange(event.currentTarget.value)}
+
+ className="h-9 w-full min-w-0 border-0 bg-transparent px-3 text-sm outline-none placeholder:text-current placeholder:opacity-50"
+
+ />
+
+ </Surface>
+
+ {username !== null && <Surface className="flex h-9 min-w-0 items-center gap-2 px-2 text-xs" title={username} aria-label={`Signed in as ${username}`}>
+
+ <span aria-hidden="true" className="grid size-7 shrink-0 place-items-center rounded-full border border-current/15 font-medium">{[...username][0]?.toUpperCase()}</span>
+
+ <span className="truncate">{username}</span>
+
+ </Surface>}
+
+ </div>
+}
diff --git a/source/client/view/structure/desktop/taskbar/launcher/search.ts b/source/client/view/structure/desktop/taskbar/launcher/search.ts
new file mode 100644
index 0000000..6d99845
--- /dev/null
+++ b/source/client/view/structure/desktop/taskbar/launcher/search.ts
@@ -0,0 +1,23 @@
+import type Program from "@client/core/link-manager/auth-manager/program-manager/program"
+
+export function searchTerms(query: string) {
+
+ return query.trim().toLowerCase().split(/\s+/u).filter(Boolean)
+}
+
+export function matchesProgram(program: Pick<Program, "name" | "description" | "categories" | "keywords"> | undefined, terms: readonly string[]) {
+
+ return terms.length === 0 || Boolean(program && matches(terms, [program.name, program.description, ...program.categories, ...program.keywords]))
+}
+
+export function matchesProcess(name: string | null, program: Parameters<typeof matchesProgram>[0], terms: readonly string[]) {
+
+ return matches(terms, [name]) || matchesProgram(program, terms)
+}
+
+function matches(terms: readonly string[], fields: readonly (string | null)[]) {
+
+ const text = fields.filter(value => value !== null).join("\n").toLowerCase()
+
+ return terms.every(term => text.includes(term))
+}
diff --git a/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsx b/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsx
index 71b7dc1..3efa296 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/start-menu-panel.tsx
@@ -3,29 +3,35 @@ import { Surface, useAppearance, useResolveTheme, useScale } from "@phreshos/rea
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 }>) {
+export default function StartMenuPanel({ labelId, name, version, left, right, footer }: Readonly<{ labelId: string, name: string, version: string, left: ReactNode, right: ReactNode, footer: 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" }}>
+ return <Surface style={{ display: "grid", gridTemplateRows: "auto minmax(0, 1fr)", minHeight: 0, height: "100%", 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">
+ <div 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>
+ <h2 id={labelId} className="m-0 truncate text-window-title font-medium">{name}</h2>
<span className="text-xs tabular-nums opacity-60" aria-label={`System version ${version}`}>v{version}</span>
- </header>
+ </div>
+
+ <div className="grid min-h-0 min-w-0" style={{ gridTemplateRows: "minmax(0, 1fr) auto", gap: spacing, padding: spacing, paddingTop: 0 }}>
+
+ <div className="grid min-h-0 min-w-0 grid-cols-2" style={{ gap: "inherit" }}>
+
+ <Surface className="min-h-0 min-w-0 overflow-hidden">{left}</Surface>
- <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">{right}</Surface>
- <Surface className="min-h-0 min-w-0 overflow-hidden">{left}</Surface>
+ </div>
- <Surface className="min-h-0 min-w-0 overflow-hidden">{right}</Surface>
+ {footer}
</div>
diff --git a/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx b/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx
index 82a44f7..ddfa170 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx
@@ -1,37 +1,47 @@
import logo from "@/assets/bundled/logo.png"
-import { memo } from "react"
+import { memo, useState } from "react"
import Launcher from "./launcher"
import Programs from "./programs/programs"
import Processes from "./processes/processes"
import StartMenuPanel from "./start-menu-panel"
-import { ApplicationContext } from "@client/view/contexts"
+import { ApplicationContext, AuthManagerContext } from "@client/view/contexts"
+import SearchBar from "./search-bar"
+import { searchTerms } from "./search"
/** The taskbar entry point for current and future desktop actions. */
export default memo(function StartMenu() {
const application = ApplicationContext.useValue()
+ const { username } = AuthManagerContext.useValue()
+
+ const [query, setQuery] = useState("")
+
+ const terms = searchTerms(query)
+
return <Launcher
- label="PhreshOS"
+ label={application.displayName}
trigger={<>
<img src={logo} alt="" className="size-5 shrink-0" />
- <span className="hidden text-xs font-semibold sm:inline">PhreshOS</span>
+ <span className="hidden text-xs font-semibold sm:inline">{application.displayName}</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(44rem,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)] 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, labelId) => <StartMenuPanel
labelId={labelId}
+ name={application.displayName}
version={application.version}
- left={<Programs onChoose={close} />}
- right={<Processes />}
+ left={<Programs onChoose={close} terms={terms} />}
+ right={<Processes terms={terms} />}
+ footer={<SearchBar query={query} onChange={setQuery} username={username} />}
/>}
</Launcher>
diff --git a/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx b/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx
index e9c0c00..6a1e273 100644
--- a/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx
+++ b/source/client/view/structure/desktop/taskbar/taskbar-surface.tsx
@@ -2,7 +2,7 @@ import { forwardRef, ReactNode } from "react"
import { Panel, type PanelProps } from "@phreshos/react-ui"
/** The window-material shell shared by surfaces opened from the taskbar. */
-export const taskbarSurfaceClassName = "m-0 isolate border-0 bg-transparent p-0 outline-none"
+export const taskbarSurfaceClassName = "m-0 isolate overflow-visible border-0 bg-transparent p-0 outline-none"
export default forwardRef<HTMLDivElement, TaskbarSurfaceProps>(function TaskbarSurface({ label, labelId, contentClassName = "", className, children, ...props }, ref) {
diff --git a/source/server/core/authentication/authentication.ts b/source/server/core/authentication/authentication.ts
index 6218360..fc20248 100644
--- a/source/server/core/authentication/authentication.ts
+++ b/source/server/core/authentication/authentication.ts
@@ -66,6 +66,11 @@ export default class Authentication {
}
}
+ public get username(): string | null {
+
+ return this.owner?.username ?? null
+ }
+
public state(): AuthenticationState {
return {
diff --git a/source/server/core/link-manager/auth-manager/auth-manager.ts b/source/server/core/link-manager/auth-manager/auth-manager.ts
index 0e13203..31c08d3 100644
--- a/source/server/core/link-manager/auth-manager/auth-manager.ts
+++ b/source/server/core/link-manager/auth-manager/auth-manager.ts
@@ -233,6 +233,8 @@ export default class AuthManager extends TheLink {
return {
+ username: this.linkManager.application.authentication.username,
+
programManager: this.programManager,
processManager: this.processManager,
@@ -244,6 +246,8 @@ export default class AuthManager extends TheLink {
export interface AuthManagerSnapshot {
+ username: string | null
+
programManager: ReturnType<ProgramManager["toJSON"]>
processManager: import("./process-manager/process-manager").ProcessManagerSnapshot
diff --git a/source/server/core/link-manager/auth-manager/program-manager/program.ts b/source/server/core/link-manager/auth-manager/program-manager/program.ts
index 0d2d82c..e392c57 100644
--- a/source/server/core/link-manager/auth-manager/program-manager/program.ts
+++ b/source/server/core/link-manager/auth-manager/program-manager/program.ts
@@ -209,6 +209,10 @@ export default class Program {
description: description ?? null,
+ categories: this.config.categories ?? [],
+
+ keywords: this.config.keywords ?? [],
+
hasAgent: this.agentPath !== null,
server: server && {