An open-source, self-hosted system for apps built with web technologies.
A pinned Program stands on the Taskbar with or without a Client; the Start Menu offers Open and Pin too
zohayrslileh3fa0aeb01a3f
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsxindex 7160e4a..cfc200e 100644--- a/source/client/view/structure/desktop/desktop.tsx+++ b/source/client/view/structure/desktop/desktop.tsx@@ -506,8 +506,8 @@ export default function Workspace() {}, [windows.presentation, windows.bringForward, focus.minimize])- // Programs kept on the Taskbar, closed or open, in the order they are listed.- const pinnedPrograms = programs.filter(program => program.pinned && program.client)+ // Programs kept on the Taskbar, closed or open, in the order they are listed, with or without a Window.+ const pinnedPrograms = programs.filter(program => program.pinned)const pinnedIdentities = new Set(pinnedPrograms.map(program => program.identity))diff --git a/source/client/view/structure/desktop/layers/shell/program-menu.tsx b/source/client/view/structure/desktop/layers/shell/program-menu.tsxnew file mode 100644index 0000000..cb78c36--- /dev/null+++ b/source/client/view/structure/desktop/layers/shell/program-menu.tsx@@ -0,0 +1,23 @@+import type Program from "@client/core/link-manager/auth-manager/program-manager/program"+import { Menu } from "@phreshos/react-ui"+import { AppWindow, Pin, PinOff } from "@phreshos/react-ui/icons"++/**+ * What can be done to one Program where the Desktop offers it: the Start Menu and its place on the+ * Taskbar. Open starts it as choosing it does; Pin keeps its place on the Taskbar, closed or open.+ */+export default function ProgramMenu({ program, onOpen }: Readonly<{ program: Program, onOpen: () => void }>) {++ return <Menu aria-label={`${program.name} actions`} size="small" onAction={action => {+ if (action === "open") onOpen()+ else if (action === "pin") void program.pin(!program.pinned).catch(() => undefined)+ }}>++ <Menu.Item id="open" textValue="Open"><AppWindow aria-hidden />Open</Menu.Item>++ <Menu.Separator />++ <Menu.Item id="pin" textValue={program.pinned ? "Unpin" : "Pin"}>{program.pinned ? <><PinOff aria-hidden />Unpin</> : <><Pin aria-hidden />Pin</>}</Menu.Item>++ </Menu>+}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 5e763b1..c27df61 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@@ -2,9 +2,11 @@ import programIcon from "@client/view/structure/desktop/programs/program-icon"import { ApplicationContext } from "@client/view/contexts"import type Program from "@client/core/link-manager/auth-manager/program-manager/program"import { useLaunchPlacement } from "@client/view/structure/desktop/launch-placement"-import { Badge, GridList, Table, Text, useAppearance, useScale, ScrollArea } from "@phreshos/react-ui"-import { useRef } from "react"+import { Badge, ContextMenu, GridList, Table, Text, useAppearance, useScale, ScrollArea } from "@phreshos/react-ui"+import { useRef, useState, type ReactElement } from "react"import Empty from "../empty"+import ProgramMenu from "../../program-menu"+import { useDesktopScaleContainer } from "@client/view/structure/desktop/desktop-scale"export type ProgramsLayout = "grid" | "list"@@ -22,6 +24,11 @@ export default function Programs({ programs, layout, running, empty, onLaunch }:const space = useScale(useAppearance().spacing)+ const scaleContainer = useDesktopScaleContainer()++ // The Program a press for the menu landed on, found under the pointer as the menu opens.+ const [menuFor, setMenuFor] = useState<Program | null>(null)+if (!programs.length) return <Empty>{empty}</Empty>const byIdentity = new Map(programs.map(program => [program.identity, program]))@@ -30,7 +37,20 @@ export default function Programs({ programs, layout, running, empty, onLaunch }:const icon = (program: Program) => programIcon(application.doors.program, program.assetId)- 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))}>+ // One menu for the whole list, as Files has: it acts on the Program it was opened on.+ const withMenu = (list: ReactElement) => <ContextMenu>+ <ContextMenu.Trigger>+ <div style={{ display: "contents" }} onContextMenuCapture={event => {+ const key = event.target instanceof Element ? event.target.closest("[data-key]")?.getAttribute("data-key") : null+ setMenuFor(key ? byIdentity.get(key) ?? null : null)+ }}>{list}</div>+ </ContextMenu.Trigger>+ <ContextMenu.Content portalContainer={scaleContainer ?? undefined}>+ {menuFor && <ProgramMenu program={menuFor} onOpen={() => onLaunch(menuFor)} />}+ </ContextMenu.Content>+ </ContextMenu>++ if (layout === "grid") return withMenu(<GridList aria-label="Programs" selectionMode="none" itemWidth={space.xlarge * 3.5} style={{ alignContent: "start", outline: "none" }} onAction={key => launch(String(key))}>{programs.map(program => <GridList.Item key={program.identity} id={program.identity} textValue={program.name}>@@ -45,9 +65,9 @@ export default function Programs({ programs, layout, running, empty, onLaunch }:</GridList.Item>)}- </GridList>+ </GridList>)- return <ScrollArea axis="horizontal"><Table aria-label="Programs" size="small" onAction={launch}>+ return withMenu(<ScrollArea axis="horizontal"><Table aria-label="Programs" size="small" onAction={launch}><Table.Header><Table.Column id="name" rowHeader minWidth={space.xlarge * 3}>Name</Table.Column>@@ -70,7 +90,7 @@ export default function Programs({ programs, layout, running, empty, onLaunch }:</Table.Row>)}</Table.Body>- </Table></ScrollArea>+ </Table></ScrollArea>)}/**@@ -88,9 +108,12 @@ export function useLaunch() {return async function (program: Program) {- const declared = program.client?.position ?? null+ // A Program without a Client opens as it declares: there is no Window to place.+ if (!program.client) return void await program.createProcess()++ const declared = program.client.position ?? null- const size = program.client?.size ?? null+ const size = program.client.size ?? nullconst placed = placement.current.place(size)diff --git a/source/client/view/structure/desktop/layers/shell/taskbar/programs/pinned-taskbar-item.tsx b/source/client/view/structure/desktop/layers/shell/taskbar/programs/pinned-taskbar-item.tsxindex 57d892c..41985b5 100644--- a/source/client/view/structure/desktop/layers/shell/taskbar/programs/pinned-taskbar-item.tsx+++ b/source/client/view/structure/desktop/layers/shell/taskbar/programs/pinned-taskbar-item.tsx@@ -1,7 +1,7 @@import Program from "@client/core/link-manager/auth-manager/program-manager/program"import { type TaskbarPosition } from "@phreshos/core"-import { ContextMenu, Menu } from "@phreshos/react-ui"-import { Plus, PinOff } from "@phreshos/react-ui/icons"+import { ContextMenu } from "@phreshos/react-ui"+import ProgramMenu from "../../program-menu"import { useDesktopScaleContainer } from "../../../../desktop-scale"import { useLaunch } from "../../start-menu/programs/programs"import TaskbarTooltip from "../taskbar-tooltip"@@ -10,7 +10,7 @@ import TaskbarItem from "./taskbar-item"/*** A Program pinned to the Taskbar: its place, kept whether it is closed or open, with its open* Windows right after it. It shows its icon alone; pressed, it opens the Program, as the Start Menu- * does. Only a Program with a Client stands here: one without has nothing to show.+ * does, with or without a Window to show.*/export default function PinnedTaskbarItem({ program, icon, position }: Readonly<{ program: Program, icon: string, position: TaskbarPosition }>) {@@ -30,14 +30,7 @@ export default function PinnedTaskbarItem({ program, icon, position }: Readonly<<ContextMenu.Content portalContainer={scaleContainer ?? undefined}>- <Menu aria-label={`${program.name} on the Taskbar`} size="small" onAction={action => {- if (action === "open") open()- else if (action === "unpin") void program.pin(false).catch(() => undefined)- }}>- <Menu.Item id="open" textValue="Open"><Plus aria-hidden />Open</Menu.Item>- <Menu.Separator />- <Menu.Item id="unpin" textValue="Unpin"><PinOff aria-hidden />Unpin</Menu.Item>- </Menu>+ <ProgramMenu program={program} onOpen={open} /></ContextMenu.Content>