Skip to content

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

Add taskbar window actions

zohayrslileh25437b6d1590
diff --git a/source/client/view/appearance/appearance.tsx b/source/client/view/appearance/appearance.tsx
index 63fa94f..4ccfa4b 100644
--- a/source/client/view/appearance/appearance.tsx
+++ b/source/client/view/appearance/appearance.tsx
@@ -21,6 +21,7 @@ export default function ({ children }: PropsWithChildren) {
function AppearanceRoot({ children }: PropsWithChildren) {
const { preferences } = useDesktopPreferences()
const [appearance, setAppearance] = useState(() => resolveStoredAppearance(localStorage.getItem(appearanceKey)))
+ const [scaleContainer, setScaleContainer] = useState<HTMLDivElement | null>(null)
const remember = useCallback(function (value: Appearance) {
setAppearance(value)
localStorage.setItem(appearanceKey, JSON.stringify(value))
@@ -33,13 +34,14 @@ function AppearanceRoot({ children }: PropsWithChildren) {
<UIProvider appearance={appearance} preferences={preferences}>
- <DesktopScaleProvider scale={preferences.scale}>
+ <DesktopScaleProvider scale={preferences.scale} container={scaleContainer}>
<div className="relative isolate h-dvh overflow-hidden" style={{ backgroundColor: background }}>
<ReducedMotion reduced={!preferences.animations}>
<div
+ ref={setScaleContainer}
className="absolute top-0 left-0 isolate grid font-roboto"
style={{ width: "100%", height: "100%", zoom: preferences.scale }}
>
diff --git a/source/client/view/structure/desktop/desktop-scale.tsx b/source/client/view/structure/desktop/desktop-scale.tsx
index 12a5fb6..076273d 100644
--- a/source/client/view/structure/desktop/desktop-scale.tsx
+++ b/source/client/view/structure/desktop/desktop-scale.tsx
@@ -1,19 +1,31 @@
import { defaultDesktopScale } from "@phreshos/core"
-import { createContext, type ReactNode, useContext } from "react"
+import { createContext, type ReactNode, useContext, useMemo } from "react"
-const DesktopScaleContext = createContext(defaultDesktopScale)
+const DesktopScaleContext = createContext<DesktopScale>({ scale: defaultDesktopScale, container: null })
/** Establishes the ratio between physical browser pixels and Desktop pixels. */
-export function DesktopScaleProvider({ children, scale }: Readonly<{ children: ReactNode, scale: number }>) {
- return <DesktopScaleContext.Provider value={scale}>{children}</DesktopScaleContext.Provider>
+export function DesktopScaleProvider({ children, scale, container }: Readonly<{ children: ReactNode, scale: number, container: HTMLElement | null }>) {
+ const value = useMemo(() => ({ scale, container }), [container, scale])
+
+ return <DesktopScaleContext.Provider value={value}>{children}</DesktopScaleContext.Provider>
}
/** Returns the effective scale of the containing Desktop representation. */
export function useDesktopScale() {
- return useContext(DesktopScaleContext)
+ return useContext(DesktopScaleContext).scale
+}
+
+/** Returns the DOM boundary through which Desktop overlays inherit that scale. */
+export function useDesktopScaleContainer() {
+ return useContext(DesktopScaleContext).container
}
/** Converts one physical browser distance into the Desktop coordinate space. */
export function physicalToDesktopPixels(value: number, scale: number) {
return value / scale
}
+
+interface DesktopScale {
+ readonly scale: number
+ readonly container: HTMLElement | null
+}
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsx
index 0601e29..81deaea 100644
--- a/source/client/view/structure/desktop/desktop.tsx
+++ b/source/client/view/structure/desktop/desktop.tsx
@@ -213,25 +213,38 @@ export default function Workspace() {
another window is shown and brought forward. */}
<OverflowRow aria-label="Open windows" backwardLabel="Earlier windows" forwardLabel="Later windows">
- {windows.listed.map(record => <WindowTaskbarItem
+ {windows.listed.map(record => {
- key={record.identity}
+ const window = windows.localWindow.projection(record.identity)
- record={record}
+ return <WindowTaskbarItem
- title={windows.localWindow.projection(record.identity).title}
+ key={record.identity}
- icon={icon(record)}
+ record={record}
- active={fronts.window?.identity === record.identity}
+ title={window.title}
- onElement={focus.taskbarItem}
+ icon={icon(record)}
- onMinimize={focus.minimize}
+ active={fronts.window?.identity === record.identity}
- onShow={windows.show}
+ minimized={window.minimized}
- />)}
+ maximized={window.maximized}
+
+ onElement={focus.taskbarItem}
+
+ onMinimize={focus.minimize}
+
+ onShow={windows.show}
+
+ onFill={windows.fill}
+
+ onClose={focus.close}
+
+ />
+ })}
</OverflowRow>
diff --git a/source/client/view/structure/desktop/taskbar/programs/window-taskbar-item.tsx b/source/client/view/structure/desktop/taskbar/programs/window-taskbar-item.tsx
index 3874021..82bf61b 100644
--- a/source/client/view/structure/desktop/taskbar/programs/window-taskbar-item.tsx
+++ b/source/client/view/structure/desktop/taskbar/programs/window-taskbar-item.tsx
@@ -1,9 +1,13 @@
import Process from "@client/core/link-manager/auth-manager/process-manager/process"
+import { ContextMenu, Menu } from "@phreshos/react-ui"
+import { useDesktopScaleContainer } from "../../desktop-scale"
import TaskbarItem from "./taskbar-item"
import { memo, useCallback } from "react"
/** A taskbar entry rerenders only when what that entry shows changes. */
-export default memo(function ({ record, title, icon, active, onElement, onMinimize, onShow }: WindowTaskbarItemProps) {
+export default memo(function ({ record, title, icon, active, minimized, maximized, onElement, onMinimize, onShow, onFill, onClose }: WindowTaskbarItemProps) {
+
+ const scaleContainer = useDesktopScaleContainer()
const press = useCallback(function () {
@@ -14,12 +18,45 @@ export default memo(function ({ record, title, icon, active, onElement, onMinimi
}, [active, onMinimize, onShow, record])
const source = useCallback((element: HTMLButtonElement | null) => onElement(record, element), [onElement, record])
+ const changeVisibility = useCallback(() => {
+
+ if (minimized) onShow(record)
+
+ else onMinimize(record, true)
+
+ }, [minimized, onMinimize, onShow, record])
+ const fill = useCallback(() => onFill(record), [onFill, record])
+ const close = useCallback(() => onClose(record), [onClose, record])
+
+ return <ContextMenu>
+
+ <ContextMenu.Trigger>
+
+ <TaskbarItem ref={source} active={active} icon={icon} onPress={press}>
+
+ {title}
+
+ </TaskbarItem>
+
+ </ContextMenu.Trigger>
- return <TaskbarItem ref={source} active={active} icon={icon} onPress={press}>
+ <ContextMenu.Content UNSTABLE_portalContainer={scaleContainer ?? undefined}>
- {title}
+ <Menu aria-label={`${title} window actions`}>
- </TaskbarItem>
+ <Menu.Item onAction={changeVisibility}>{minimized ? "Show" : "Minimize"}</Menu.Item>
+
+ <Menu.Item onAction={fill}>{maximized ? "Restore" : "Maximize"}</Menu.Item>
+
+ <Menu.Separator />
+
+ <Menu.Item color="danger:base" onAction={close}>Close</Menu.Item>
+
+ </Menu>
+
+ </ContextMenu.Content>
+
+ </ContextMenu>
})
interface WindowTaskbarItemProps {
@@ -32,9 +69,17 @@ interface WindowTaskbarItemProps {
active: boolean
+ minimized: boolean
+
+ maximized: boolean
+
onElement: (record: Process, element: HTMLButtonElement | null) => void
onMinimize: (record: Process, minimized: boolean) => void
onShow: (record: Process) => void
+
+ onFill: (record: Process) => void
+
+ onClose: (record: Process) => void
}