Skip to content

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

Shell: Programs attached from their projects are listed, tinted, and forgotten like installed ones

zohayrslilehc08425b0eeef
diff --git a/source/client/view/structure/desktop/layers/shell/dialogs/uninstall-program.tsx b/source/client/view/structure/desktop/layers/shell/dialogs/uninstall-program.tsx
index 2bf1064..b6446a8 100644
--- a/source/client/view/structure/desktop/layers/shell/dialogs/uninstall-program.tsx
+++ b/source/client/view/structure/desktop/layers/shell/dialogs/uninstall-program.tsx
@@ -10,8 +10,9 @@ import useShown from "./shown"
const UninstallProgramContext = createContext<((program: Program) => void) | null>(null)
/**
- * Lets the Shell's Program menus ask to uninstall a Program: the owner confirms in a dialog over the
- * whole Desktop, which the Start Menu would stand above, so it closes first.
+ * Lets the Shell's Program menus ask to remove a Program: to uninstall an installed one, or to forget
+ * one attached from its project. The owner confirms in a dialog over the whole Desktop, which the
+ * Start Menu would stand above, so it closes first.
*/
export function UninstallProgramProvider({ children }: Readonly<{ children: ReactNode }>) {
@@ -36,7 +37,7 @@ export function UninstallProgramProvider({ children }: Readonly<{ children: Reac
</UninstallProgramContext.Provider>
}
-/** Asks the owner to confirm uninstalling a Program. */
+/** Asks the owner to confirm uninstalling a Program, or forgetting one attached from its project. */
export function useUninstallProgram() {
const ask = useContext(UninstallProgramContext)
@@ -71,6 +72,46 @@ function UninstallProgram({ program, onDone }: Readonly<{ program: Program | nul
function UninstallProgramView({ program, onDone }: Readonly<{ program: Program, onDone: () => void }>) {
+ if (program.installedAt === null) return <ForgetProgramView program={program} onDone={onDone} />
+
+ return <InstalledProgramView program={program} onDone={onDone} />
+}
+
+/** An attached Program is not installed: it is forgotten, and its project's files stay. */
+function ForgetProgramView({ program, onDone }: Readonly<{ program: Program, onDone: () => void }>) {
+
+ const forgetting = usePromise(async () => {
+
+ await program.forget("")
+
+ onDone()
+ })
+
+ return <>
+
+ <AlertDialog.Header>
+
+ <AlertDialog.Title>Forget {program.name}?</AlertDialog.Title>
+
+ <AlertDialog.Description>Its Processes end and the System no longer knows it. Its project's files stay.</AlertDialog.Description>
+
+ </AlertDialog.Header>
+
+ {forgetting.exception && <AlertDialog.Body><Alert className="text-sm">{String(forgetting.exception.current)}</Alert></AlertDialog.Body>}
+
+ <AlertDialog.Footer>
+
+ <Button autoFocus disabled={forgetting.isPending} onPress={onDone}>Cancel</Button>
+
+ <Button color="danger" pending={forgetting.isPending} onPress={() => void forgetting.safeExecute()}>Forget</Button>
+
+ </AlertDialog.Footer>
+
+ </>
+}
+
+function InstalledProgramView({ program, onDone }: Readonly<{ program: Program, onDone: () => void }>) {
+
const [purge, setPurge] = useState(false)
const uninstalling = usePromise(async () => {
diff --git a/source/client/view/structure/desktop/layers/shell/program-menu.tsx b/source/client/view/structure/desktop/layers/shell/program-menu.tsx
index f9b01ec..4d63310 100644
--- a/source/client/view/structure/desktop/layers/shell/program-menu.tsx
+++ b/source/client/view/structure/desktop/layers/shell/program-menu.tsx
@@ -1,12 +1,12 @@
import type Program from "@client/core/link-manager/auth-manager/program-manager/program"
import { Menu } from "@phreshos/react-ui"
-import { AppWindow, Pin, PinOff, Trash2 } from "@phreshos/react-ui/icons"
+import { AppWindow, CircleOff, Pin, PinOff, Trash2 } from "@phreshos/react-ui/icons"
import { useUninstallProgram } from "./dialogs/uninstall-program"
/**
* 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;
- * Uninstall removes an installed one once the owner confirms.
+ * Uninstall removes an installed one, and Forget one attached from its project, once the owner confirms.
*/
export default function ProgramMenu({ program, onOpen }: Readonly<{ program: Program, onOpen: () => void }>) {
@@ -17,7 +17,7 @@ export default function ProgramMenu({ program, onOpen }: Readonly<{ program: Pro
return <Menu aria-label={`${program.name} actions`} size="small" onAction={action => {
if (action === "open") onOpen()
else if (action === "pin") void program.pin(pinnedAt === null).catch(() => undefined)
- else if (action === "uninstall") uninstall(program)
+ else if (action === "uninstall" || action === "forget") uninstall(program)
}}>
<Menu.Item id="open" textValue="Open"><AppWindow aria-hidden />Open</Menu.Item>
@@ -26,13 +26,11 @@ export default function ProgramMenu({ program, onOpen }: Readonly<{ program: Pro
<Menu.Item id="pin" textValue={pinnedAt !== null ? "Unpin" : "Pin"}>{pinnedAt !== null ? <><PinOff aria-hidden />Unpin</> : <><Pin aria-hidden />Pin</>}</Menu.Item>
- {installedAt !== null && <>
-
- <Menu.Separator />
-
- <Menu.Item id="uninstall" color="danger" textValue="Uninstall"><Trash2 aria-hidden />Uninstall</Menu.Item>
+ <Menu.Separator />
- </>}
+ {installedAt !== null
+ ? <Menu.Item id="uninstall" color="danger" textValue="Uninstall"><Trash2 aria-hidden />Uninstall</Menu.Item>
+ : <Menu.Item id="forget" color="danger" textValue="Forget"><CircleOff aria-hidden />Forget</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.tsx
index 29b4149..85856b1 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,7 +2,7 @@ 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, ContextMenu, GridList, Table, Text, useAppearance, useScale, ScrollArea } from "@phreshos/react-ui"
+import { Badge, ContextMenu, GridList, Table, Text, useAppearance, useColor, useScale, ScrollArea } from "@phreshos/react-ui"
import { useRef, useState, type ReactElement } from "react"
import Empty from "../empty"
import ProgramMenu from "../../program-menu"
@@ -23,6 +23,7 @@ export default function Programs({ programs, layout, running, empty, onLaunch }:
const application = ApplicationContext.useValue()
const space = useScale(useAppearance().spacing)
+ const attachedColor = useAttachedColor()
const surface = useStartMenuSurface()
@@ -52,7 +53,8 @@ export default function Programs({ programs, layout, running, empty, onLaunch }:
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}>
+ {/* A Program attached from its project stands apart by a very light tint of its own. */}
+ {programs.map(program => <GridList.Item key={program.identity} id={program.identity} textValue={program.name} restColor={program.installedAt === null ? attachedColor : undefined}>
{/* 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 }}>
@@ -77,7 +79,7 @@ export default function Programs({ programs, layout, running, empty, onLaunch }:
</Table.Header>
<Table.Body>
- {programs.map(program => <Table.Row key={program.identity} id={program.identity} textValue={program.name}>
+ {programs.map(program => <Table.Row key={program.identity} id={program.identity} textValue={program.name} restColor={program.installedAt === null ? attachedColor : undefined}>
<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 }} />
@@ -123,3 +125,21 @@ export function useLaunch() {
await program.createProcess({ client: declared ? (placed.size ? { size: placed.size } : {}) : placed })
}
}
+
+/**
+ * The tint of a Program attached from its project, not installed: a card's own color with a little
+ * of the warning color in it, so it stands apart while staying close to the others.
+ */
+function useAttachedColor() {
+ return mix(useColor("default").base, useColor("warning").subtle, attachedShare)
+}
+
+/** How much of the warning color an attached Program's card takes. */
+const attachedShare = 0.35
+
+/** Two hex colors mixed: `share` of the second in the first. */
+function mix(first: string, second: string, share: number) {
+ const channels = (hex: string) => [1, 3, 5].map(at => parseInt(hex.slice(at, at + 2), 16))
+ const [a, b] = [channels(first), channels(second)]
+ return `#${a.map((value, index) => Math.round(value + (b[index]! - value) * share).toString(16).padStart(2, "0")).join("")}`
+}
diff --git a/source/client/view/structure/desktop/programs/programs.ts b/source/client/view/structure/desktop/programs/programs.ts
index 1a41824..bbc9df0 100644
--- a/source/client/view/structure/desktop/programs/programs.ts
+++ b/source/client/view/structure/desktop/programs/programs.ts
@@ -16,5 +16,6 @@ export default function usePrograms() {
useLayoutEffect(() => manager.subscribePrograms(setPrograms), [manager])
- return programs.filter(program => program.installedAt !== null)
+ // Installed or attached from a project: an attached Program can do all an installed one can.
+ return programs
}