Skip to content

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

Uninstall from the Program menu, asked in a System dialog

zohayrslileh41b25eee2977
diff --git a/source/client/view/structure/desktop/layers/shell/default-shell.tsx b/source/client/view/structure/desktop/layers/shell/default-shell.tsx
index 2115426..c07da9a 100644
--- a/source/client/view/structure/desktop/layers/shell/default-shell.tsx
+++ b/source/client/view/structure/desktop/layers/shell/default-shell.tsx
@@ -3,6 +3,7 @@ import { useState, type ReactNode } from "react"
import SystemErrors from "./dialogs/system-errors"
import PermissionRequests from "./dialogs/permission-requests"
import OpenRequests from "./dialogs/open-requests"
+import { UninstallProgramProvider } from "./dialogs/uninstall-program"
import StartMenu, { StartMenuButton, StartMenuProvider, useStartMenuOpen } from "./start-menu/start-menu"
import SignOut from "./taskbar/sign-out"
import Taskbar from "./taskbar/taskbar"
@@ -24,11 +25,15 @@ export default function DefaultShell({ spacing, taskbar, viewport, mappedWindows
<StartMenuProvider spacing={spacing} taskbar={taskbar}>
- <DefaultTaskbar spacing={spacing} taskbar={taskbar} viewport={viewport} mappedWindows={mappedWindows} horizontal={horizontal}>
- {children}
- </DefaultTaskbar>
+ <UninstallProgramProvider>
- <StartMenu />
+ <DefaultTaskbar spacing={spacing} taskbar={taskbar} viewport={viewport} mappedWindows={mappedWindows} horizontal={horizontal}>
+ {children}
+ </DefaultTaskbar>
+
+ <StartMenu />
+
+ </UninstallProgramProvider>
</StartMenuProvider>
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
new file mode 100644
index 0000000..2bf1064
--- /dev/null
+++ b/source/client/view/structure/desktop/layers/shell/dialogs/uninstall-program.tsx
@@ -0,0 +1,110 @@
+import type 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 { AlertDialog, Button, Checkbox } from "@phreshos/react-ui"
+import { createContext, useCallback, useContext, useState, type ReactNode } from "react"
+import { useDesktopScaleContainer } from "../../../desktop-scale"
+import { useCloseStartMenu } from "../start-menu/start-menu"
+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.
+ */
+export function UninstallProgramProvider({ children }: Readonly<{ children: ReactNode }>) {
+
+ const [program, setProgram] = useState<Program | null>(null)
+
+ const closeStartMenu = useCloseStartMenu()
+
+ const ask = useCallback(function (program: Program) {
+
+ closeStartMenu()
+
+ setProgram(program)
+
+ }, [closeStartMenu])
+
+ return <UninstallProgramContext.Provider value={ask}>
+
+ {children}
+
+ <UninstallProgram program={program} onDone={() => setProgram(null)} />
+
+ </UninstallProgramContext.Provider>
+}
+
+/** Asks the owner to confirm uninstalling a Program. */
+export function useUninstallProgram() {
+
+ const ask = useContext(UninstallProgramContext)
+
+ if (!ask) throw new Error("Uninstalling a Program from the Shell requires UninstallProgramProvider")
+
+ return ask
+}
+
+function UninstallProgram({ program, onDone }: Readonly<{ program: Program | null, onDone: () => void }>) {
+
+ const container = useDesktopScaleContainer()
+
+ // The Program stays shown while the dialog leaves, so it does not empty as it fades.
+ const shown = useShown(program ?? undefined)
+
+ return <AlertDialog open={program !== null}>
+
+ <AlertDialog.Backdrop portalContainer={container ?? undefined}>
+
+ <AlertDialog.Content style={{ width: "28rem" }}>
+
+ {/* Keyed by the Program: a new one starts with nothing chosen. */}
+ {shown && <UninstallProgramView key={shown.reference} program={shown} onDone={onDone} />}
+
+ </AlertDialog.Content>
+
+ </AlertDialog.Backdrop>
+
+ </AlertDialog>
+}
+
+function UninstallProgramView({ program, onDone }: Readonly<{ program: Program, onDone: () => void }>) {
+
+ const [purge, setPurge] = useState(false)
+
+ const uninstalling = usePromise(async () => {
+
+ for await (const _chunk of program.uninstall({ purge })) { /* consume command output */ }
+
+ onDone()
+ })
+
+ return <>
+
+ <AlertDialog.Header>
+
+ <AlertDialog.Title>Uninstall {program.name}?</AlertDialog.Title>
+
+ <AlertDialog.Description>Its Processes end and its files are removed.</AlertDialog.Description>
+
+ </AlertDialog.Header>
+
+ <AlertDialog.Body>
+
+ <Checkbox checked={purge} disabled={uninstalling.isPending} onChange={setPurge} label="Also remove its data" description="Its storage, store, and database. Otherwise they stay for a later install." />
+
+ {uninstalling.exception && <Alert className="text-sm">{String(uninstalling.exception.current)}</Alert>}
+
+ </AlertDialog.Body>
+
+ <AlertDialog.Footer>
+
+ <Button autoFocus disabled={uninstalling.isPending} onPress={onDone}>Cancel</Button>
+
+ <Button color="danger" pending={uninstalling.isPending} onPress={() => void uninstalling.safeExecute()}>Uninstall</Button>
+
+ </AlertDialog.Footer>
+
+ </>
+}
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 c88d06a..f9b01ec 100644
--- a/source/client/view/structure/desktop/layers/shell/program-menu.tsx
+++ b/source/client/view/structure/desktop/layers/shell/program-menu.tsx
@@ -1,18 +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"
+import { AppWindow, 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.
+ * 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.
*/
export default function ProgramMenu({ program, onOpen }: Readonly<{ program: Program, onOpen: () => void }>) {
- const { pinnedAt } = program
+ const { pinnedAt, installedAt } = program
+
+ const uninstall = useUninstallProgram()
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)
}}>
<Menu.Item id="open" textValue="Open"><AppWindow aria-hidden />Open</Menu.Item>
@@ -21,5 +26,13 @@ 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>
}