An open-source, self-hosted system for apps built with web technologies.
A pinned Program keeps its place on the Taskbar, its open Windows right after it; on a narrow Desktop the Taskbar shows icons alone
zohayrslileha1df4382f69d
diff --git a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/client/core/link-manager/auth-manager/program-manager/program-manager.tsindex b00aa40..be52634 100644--- a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts+++ b/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts@@ -223,7 +223,10 @@ export default class ProgramManager extends TheLink {if (!payload || typeof pinned !== "boolean") returnconst program = this.programs.get(payload.identity)if (!program || program.reference !== payload.reference) return+ program.pinned = pinnedawait this.$inbound.publish("/pinned", program, pinned)+ // The Taskbar follows the list; a pin changes where a Program stands in it.+ await this.$inbound.publish("/programs", this.list())}@Subscribe("/command-output")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.tsindex c047ffd..52b70c1 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@@ -52,6 +52,9 @@ export default class Program {/** Whether it starts with the System. */public startup: boolean+ /** Whether it keeps its place on the Taskbar, closed or open. */+ public pinned: boolean+public constructor(programManager: ProgramManager, payload: ProgramRecord) {this.programManager = programManager@@ -89,6 +92,8 @@ export default class Program {this.opens = payload.opensthis.startup = payload.startup++ this.pinned = payload.pinned}public updatePermissions(permissions: unknown) {@@ -106,6 +111,12 @@ export default class Program {await this.createProcess()}+ /** Keeps its place on the Taskbar, or gives it up. */+ public async pin(pinned: boolean) {++ await this.programManager.pinned(this.address, pinned ? "pin" : "unpin")+ }+public install(options: ProgramInstallOptions = {}, asker = "") {return this.programManager.command(this.address, "install", options, asker)diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsxindex 2db710d..7160e4a 100644--- a/source/client/view/structure/desktop/desktop.tsx+++ b/source/client/view/structure/desktop/desktop.tsx@@ -12,12 +12,14 @@ import ProgramAccessProbe, { type ProgramAccess } from "../../components/programimport DefaultShell from "./layers/shell/default-shell"import OverflowRow from "./layers/shell/taskbar/programs/overflow-row"import WindowTaskbarItem from "./layers/shell/taskbar/programs/window-taskbar-item"+import PinnedTaskbarItem from "./layers/shell/taskbar/programs/pinned-taskbar-item"+import usePrograms from "./programs/programs"import ProcessWindow from "./windows/process-window"import useWindows from "../../components/window-manager/window-manager"import { ReadyWallpaper, WallpaperBackground } from "./layers/wallpaper/wallpaper"import Loading from "../../components/loading"import { useRequirement } from "@libs/readiness"-import { usePreferences, useThemedValue } from "@phreshos/react-ui"+import { narrowAppLayoutWidth, usePreferences, useThemedValue } from "@phreshos/react-ui"import { useProperty } from "@the-link/react"import SharedResizeBoundaries from "./windows/shared-resize-boundaries"import { programsRequirement } from "../readiness-requirements"@@ -43,6 +45,8 @@ export default function Workspace() {const windows = useWindows(authManager)+ const programs = usePrograms()+const completePrograms = useRequirement(programsRequirement)const initialPrograms = useRef<ReadonlySet<string> | null>(null)@@ -502,18 +506,23 @@ export default function Workspace() {}, [windows.presentation, windows.bringForward, focus.minimize])- const taskbarItems = <OverflowRow- orientation={taskbarOrientation}- className="h-full w-full"- aria-label="Open windows"- backwardLabel="Earlier windows"- forwardLabel="Later windows"- >+ // Programs kept on the Taskbar, closed or open, in the order they are listed.+ const pinnedPrograms = programs.filter(program => program.pinned && program.client)- {/* What a press means is composed here because it is a person's- expectation, not a system operation: the front window hides;- pressing another takes you to its view and brings it forward. */}- {windows.listed.map(record => {+ const pinnedIdentities = new Set(pinnedPrograms.map(program => program.identity))++ const togglePinned = useCallback(function (record: Process) {++ const program = programs.find(entry => entry.identity === record.program)++ if (program) void program.pin(!program.pinned).catch(() => undefined)++ }, [programs])++ // On a narrow Desktop, where Programs give up their sidebars, a Taskbar along the screen shows icons alone.+ const labeled = viewSize.width > narrowAppLayoutWidth++ function windowItem(record: Process) {const window = windows.presentation.projection(record.identity)@@ -529,12 +538,18 @@ export default function Workspace() {position={appearance.taskbar.position}+ labeled={labeled}+active={focusedWindow === record.identity}minimized={window.minimized}maximized={window.maximized}+ pinned={pinnedIdentities.has(record.program)}++ onTogglePinned={togglePinned}+onElement={focus.taskbarItem}onMinimize={focus.minimize}@@ -550,7 +565,27 @@ export default function Workspace() {onClose={focus.close}/>- })}+ }++ const taskbarItems = <OverflowRow+ orientation={taskbarOrientation}+ className="h-full w-full"+ aria-label="Open windows"+ backwardLabel="Earlier windows"+ forwardLabel="Later windows"+ >++ {/* What a press means is composed here because it is a person's+ expectation, not a system operation: the front window hides;+ pressing another takes you to its view and brings it forward.+ A pinned Program keeps its place, its open Windows right after it;+ the Windows of other Programs follow, as they opened. */}+ {pinnedPrograms.flatMap(program => [+ <PinnedTaskbarItem key={`pinned:${program.identity}`} program={program} icon={icon({ program: program.identity })} position={appearance.taskbar.position} />,+ ...windows.listed.filter(record => record.program === program.identity).map(windowItem)+ ])}++ {windows.listed.filter(record => !pinnedIdentities.has(record.program)).map(windowItem)}</OverflowRow>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 7663a77..cdf6907 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@@ -208,5 +208,3 @@ 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. */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.tsxnew file mode 100644index 0000000..4284144--- /dev/null+++ b/source/client/view/structure/desktop/layers/shell/taskbar/programs/pinned-taskbar-item.tsx@@ -0,0 +1,44 @@+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 { useDesktopScaleContainer } from "../../../../desktop-scale"+import { useLaunch } from "../../start-menu/programs/programs"+import TaskbarTooltip from "../taskbar-tooltip"+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 a new Window of the Program.+ */+export default function PinnedTaskbarItem({ program, icon, position }: Readonly<{ program: Program, icon: string, position: TaskbarPosition }>) {++ const scaleContainer = useDesktopScaleContainer()++ const launch = useLaunch()++ const open = () => void launch(program).catch(() => undefined)++ return <TaskbarTooltip label={program.name}><ContextMenu>++ <ContextMenu.Trigger>++ <TaskbarItem icon={icon} position={position} labeled={false} onPress={open}>{program.name}</TaskbarItem>++ </ContextMenu.Trigger>++ <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="New window"><Plus aria-hidden />New window</Menu.Item>+ <Menu.Separator />+ <Menu.Item id="unpin" textValue="Unpin from Taskbar"><PinOff aria-hidden />Unpin from Taskbar</Menu.Item>+ </Menu>++ </ContextMenu.Content>++ </ContextMenu></TaskbarTooltip>+}diff --git a/source/client/view/structure/desktop/layers/shell/taskbar/programs/taskbar-item.tsx b/source/client/view/structure/desktop/layers/shell/taskbar/programs/taskbar-item.tsxindex c465d35..0eb91b0 100644--- a/source/client/view/structure/desktop/layers/shell/taskbar/programs/taskbar-item.tsx+++ b/source/client/view/structure/desktop/layers/shell/taskbar/programs/taskbar-item.tsx@@ -6,10 +6,13 @@ import { forwardRef, type ReactNode } from "react"* A window on the Taskbar. The windows sit flat and translucent in the bar, so* the active one, raised in the primary color, is the one that stands out.*/-export default forwardRef<HTMLButtonElement, TaskbarItemProps>(function TaskbarItem({ active = false, icon, position, children, className, ...props }, ref) {+export default forwardRef<HTMLButtonElement, TaskbarItemProps>(function TaskbarItem({ active = false, icon, position, labeled = true, children, className, ...props }, ref) {const horizontal = position === "top" || position === "bottom"+ // Its name beside its icon on a Taskbar lying along a wide screen; its icon alone otherwise.+ const named = horizontal && labeled+return <Buttonref={ref}@@ -18,14 +21,15 @@ export default forwardRef<HTMLButtonElement, TaskbarItemProps>(function TaskbarIdepth={active ? "raised" : "flat"}color={active ? "primary:soft" : undefined}material={active ? undefined : resting}- className={`${horizontal ? "max-w-40 scroll-mx-8" : "w-full scroll-my-8 px-0"} ${className ?? ""}`}+ iconOnly={horizontal && !named}+ className={`${named ? "max-w-40 scroll-mx-8" : horizontal ? "scroll-mx-8" : "w-full scroll-my-8 px-0"} ${className ?? ""}`}{...props}><img src={icon} alt="" draggable={false} className="size-4 shrink-0 rounded-sm object-contain" />- <span className={horizontal ? "truncate" : "sr-only"}>{children}</span>+ <span className={named ? "truncate" : "sr-only"}>{children}</span></Button>})@@ -42,5 +46,8 @@ interface TaskbarItemProps extends Omit<ButtonActionProps, "children"> {position: TaskbarPosition+ /** Whether its name shows beside its icon where the Taskbar lies along the screen; on a narrow one it does not. */+ labeled?: boolean+children?: ReactNode}diff --git a/source/client/view/structure/desktop/layers/shell/taskbar/programs/window-taskbar-item.tsx b/source/client/view/structure/desktop/layers/shell/taskbar/programs/window-taskbar-item.tsxindex c10ac1b..ac8dd80 100644--- a/source/client/view/structure/desktop/layers/shell/taskbar/programs/window-taskbar-item.tsx+++ b/source/client/view/structure/desktop/layers/shell/taskbar/programs/window-taskbar-item.tsx@@ -9,7 +9,7 @@ import useDragHold from "../../../../drag-hold"import { memo, useCallback } from "react"/** A taskbar entry rerenders only when what that entry shows changes. */-export default memo(function ({ record, title, icon, position, active, minimized, maximized, onElement, onMinimize, onShow, onGoTo, onBringHere, onMaximize, onClose }: WindowTaskbarItemProps) {+export default memo(function ({ record, title, icon, position, labeled, active, minimized, maximized, pinned, onElement, onMinimize, onShow, onGoTo, onBringHere, onMaximize, onTogglePinned, onClose }: WindowTaskbarItemProps) {const scaleContainer = useDesktopScaleContainer()@@ -38,13 +38,14 @@ export default memo(function ({ record, title, icon, position, active, minimizedconst maximize = useCallback(() => void onMaximize(record), [onMaximize, record])const bringHere = useCallback(() => onBringHere(record), [onBringHere, record])const close = useCallback(() => onClose(record), [onClose, record])+ const togglePinned = useCallback(() => onTogglePinned(record), [onTogglePinned, record])// The title shows on hover and focus, since a Taskbar standing on its side has room for the icon alone.return <TaskbarTooltip label={title}><ContextMenu><ContextMenu.Trigger>- <TaskbarItem ref={source} active={active} icon={icon} position={position} onPress={press}>+ <TaskbarItem ref={source} active={active} icon={icon} position={position} labeled={labeled} onPress={press}>{title}@@ -54,8 +55,8 @@ export default memo(function ({ record, title, icon, position, active, minimized<ContextMenu.Content portalContainer={scaleContainer ?? undefined}>- <WindowMenu title={title} minimized={minimized} maximized={maximized}- onGoTo={goTo} onBringHere={bringHere} onToggleMinimized={changeVisibility} onToggleMaximized={maximize} onClose={close} />+ <WindowMenu title={title} minimized={minimized} maximized={maximized} pinned={pinned}+ onGoTo={goTo} onBringHere={bringHere} onToggleMinimized={changeVisibility} onToggleMaximized={maximize} onTogglePinned={togglePinned} onClose={close} /></ContextMenu.Content>@@ -72,12 +73,21 @@ interface WindowTaskbarItemProps {position: TaskbarPosition+ /** Whether its title shows beside its icon; see TaskbarItem. */+ labeled: boolean+active: booleanminimized: booleanmaximized: boolean+ /** Whether its Program keeps its place on the Taskbar. */+ pinned: boolean++ /** Pins its Program to the Taskbar, or unpins it. */+ onTogglePinned: (record: Process) => void+onElement: (record: Process, element: HTMLButtonElement | null) => voidonMinimize: (record: Process, minimized: boolean) => voiddiff --git a/source/client/view/structure/desktop/layers/shell/window-menu.tsx b/source/client/view/structure/desktop/layers/shell/window-menu.tsxindex bb38b6b..23ea2d1 100644--- a/source/client/view/structure/desktop/layers/shell/window-menu.tsx+++ b/source/client/view/structure/desktop/layers/shell/window-menu.tsx@@ -1,15 +1,18 @@import { Menu } from "@phreshos/react-ui"-import { ArrowDownLeft, ArrowUpRight, LocateFixed, Magnet, Maximize2, Minimize2, X } from "@phreshos/react-ui/icons"+import { ArrowDownLeft, ArrowUpRight, LocateFixed, Magnet, Maximize2, Minimize2, Pin, PinOff, X } from "@phreshos/react-ui/icons"/*** What can be done to one standard Window, the same wherever it is offered: its Taskbar item and its* icon on the Map. Going to it and bringing it here move between views; the rest act on the Window* where it is, with the same icons as the Window's own title bar controls.*/-export default function WindowMenu({ title, minimized, maximized, onGoTo, onBringHere, onToggleMinimized, onToggleMaximized, onClose }: Readonly<{+export default function WindowMenu({ title, minimized, maximized, pinned, onGoTo, onBringHere, onToggleMinimized, onToggleMaximized, onTogglePinned, onClose }: Readonly<{title: stringminimized: booleanmaximized: boolean+ /** Whether its Program keeps its place on the Taskbar; offered only where `onTogglePinned` is. */+ pinned?: boolean+ onTogglePinned?: () => voidonGoTo: () => voidonBringHere: () => voidonToggleMinimized: () => void@@ -22,6 +25,7 @@ export default function WindowMenu({ title, minimized, maximized, onGoTo, onBrinelse if (action === "bringHere") onBringHere()else if (action === "visibility") onToggleMinimized()else if (action === "maximize") onToggleMaximized()+ else if (action === "pin") onTogglePinned?.()else if (action === "close") onClose()}}>@@ -35,6 +39,11 @@ export default function WindowMenu({ title, minimized, maximized, onGoTo, onBrin<Menu.Item id="maximize" textValue={maximized ? "Restore" : "Maximize"}>{maximized ? <><Minimize2 aria-hidden />Restore</> : <><Maximize2 aria-hidden />Maximize</>}</Menu.Item>+ {onTogglePinned && <>+ <Menu.Separator />+ <Menu.Item id="pin" textValue={pinned ? "Unpin from Taskbar" : "Pin to Taskbar"}>{pinned ? <><PinOff aria-hidden />Unpin from Taskbar</> : <><Pin aria-hidden />Pin to Taskbar</>}</Menu.Item>+ </>}+<Menu.Separator /><Menu.Item id="close" color="danger" textValue="Close"><X aria-hidden />Close</Menu.Item>diff --git a/source/server/core/link-manager/auth-manager/program-manager/entry.ts b/source/server/core/link-manager/auth-manager/program-manager/entry.tsindex aa8e66e..f561de3 100644--- a/source/server/core/link-manager/auth-manager/program-manager/entry.ts+++ b/source/server/core/link-manager/auth-manager/program-manager/entry.ts@@ -58,8 +58,11 @@ export default class Entry {// Whether it starts with the System, so a list can be filtered// where it is held. The launch itself stays behind `startup.get()`.- startup: new ProgramStateStorage(this.program).startup() !== null- } satisfies ProgramSnapshot & { permissions: Permissions, startup: boolean }+ startup: new ProgramStateStorage(this.program).startup() !== null,++ // Whether it keeps its place on a Desktop's Taskbar, closed or open.+ pinned: new ProgramStateStorage(this.program).pinned()+ } satisfies ProgramSnapshot & { permissions: Permissions, startup: boolean, pinned: boolean }}public toJSON() {diff --git a/tests/permission-synchronization.test.ts b/tests/permission-synchronization.test.tsindex 4341c51..f8e2df1 100644--- a/tests/permission-synchronization.test.ts+++ b/tests/permission-synchronization.test.ts@@ -23,7 +23,8 @@ function record(permissions: ProgramRecord["permissions"]): ProgramRecord {server: null,client: null,permissions,- startup: false+ startup: false,+ pinned: false}}