Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(appshot): an editor for appshots, opened from the corner card

rubenluetke10-beep6b8633b73033
diff --git a/docs/appshots.md b/docs/appshots.md
index 1ac889dc67..7856b55dc1 100644
--- a/docs/appshots.md
+++ b/docs/appshots.md
@@ -54,6 +54,30 @@ rectangle (see below).
A spoken "what do you see?" is the same look (Screen Context); it also plays
the shutter and shows up as the last appshot.
+## The card in the corner, and the editor
+
+After the shutter the picture flies into the bottom-right corner of its
+screen and rests there as a card for about six seconds (longer while the
+pointer is on it):
+
+- **Click** opens the app on the Appshots page with the **appshot editor**:
+ arrow, rectangle, ellipse, pen, highlighter, text, pixelate and crop, with
+ undo/redo (Ctrl+Z / Ctrl+Y) and one-key tools (A, R, E, P, H, T, B, C).
+ **Copy** puts the result on the clipboard, **Save** downloads a PNG, and
+ **Use this version** replaces the held appshot, so the next message carries
+ the edited picture (a picture already sent into a voice call stays as it
+ was). The last appshot on the Appshots page opens the same editor.
+- **Drag** the card into any app that accepts files or images (chat, mail,
+ Explorer/Finder) to drop the picture there.
+- **Right-click** dismisses it.
+
+Only the finished, privacy-filtered appshot can leave by drag — the card's
+own thumbnail is cut from the raw frame and never does. A drag is the one
+moment an appshot touches disk: the picture is written to
+`<temp>/jarvis-appshots/` just then, and files older than an hour are removed
+on the next drag. With `[screen_context].deck_preview_s = 0` (keep nothing)
+the card only opens the editor and shares nothing.
+
## Where a shortcut appshot goes
| Destination | Running voice call | No voice call |
@@ -129,7 +153,10 @@ instance) arms the shortcuts.
last appshot, memory only), `gesture.py` (both-Alt watcher), `hotkey.py`
(both shortcuts' lifecycle), `region.py` (area selection and its coordinate
mapping), `picker/` (the area picker sidecar), `effect.py` (shutter hook),
-`delivery.py` (voice calls).
+`delivery.py` (voice calls). The corner card lives in the indicator sidecar
+(`jarvis/cu/indicator/renderer.py`, `_CardWindow`); the editor is
+`frontend/src/views/AppshotEditor.tsx` with its document model in
+`lib/appshotEditorModel.ts`.
The live model's `take_appshot` tool is `jarvis/plugins/tool/appshot.py`; the
REST surface is `jarvis/ui/web/appshot_routes.py`; the page is
`frontend/src/views/AppshotsView.tsx`.
diff --git a/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts b/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts
index a57857cd8a..a58ac905af 100644
--- a/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts
@@ -24,6 +24,7 @@ import {
useCommandActivityStore,
COMMAND_ACTIVITY_EVENTS,
} from "@/store/commandActivity";
+import { useAppshotEditor } from "@/store/appshotEditor";
import { useDeckStore } from "@/store/deck";
import { useHomeStore } from "@/store/home";
import { PANE_ACTIVITY_EVENT } from "@/store/workspacePanes";
@@ -155,6 +156,19 @@ export function useWebSocket(): void {
}
}
+ // A click on the appshot card in the screen corner: open the editor on
+ // the Appshots page. A detached solo window leaves it to the main one.
+ if (env.event_name === "AppshotEditRequested" && !useEventStore.getState().solo) {
+ const id = (env.payload as { appshot_id?: unknown }).appshot_id;
+ if (typeof id === "string" && id) {
+ setActiveSection("appshots");
+ useAppshotEditor.getState().open(id);
+ } else {
+ setActiveSection("appshots");
+ pushToast("warning", translate("appshots.editor.gone"));
+ }
+ }
+
// Live reasoning trace: while the text chat is waiting on a reply,
// turn-progress events (tools, computer-use, worker dispatch, ...)
// become visible thinking steps. Gated on chatThinking inside the
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index 655f738bb9..1304c98e80 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -6042,7 +6042,33 @@
"voice_hint": "Du kannst auch einfach sagen: \"Mach einen Appshot\".",
"save_error": "Speichern fehlgeschlagen: {0}",
"toast_refused": "Kein Appshot: {0}",
- "chip_label": "Appshot an deine Nachricht gehängt"
+ "chip_label": "Appshot an deine Nachricht gehängt",
+ "editor": {
+ "title": "Appshot bearbeiten",
+ "open": "Bearbeiten",
+ "tool_arrow": "Pfeil",
+ "tool_rect": "Rechteck",
+ "tool_ellipse": "Ellipse",
+ "tool_pen": "Stift",
+ "tool_highlight": "Textmarker",
+ "tool_text": "Text",
+ "tool_pixelate": "Verpixeln",
+ "tool_crop": "Zuschneiden",
+ "color": "Farbe",
+ "size": "Stärke",
+ "undo": "Rückgängig",
+ "redo": "Wiederholen",
+ "copy": "Kopieren",
+ "copied": "In die Zwischenablage kopiert",
+ "copy_failed": "Kopieren ging nicht: {0}",
+ "copy_timeout": "die Zwischenablage hat nicht geantwortet",
+ "save": "Speichern",
+ "apply": "Diese Version nutzen",
+ "applied": "Bearbeiteter Appshot gespeichert. Deine nächste Nachricht nutzt ihn.",
+ "close": "Schließen",
+ "gone": "Dieser Appshot wird nicht mehr aufbewahrt und kann nicht bearbeitet werden.",
+ "text_placeholder": "Text…"
+ }
},
"pets": {
"title": "Meine Pets",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 6c0ae2837d..69806c7dd3 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -6075,7 +6075,33 @@
"voice_hint": "You can also just say \"take an appshot\".",
"save_error": "Could not save: {0}",
"toast_refused": "No appshot: {0}",
- "chip_label": "Appshot added to your message"
+ "chip_label": "Appshot added to your message",
+ "editor": {
+ "title": "Edit appshot",
+ "open": "Edit",
+ "tool_arrow": "Arrow",
+ "tool_rect": "Rectangle",
+ "tool_ellipse": "Ellipse",
+ "tool_pen": "Pen",
+ "tool_highlight": "Highlighter",
+ "tool_text": "Text",
+ "tool_pixelate": "Pixelate",
+ "tool_crop": "Crop",
+ "color": "Colour",
+ "size": "Size",
+ "undo": "Undo",
+ "redo": "Redo",
+ "copy": "Copy",
+ "copied": "Copied to the clipboard",
+ "copy_failed": "Could not copy: {0}",
+ "copy_timeout": "the clipboard did not answer",
+ "save": "Save",
+ "apply": "Use this version",
+ "applied": "Edited appshot saved. Your next message uses it.",
+ "close": "Close",
+ "gone": "This appshot is no longer kept, so it cannot be edited.",
+ "text_placeholder": "Type…"
+ }
},
"pets": {
"title": "My Pets",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index 63a48eb1f1..1feb95956f 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -6042,7 +6042,33 @@
"voice_hint": "También puedes decir \"haz un appshot\".",
"save_error": "No se pudo guardar: {0}",
"toast_refused": "Sin appshot: {0}",
- "chip_label": "Appshot añadido a tu mensaje"
+ "chip_label": "Appshot añadido a tu mensaje",
+ "editor": {
+ "title": "Editar appshot",
+ "open": "Editar",
+ "tool_arrow": "Flecha",
+ "tool_rect": "Rectángulo",
+ "tool_ellipse": "Elipse",
+ "tool_pen": "Lápiz",
+ "tool_highlight": "Marcador",
+ "tool_text": "Texto",
+ "tool_pixelate": "Pixelar",
+ "tool_crop": "Recortar",
+ "color": "Color",
+ "size": "Grosor",
+ "undo": "Deshacer",
+ "redo": "Rehacer",
+ "copy": "Copiar",
+ "copied": "Copiado al portapapeles",
+ "copy_failed": "No se pudo copiar: {0}",
+ "copy_timeout": "el portapapeles no respondió",
+ "save": "Guardar",
+ "apply": "Usar esta versión",
+ "applied": "Appshot editado guardado. Tu próximo mensaje lo usará.",
+ "close": "Cerrar",
+ "gone": "Este appshot ya no se conserva, así que no se puede editar.",
+ "text_placeholder": "Escribe…"
+ }
},
"pets": {
"title": "Mis mascotas",
diff --git a/jarvis/ui/web/frontend/src/lib/appshotApi.ts b/jarvis/ui/web/frontend/src/lib/appshotApi.ts
index 323dda617d..fbdea2541f 100644
--- a/jarvis/ui/web/frontend/src/lib/appshotApi.ts
+++ b/jarvis/ui/web/frontend/src/lib/appshotApi.ts
@@ -80,9 +80,10 @@ export function fetchLatestAppshot(): Promise<{ appshot: AppshotMeta | null }> {
return request<{ appshot: AppshotMeta | null }>("/api/appshot/latest");
}
-export function latestAppshotImageUrl(id: string): string {
- // The id only busts the <img> cache between appshots; the server keeps one.
- return `/api/appshot/latest/image?v=${encodeURIComponent(id)}`;
+export function latestAppshotImageUrl(id: string, revision = 0): string {
+ // The id (and the edit revision) only bust the <img> cache; the server keeps one.
+ const v = revision ? `${id}-${revision}` : id;
+ return `/api/appshot/latest/image?v=${encodeURIComponent(v)}`;
}
export function takeAppshot(
diff --git a/jarvis/ui/web/frontend/src/lib/appshotEditorModel.test.ts b/jarvis/ui/web/frontend/src/lib/appshotEditorModel.test.ts
new file mode 100644
index 0000000000..d362cec143
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/appshotEditorModel.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from "vitest";
+
+import { clampRect, rectFrom, strokeWidths, textSize, viewport, type Op } from "@/lib/appshotEditorModel";
+
+describe("appshot editor model", () => {
+ it("builds the same rectangle for a drag in any direction", () => {
+ expect(rectFrom({ x: 50, y: 40 }, { x: 10, y: 10 })).toEqual({ x: 10, y: 10, w: 40, h: 30 });
+ });
+
+ it("clamps a rectangle to the picture and drops one that leaves nothing", () => {
+ expect(clampRect({ x: -10, y: 5, w: 50, h: 500 }, 100, 80)).toEqual({ x: 0, y: 5, w: 40, h: 75 });
+ expect(clampRect({ x: 120, y: 0, w: 20, h: 20 }, 100, 80)).toBeNull();
+ });
+
+ it("shows the last crop, and the whole picture again once it is undone", () => {
+ const crop: Op = { kind: "crop", rect: { x: 10, y: 10, w: 50, h: 40 } };
+ const pen: Op = { kind: "pen", points: [{ x: 1, y: 1 }], color: "#fff", width: 3 };
+ expect(viewport([pen, crop], 200, 100)).toEqual(crop.rect);
+ expect(viewport([pen], 200, 100)).toEqual({ x: 0, y: 0, w: 200, h: 100 });
+ });
+
+ it("scales stroke and text sizes with the picture", () => {
+ const [small, , large] = strokeWidths(1400, 800);
+ expect(small).toBe(3);
+ expect(large).toBe(11);
+ expect(strokeWidths(2800, 1600)[0]).toBe(6);
+ expect(textSize(6)).toBe(30);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/lib/appshotEditorModel.ts b/jarvis/ui/web/frontend/src/lib/appshotEditorModel.ts
new file mode 100644
index 0000000000..45c8d80baa
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/appshotEditorModel.ts
@@ -0,0 +1,195 @@
+/**
+ * The appshot editor's document: a base picture plus a list of operations,
+ * drawn in the picture's own pixel space. Pure data + one renderer, so the
+ * on-screen canvas and the exported PNG are painted by the same code.
+ *
+ * A crop is an operation too: the last one sets the visible part of the
+ * picture, and undo brings the rest back.
+ */
+
+export type Tool = "arrow" | "rect" | "ellipse" | "pen" | "highlight" | "text" | "pixelate" | "crop";
+
+export interface Point {
+ x: number;
+ y: number;
+}
+
+export interface Rect {
+ x: number;
+ y: number;
+ w: number;
+ h: number;
+}
+
+export type Op =
+ | { kind: "arrow"; from: Point; to: Point; color: string; width: number }
+ | { kind: "rect" | "ellipse"; rect: Rect; color: string; width: number }
+ | { kind: "pen" | "highlight"; points: Point[]; color: string; width: number }
+ | { kind: "text"; at: Point; text: string; color: string; size: number }
+ | { kind: "pixelate"; rect: Rect; block: number }
+ | { kind: "crop"; rect: Rect };
+
+export const COLORS = ["#ef4444", "#f97316", "#facc15", "#22c55e", "#3b82f6", "#ffffff", "#111111"];
+
+/** Stroke widths (S / M / L) for a picture of this size, in its own pixels. */
+export function strokeWidths(width: number, height: number): [number, number, number] {
+ const unit = Math.max(1, Math.max(width, height) / 1400);
+ return [Math.round(3 * unit), Math.round(6 * unit), Math.round(11 * unit)];
+}
+
+export function textSize(stroke: number): number {
+ return Math.max(14, Math.round(stroke * 5));
+}
+
+/** A rectangle from two corners, in any drag direction. */
+export function rectFrom(a: Point, b: Point): Rect {
+ return {
+ x: Math.min(a.x, b.x),
+ y: Math.min(a.y, b.y),
+ w: Math.abs(b.x - a.x),
+ h: Math.abs(b.y - a.y),
+ };
+}
+
+/** The visible part of the picture: the last crop, or all of it. */
+export function viewport(ops: Op[], width: number, height: number): Rect {
+ for (let i = ops.length - 1; i >= 0; i -= 1) {
+ const op = ops[i];
+ if (op.kind === "crop") return op.rect;
+ }
+ return { x: 0, y: 0, w: width, h: height };
+}
+
+/** Clamp a rect to the picture; `null` when nothing of it is left. */
+export function clampRect(rect: Rect, width: number, height: number): Rect | null {
+ const x = Math.max(0, Math.min(width, rect.x));
+ const y = Math.max(0, Math.min(height, rect.y));
+ const right = Math.max(0, Math.min(width, rect.x + rect.w));
+ const bottom = Math.max(0, Math.min(height, rect.y + rect.h));
+ if (right - x < 2 || bottom - y < 2) return null;
+ return { x, y, w: right - x, h: bottom - y };
+}
+
+function arrow(ctx: CanvasRenderingContext2D, from: Point, to: Point, width: number) {
+ const angle = Math.atan2(to.y - from.y, to.x - from.x);
+ const head = Math.max(10, width * 4);
+ const back = { x: to.x - Math.cos(angle) * head * 0.8, y: to.y - Math.sin(angle) * head * 0.8 };
+ ctx.beginPath();
+ ctx.moveTo(from.x, from.y);
+ ctx.lineTo(back.x, back.y);
+ ctx.stroke();
+ ctx.beginPath();
+ ctx.moveTo(to.x, to.y);
+ ctx.lineTo(to.x - Math.cos(angle - 0.45) * head, to.y - Math.sin(angle - 0.45) * head);
+ ctx.lineTo(to.x - Math.cos(angle + 0.45) * head, to.y - Math.sin(angle + 0.45) * head);
+ ctx.closePath();
+ ctx.fill();
+}
+
+function pixelate(ctx: CanvasRenderingContext2D, base: CanvasImageSource, rect: Rect, block: number) {
+ const w = Math.max(1, Math.round(rect.w / block));
+ const h = Math.max(1, Math.round(rect.h / block));
+ const small = document.createElement("canvas");
+ small.width = w;
+ small.height = h;
+ const sctx = small.getContext("2d");
+ if (!sctx) return;
+ sctx.imageSmoothingEnabled = true;
+ sctx.drawImage(base, rect.x, rect.y, rect.w, rect.h, 0, 0, w, h);
+ ctx.save();
+ ctx.imageSmoothingEnabled = false;
+ ctx.drawImage(small, 0, 0, w, h, rect.x, rect.y, rect.w, rect.h);
+ ctx.restore();
+}
+
+/**
+ * Paint the picture and every operation (crops excluded) in picture space.
+ * The caller sets the transform: identity for an export, a scale + offset
+ * for the screen.
+ */
+export function paintOps(ctx: CanvasRenderingContext2D, base: CanvasImageSource, ops: Op[]) {
+ ctx.drawImage(base, 0, 0);
+ for (const op of ops) {
+ ctx.save();
+ ctx.lineCap = "round";
+ ctx.lineJoin = "round";
+ switch (op.kind) {
+ case "arrow":
+ ctx.strokeStyle = op.color;
+ ctx.fillStyle = op.color;
+ ctx.lineWidth = op.width;
+ arrow(ctx, op.from, op.to, op.width);
+ break;
+ case "rect":
+ ctx.strokeStyle = op.color;
+ ctx.lineWidth = op.width;
+ ctx.strokeRect(op.rect.x, op.rect.y, op.rect.w, op.rect.h);
+ break;
+ case "ellipse":
+ ctx.strokeStyle = op.color;
+ ctx.lineWidth = op.width;
+ ctx.beginPath();
+ ctx.ellipse(
+ op.rect.x + op.rect.w / 2,
+ op.rect.y + op.rect.h / 2,
+ Math.max(1, op.rect.w / 2),
+ Math.max(1, op.rect.h / 2),
+ 0,
+ 0,
+ Math.PI * 2,
+ );
+ ctx.stroke();
+ break;
+ case "pen":
+ case "highlight":
+ if (op.points.length === 0) break;
+ ctx.strokeStyle = op.color;
+ ctx.lineWidth = op.kind === "highlight" ? op.width * 4 : op.width;
+ if (op.kind === "highlight") {
+ ctx.globalAlpha = 0.35;
+ ctx.lineCap = "square";
+ }
+ ctx.beginPath();
+ ctx.moveTo(op.points[0].x, op.points[0].y);
+ for (const p of op.points.slice(1)) ctx.lineTo(p.x, p.y);
+ if (op.points.length === 1) ctx.lineTo(op.points[0].x + 0.1, op.points[0].y);
+ ctx.stroke();
+ break;
+ case "text": {
+ ctx.font = `600 ${op.size}px Inter, "Segoe UI", system-ui, sans-serif`;
+ ctx.textBaseline = "top";
+ ctx.fillStyle = op.color;
+ ctx.shadowColor = "rgba(0,0,0,0.45)";
+ ctx.shadowBlur = Math.max(2, op.size / 8);
+ op.text.split("\n").forEach((line, i) => {
+ ctx.fillText(line, op.at.x, op.at.y + i * op.size * 1.25);
+ });
+ break;
+ }
+ case "pixelate":
+ pixelate(ctx, base, op.rect, op.block);
+ break;
+ case "crop":
+ break;
+ }
+ ctx.restore();
+ }
+}
+
+/** Render the finished picture (cropped, with every edit) to a PNG blob. */
+export async function exportPng(
+ base: HTMLImageElement,
+ ops: Op[],
+): Promise<Blob> {
+ const view = viewport(ops, base.naturalWidth, base.naturalHeight);
+ const canvas = document.createElement("canvas");
+ canvas.width = Math.round(view.w);
+ canvas.height = Math.round(view.h);
+ const ctx = canvas.getContext("2d");
+ if (!ctx) throw new Error("No 2D canvas available.");
+ ctx.translate(-view.x, -view.y);
+ paintOps(ctx, base, ops);
+ return await new Promise<Blob>((resolve, reject) =>
+ canvas.toBlob((blob) => (blob ? resolve(blob) : reject(new Error("Export failed."))), "image/png"),
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/store/appshotEditor.ts b/jarvis/ui/web/frontend/src/store/appshotEditor.ts
new file mode 100644
index 0000000000..fbfeff4d93
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/store/appshotEditor.ts
@@ -0,0 +1,19 @@
+/**
+ * Which appshot the editor should open. Set by a click on the appshot card in
+ * the screen corner (the `AppshotEditRequested` event) or on the last appshot
+ * on the Appshots page; the Appshots view renders the editor while it is set.
+ */
+import { create } from "zustand";
+
+interface AppshotEditorState {
+ /** The appshot id to edit, or null when the editor is closed. */
+ openId: string | null;
+ open: (id: string) => void;
+ close: () => void;
+}
+
+export const useAppshotEditor = create<AppshotEditorState>((set) => ({
+ openId: null,
+ open: (id) => set({ openId: id }),
+ close: () => set({ openId: null }),
+}));
diff --git a/jarvis/ui/web/frontend/src/views/AppshotEditor.tsx b/jarvis/ui/web/frontend/src/views/AppshotEditor.tsx
new file mode 100644
index 0000000000..cbd9b6f923
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/views/AppshotEditor.tsx
@@ -0,0 +1,515 @@
+import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
+import {
+ Check,
+ Circle,
+ Copy,
+ Crop,
+ Download,
+ Grid3x3,
+ Highlighter,
+ Loader2,
+ MoveUpRight,
+ Pencil,
+ Redo2,
+ Square,
+ Type,
+ Undo2,
+ X,
+} from "lucide-react";
+
+import { Button } from "@/components/ui/button";
+import { QuickTooltip } from "@/components/ui/tooltip";
+import { useT } from "@/i18n";
+import { latestAppshotImageUrl } from "@/lib/appshotApi";
+import {
+ COLORS,
+ clampRect,
+ exportPng,
+ paintOps,
+ rectFrom,
+ strokeWidths,
+ textSize,
+ viewport,
+ type Op,
+ type Point,
+ type Tool,
+} from "@/lib/appshotEditorModel";
+import { cn } from "@/lib/utils";
+import { useEventStore } from "@/store/events";
+
+/**
+ * The appshot editor — annotate the last appshot the way ShareX's image
+ * editor does: arrow, rectangle, ellipse, pen, highlighter, text, pixelate and
+ * crop, with undo/redo. The result can be copied, saved, or put back in place
+ * of the appshot so the next message carries the edited picture.
+ *
+ * Everything happens in this window's memory; only "Save" writes a file (a
+ * normal download the user asked for).
+ *
+ * Rendered in place (a fixed full-window layer), not portalled: inside the
+ * Settings dialog it then counts as that dialog's nested modal, so its clicks
+ * and Escape never read as "outside" and its text box can take focus.
+ */
+
+const TOOLS: { tool: Tool; icon: typeof Square; key: string }[] = [
+ { tool: "arrow", icon: MoveUpRight, key: "a" },
+ { tool: "rect", icon: Square, key: "r" },
+ { tool: "ellipse", icon: Circle, key: "e" },
+ { tool: "pen", icon: Pencil, key: "p" },
+ { tool: "highlight", icon: Highlighter, key: "h" },
+ { tool: "text", icon: Type, key: "t" },
+ { tool: "pixelate", icon: Grid3x3, key: "b" },
+ { tool: "crop", icon: Crop, key: "c" },
+];
+
+interface Draft {
+ op: Op;
+ start: Point;
+}
+
+function stamp(): string {
+ return new Date().toISOString().replace(/[-:]/g, "").replace(/\..*$/, "").replace("T", "-");
+}
+
+export function AppshotEditor({ appshotId, onClose }: { appshotId: string; onClose: () => void }) {
+ const t = useT();
+ const pushToast = useEventStore((s) => s.pushToast);
+ const [image, setImage] = useState<HTMLImageElement | null>(null);
+ const [failed, setFailed] = useState(false);
+ const [ops, setOps] = useState<Op[]>([]);
+ const [redo, setRedo] = useState<Op[]>([]);
+ const [tool, setTool] = useState<Tool>("arrow");
+ const [color, setColor] = useState(COLORS[0]);
+ const [widthIndex, setWidthIndex] = useState(1);
+ const [draft, setDraftState] = useState<Draft | null>(null);
+ // Pointer events can outrun React's re-render (a quick flick sends its
+ // moves and the release before the press has rendered), so the handlers
+ // read and write the draft through a ref; the state only drives painting.
+ const draftRef = useRef<Draft | null>(null);
+ const setDraft = useCallback((next: Draft | null) => {
+ draftRef.current = next;
+ setDraftState(next);
+ }, []);
+ const [typing, setTyping] = useState<{ at: Point; text: string } | null>(null);
+ const [busy, setBusy] = useState<"" | "copy" | "save" | "apply">("");
+ const stageRef = useRef<HTMLDivElement | null>(null);
+ const canvasRef = useRef<HTMLCanvasElement | null>(null);
+ const [stage, setStage] = useState({ w: 0, h: 0 });
+
+ // -- load ----------------------------------------------------------------
+ useEffect(() => {
+ let alive = true;
+ const img = new Image();
+ img.onload = () => alive && setImage(img);
+ img.onerror = () => alive && setFailed(true);
+ img.src = latestAppshotImageUrl(appshotId);
+ return () => {
+ alive = false;
+ };
+ }, [appshotId]);
+
+ useLayoutEffect(() => {
+ const el = stageRef.current;
+ if (!el) return;
+ const measure = () => setStage({ w: el.clientWidth, h: el.clientHeight });
+ measure();
+ if (typeof ResizeObserver === "undefined") {
+ window.addEventListener("resize", measure);
+ return () => window.removeEventListener("resize", measure);
+ }
+ const observer = new ResizeObserver(measure);
+ observer.observe(el);
+ return () => observer.disconnect();
+ }, []);
+
+ const iw = image?.naturalWidth ?? 0;
+ const ih = image?.naturalHeight ?? 0;
+ const widths = strokeWidths(iw || 1, ih || 1);
+ const width = widths[widthIndex];
+ const view = viewport(ops, iw, ih);
+ // While cropping, show the whole picture so a crop can also grow back.
+ const shown = tool === "crop" ? { x: 0, y: 0, w: iw, h: ih } : view;
+ const scale =
+ shown.w > 0 && stage.w > 0 ? Math.min((stage.w - 48) / shown.w, (stage.h - 48) / shown.h, 1) : 1;
+ const cw = Math.max(1, Math.round(shown.w * scale));
+ const ch = Math.max(1, Math.round(shown.h * scale));
+
+ // -- paint ---------------------------------------------------------------
+ useEffect(() => {
+ const canvas = canvasRef.current;
+ if (!canvas || !image) return;
+ const dpr = window.devicePixelRatio || 1;
+ canvas.width = Math.round(cw * dpr);
+ canvas.height = Math.round(ch * dpr);
+ const ctx = canvas.getContext("2d");
+ if (!ctx) return;
+ ctx.setTransform(dpr * scale, 0, 0, dpr * scale, -shown.x * dpr * scale, -shown.y * dpr * scale);
+ ctx.clearRect(shown.x, shown.y, shown.w, shown.h);
+ const drawn = draft && draft.op.kind !== "crop" ? [...ops, draft.op] : ops;
+ paintOps(ctx, image, drawn.filter((op) => op.kind !== "crop"));
+ if (tool === "crop") {
+ const crop = draft?.op.kind === "crop" ? draft.op.rect : view;
+ ctx.save();
+ ctx.fillStyle = "rgba(0,0,0,0.55)";
+ ctx.beginPath();
+ ctx.rect(0, 0, iw, ih);
+ ctx.rect(crop.x, crop.y, crop.w, crop.h);
+ ctx.fill("evenodd");
+ ctx.strokeStyle = "#ffffff";
+ ctx.lineWidth = 1.5 / scale;
+ ctx.setLineDash([6 / scale, 4 / scale]);
+ ctx.strokeRect(crop.x, crop.y, crop.w, crop.h);
+ ctx.restore();
+ }
+ }, [image, ops, draft, tool, cw, ch, scale, shown.x, shown.y, shown.w, shown.h, iw, ih, view]);
+
+ // -- editing -------------------------------------------------------------
+ const push = useCallback((op: Op) => {
+ setOps((prev) => [...prev, op]);
+ setRedo([]);
+ }, []);
+
+ const undo = useCallback(() => {
+ if (ops.length === 0) return;
+ setRedo([...redo, ops[ops.length - 1]]);
+ setOps(ops.slice(0, -1));
+ }, [ops, redo]);
+
+ const redoOne = useCallback(() => {
+ if (redo.length === 0) return;
+ setOps([...ops, redo[redo.length - 1]]);
+ setRedo(redo.slice(0, -1));
+ }, [ops, redo]);
+
+ const toImage = (event: React.PointerEvent): Point => {
+ const rect = canvasRef.current!.getBoundingClientRect();
+ return {
+ x: shown.x + (event.clientX - rect.left) / scale,
+ y: shown.y + (event.clientY - rect.top) / scale,
+ };
+ };
+
+ const commitText = useCallback(() => {
+ setTyping((current) => {
+ if (current && current.text.trim()) {
+ push({ kind: "text", at: current.at, text: current.text, color, size: textSize(width) });
+ }
+ return null;
+ });
+ }, [color, push, width]);
+
+ const onPointerDown = (event: React.PointerEvent) => {
+ if (!image || event.button !== 0) return;
+ const p = toImage(event);
+ if (tool === "text") {
+ // Keep the press from moving focus to the dialog behind the canvas: it
+ // would blur (and so close) the text box this click is about to open.
+ event.preventDefault();
+ if (typing) commitText();
+ setTyping({ at: p, text: "" });
+ return;
+ }
+ (event.target as Element).setPointerCapture(event.pointerId);
+ const zero = { x: p.x, y: p.y, w: 0, h: 0 };
+ let op: Op;
+ switch (tool) {
+ case "arrow":
+ op = { kind: "arrow", from: p, to: p, color, width };
+ break;
+ case "rect":
+ case "ellipse":
+ op = { kind: tool, rect: zero, color, width };
+ break;
+ case "pen":
+ case "highlight":
+ op = { kind: tool, points: [p], color, width };
+ break;
+ case "pixelate":
+ op = { kind: "pixelate", rect: zero, block: Math.max(6, width * 2) };
+ break;
+ default:
+ op = { kind: "crop", rect: zero };
+ }
+ setDraft({ op, start: p });
+ };
+
+ const onPointerMove = (event: React.PointerEvent) => {
+ const draft = draftRef.current;
+ if (!draft) return;
+ const p = toImage(event);
+ const op = draft.op;
+ let next: Op = op;
+ if (op.kind === "arrow") next = { ...op, to: p };
+ else if (op.kind === "pen" || op.kind === "highlight") next = { ...op, points: [...op.points, p] };
+ else if (op.kind === "rect" || op.kind === "ellipse" || op.kind === "pixelate" || op.kind === "crop") {
+ next = { ...op, rect: rectFrom(draft.start, p) };
+ }
+ setDraft({ ...draft, op: next });
+ };
+
+ const onPointerUp = () => {
+ const draft = draftRef.current;
+ if (!draft) return;
+ const op = draft.op;
+ setDraft(null);
+ if (op.kind === "arrow" && Math.hypot(op.to.x - op.from.x, op.to.y - op.from.y) < 4) return;
+ if ("rect" in op) {
+ const rect = clampRect(op.rect, iw, ih);
+ if (!rect || rect.w < 4 || rect.h < 4) return;
+ push({ ...op, rect } as Op);
+ if (op.kind === "crop") setTool("arrow");
+ return;
+ }
+ push(op);
+ };
+
+ // -- results -------------------------------------------------------------
+ const render = useCallback(async () => {
+ if (!image) throw new Error(t("appshots.editor.gone"));
+ return await exportPng(image, ops);
+ }, [image, ops, t]);
+
+ const copy = useCallback(async () => {
+ setBusy("copy");
+ try {
+ const blob = await render();
+ // A browser that waits for focus or a permission never settles this
+ // promise; the button must not spin forever.
+ await Promise.race([
+ navigator.clipboard.write([new ClipboardItem({ "image/png": blob })]),
+ new Promise((_, reject) =>
+ window.setTimeout(() => reject(new Error(t("appshots.editor.copy_timeout"))), 5000),
+ ),
+ ]);
+ pushToast("success", t("appshots.editor.copied"));
+ } catch (error) {
+ pushToast("error", t("appshots.editor.copy_failed").replace("{0}", (error as Error).message));
+ } finally {
+ setBusy("");
+ }
+ }, [pushToast, render, t]);
+
+ const save = useCallback(async () => {
+ setBusy("save");
+ try {
+ const blob = await render();
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = `appshot-${stamp()}.png`;
+ document.body.appendChild(a);
+ a.click();
+ a.remove();
+ window.setTimeout(() => URL.revokeObjectURL(url), 10_000);
+ } catch (error) {
+ pushToast("error", (error as Error).message);
+ } finally {
+ setBusy("");
+ }
+ }, [pushToast, render]);
+
+ const apply = useCallback(async () => {
+ setBusy("apply");
+ try {
+ const blob = await render();
+ const response = await fetch(`/api/appshot/latest/image?id=${encodeURIComponent(appshotId)}`, {
+ method: "PUT",
+ headers: { "content-type": "image/png" },
+ body: blob,
+ });
+ if (!response.ok) {
+ const body = (await response.json().catch(() => null)) as { detail?: string } | null;
+ throw new Error(body?.detail || `HTTP ${response.status}`);
+ }
+ pushToast("success", t("appshots.editor.applied"));
+ onClose();
+ } catch (error) {
+ pushToast("error", (error as Error).message);
+ } finally {
+ setBusy("");
+ }
+ }, [appshotId, onClose, pushToast, render, t]);
+
+ // -- keyboard ------------------------------------------------------------
+ useEffect(() => {
+ const onKey = (event: KeyboardEvent) => {
+ if (typing) return; // the text box owns the keys while it is open
+ const mod = event.ctrlKey || event.metaKey;
+ const key = event.key.toLowerCase();
+ if (event.key === "Escape") {
+ event.preventDefault();
+ if (draftRef.current) setDraft(null);
+ else onClose();
+ } else if (mod && key === "z" && !event.shiftKey) {
+ event.preventDefault();
+ undo();
+ } else if (mod && (key === "y" || (key === "z" && event.shiftKey))) {
+ event.preventDefault();
+ redoOne();
+ } else if (mod && key === "c") {
+ event.preventDefault();
+ void copy();
+ } else if (mod && key === "s") {
+ event.preventDefault();
+ void save();
+ } else if (!mod && !event.altKey) {
+ const hit = TOOLS.find((entry) => entry.key === key);
+ if (hit) setTool(hit.tool);
+ }
+ };
+ window.addEventListener("keydown", onKey);
+ return () => window.removeEventListener("keydown", onKey);
+ }, [copy, onClose, redoOne, save, setDraft, typing, undo]);
+
+ const toolLabel = (name: Tool) => t(`appshots.editor.tool_${name}`);
+ const textScreen = typing
+ ? { left: (typing.at.x - shown.x) * scale, top: (typing.at.y - shown.y) * scale }
+ : null;
+
+ return (
+ <div
+ className="fixed inset-0 z-[80] flex flex-col bg-background/95 backdrop-blur-sm"
+ role="dialog"
+ aria-modal="true"
+ aria-label={t("appshots.editor.title")}
+ data-testid="appshot-editor"
+ >
+ <div className="flex shrink-0 items-center gap-3 border-b border-border px-4 py-2.5">
+ <p className="mr-2 text-base font-medium text-foreground">{t("appshots.editor.title")}</p>
+
+ <div className="flex items-center gap-0.5 rounded-lg bg-secondary/60 p-0.5" role="toolbar">
+ {TOOLS.map(({ tool: name, icon: Icon, key }) => (
+ <QuickTooltip key={name} content={`${toolLabel(name)} (${key.toUpperCase()})`} side="bottom">
+ <button
+ type="button"
+ aria-label={toolLabel(name)}
+ aria-pressed={tool === name}
+ onClick={() => setTool(name)}
+ data-testid={`appshot-editor-tool-${name}`}
+ className={cn(
+ "flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors",
+ "hover:bg-popover hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong",
+ tool === name && "bg-popover text-foreground shadow-sm",
+ )}
+ >
+ <Icon className="h-4 w-4" aria-hidden />
+ </button>
+ </QuickTooltip>
+ ))}
+ </div>
+
+ <div className="flex items-center gap-1.5" aria-label={t("appshots.editor.color")}>
+ {COLORS.map((swatch) => (
+ <button
+ key={swatch}
+ type="button"
+ aria-label={swatch}
+ aria-pressed={color === swatch}
+ onClick={() => setColor(swatch)}
+ className={cn(
+ "h-5 w-5 rounded-full border border-border transition-transform focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong",
+ color === swatch && "scale-110 ring-2 ring-foreground/70 ring-offset-2 ring-offset-background",
+ )}
+ style={{ backgroundColor: swatch }}
+ />
+ ))}
+ </div>
+
+ <div className="flex items-center gap-0.5 rounded-lg bg-secondary/60 p-0.5" aria-label={t("appshots.editor.size")}>
+ {[0, 1, 2].map((index) => (
+ <button
+ key={index}
+ type="button"
+ aria-label={`${t("appshots.editor.size")} ${index + 1}`}
+ aria-pressed={widthIndex === index}
+ onClick={() => setWidthIndex(index)}
+ className={cn(
+ "flex h-8 w-8 items-center justify-center rounded-md transition-colors hover:bg-popover",
+ widthIndex === index && "bg-popover shadow-sm",
+ )}
+ >
+ <span className="rounded-full bg-foreground" style={{ width: 4 + index * 4, height: 4 + index * 4 }} />
+ </button>
+ ))}
+ </div>
+
+ <div className="flex items-center gap-0.5">
+ <QuickTooltip content={`${t("appshots.editor.undo")} (Ctrl+Z)`} side="bottom">
+ <Button type="button" variant="ghost" size="sm" onClick={undo} disabled={ops.length === 0} aria-label={t("appshots.editor.undo")}>
+ <Undo2 aria-hidden />
+ </Button>
+ </QuickTooltip>
+ <QuickTooltip content={`${t("appshots.editor.redo")} (Ctrl+Y)`} side="bottom">
+ <Button type="button" variant="ghost" size="sm" onClick={redoOne} disabled={redo.length === 0} aria-label={t("appshots.editor.redo")}>
+ <Redo2 aria-hidden />
+ </Button>
+ </QuickTooltip>
+ </div>
+
+ <div className="ml-auto flex items-center gap-2">
+ <Button type="button" variant="secondary" size="sm" onClick={() => void copy()} disabled={!image || busy !== ""} data-testid="appshot-editor-copy">
+ {busy === "copy" ? <Loader2 className="animate-spin" aria-hidden /> : <Copy aria-hidden />}
+ {t("appshots.editor.copy")}
+ </Button>
+ <Button type="button" variant="secondary" size="sm" onClick={() => void save()} disabled={!image || busy !== ""} data-testid="appshot-editor-save">
+ {busy === "save" ? <Loader2 className="animate-spin" aria-hidden /> : <Download aria-hidden />}
+ {t("appshots.editor.save")}
+ </Button>
+ <Button type="button" size="sm" onClick={() => void apply()} disabled={!image || busy !== ""} data-testid="appshot-editor-apply">
+ {busy === "apply" ? <Loader2 className="animate-spin" aria-hidden /> : <Check aria-hidden />}
+ {t("appshots.editor.apply")}
+ </Button>
+ <Button type="button" variant="ghost" size="sm" onClick={onClose} aria-label={t("appshots.editor.close")} data-testid="appshot-editor-close">
+ <X aria-hidden />
+ </Button>
+ </div>
+ </div>
+
+ <div ref={stageRef} className="relative flex min-h-0 flex-1 items-center justify-center overflow-hidden">
+ {failed ? (
+ <p className="text-base text-muted-foreground">{t("appshots.editor.gone")}</p>
+ ) : !image ? (
+ <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" aria-hidden />
+ ) : (
+ <div className="relative shadow-2xl ring-1 ring-border" style={{ width: cw, height: ch }}>
+ <canvas
+ ref={canvasRef}
+ style={{ width: cw, height: ch, cursor: tool === "text" ? "text" : "crosshair", touchAction: "none" }}
+ onPointerDown={onPointerDown}
+ onPointerMove={onPointerMove}
+ onPointerUp={onPointerUp}
+ data-testid="appshot-editor-canvas"
+ />
+ {typing && textScreen && (
+ <textarea
+ autoFocus
+ value={typing.text}
+ placeholder={t("appshots.editor.text_placeholder")}
+ onChange={(event) => setTyping({ ...typing, text: event.target.value })}
+ onBlur={commitText}
+ onKeyDown={(event) => {
+ if (event.key === "Enter" && !event.shiftKey) {
+ event.preventDefault();
+ commitText();
+ } else if (event.key === "Escape") {
+ event.preventDefault();
+ setTyping(null);
+ }
+ }}
+ rows={1}
+ className="absolute resize-none border border-dashed border-white/70 bg-black/20 p-0 font-semibold leading-tight outline-none placeholder:text-white/50"
+ style={{
+ left: textScreen.left,
+ top: textScreen.top,
+ color,
+ fontSize: textSize(width) * scale,
+ minWidth: 120,
+ }}
+ />
+ )}
+ </div>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/views/AppshotsView.test.tsx b/jarvis/ui/web/frontend/src/views/AppshotsView.test.tsx
index 6b81a09bdc..fe99484c06 100644
--- a/jarvis/ui/web/frontend/src/views/AppshotsView.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/AppshotsView.test.tsx
@@ -2,6 +2,7 @@ import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/re
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { formatAppshotHotkey } from "@/lib/appshotApi";
+import { useAppshotEditor } from "@/store/appshotEditor";
import { useEventStore } from "@/store/events";
import { AppshotsView } from "@/views/AppshotsView";
@@ -221,6 +222,59 @@ describe("AppshotsView shortcut recorder", () => {
});
});
+describe("AppshotsView editor", () => {
+ const SHOT = {
+ id: "shot-1",
+ width: 800,
+ height: 500,
+ label: "selected area",
+ app_name: "Editor",
+ trigger: "hotkey",
+ taken_at: 1_700_000_000,
+ delivered_to: "message",
+ };
+
+ beforeEach(() => {
+ useEventStore.setState({ events: [], toasts: [], assistantName: "Jarvis" });
+ useAppshotEditor.setState({ openId: null });
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async (url: string) => {
+ if (url === "/api/appshot/settings") return json(SETTINGS);
+ if (url === "/api/appshot/latest") return json({ appshot: SHOT });
+ return json({}, 404);
+ }),
+ );
+ });
+
+ afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ });
+
+ it("opens from the last appshot and closes on Escape", async () => {
+ render(<AppshotsView />);
+ fireEvent.click(await screen.findByTestId("appshots-preview-edit"));
+ expect(await screen.findByTestId("appshot-editor")).toBeDefined();
+ expect(useAppshotEditor.getState().openId).toBe("shot-1");
+
+ fireEvent.keyDown(window, { key: "r" });
+ expect(
+ screen.getByTestId("appshot-editor-tool-rect").getAttribute("aria-pressed"),
+ ).toBe("true");
+
+ fireEvent.keyDown(window, { key: "Escape" });
+ await waitFor(() => expect(screen.queryByTestId("appshot-editor")).toBeNull());
+ expect(useAppshotEditor.getState().openId).toBeNull();
+ });
+
+ it("opens when the card in the screen corner asked for it", async () => {
+ useAppshotEditor.getState().open("shot-1");
+ render(<AppshotsView />);
+ expect(await screen.findByTestId("appshot-editor")).toBeDefined();
+ });
+});
+
describe("formatAppshotHotkey", () => {
it("names the both-Alt gesture per platform", () => {
expect(formatAppshotHotkey("alt+alt", false)).toBe("Alt + Alt");
diff --git a/jarvis/ui/web/frontend/src/views/AppshotsView.tsx b/jarvis/ui/web/frontend/src/views/AppshotsView.tsx
index 004dfd7551..a0f66a83f4 100644
--- a/jarvis/ui/web/frontend/src/views/AppshotsView.tsx
+++ b/jarvis/ui/web/frontend/src/views/AppshotsView.tsx
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
-import { Loader2, Trash2 } from "lucide-react";
+import { Loader2, PenLine, Trash2 } from "lucide-react";
import { PageHeader } from "@/components/layout/PageHeader";
import { Button } from "@/components/ui/button";
@@ -21,7 +21,9 @@ import {
import { gestureFamily } from "@/lib/appshotChord";
import { cn } from "@/lib/utils";
import { AppshotShortcutField } from "@/views/AppshotShortcutField";
+import { useAppshotEditor } from "@/store/appshotEditor";
import { useEventStore } from "@/store/events";
+import { AppshotEditor } from "@/views/AppshotEditor";
/**
* Appshots — show the assistant the window you are working in.
@@ -147,7 +149,17 @@ function deliveredLabel(t: (key: string) => string, deliveredTo: string): string
}
}
-function LatestPreview({ shot, onForget }: { shot: AppshotMeta; onForget: () => void }) {
+function LatestPreview({
+ shot,
+ revision,
+ onForget,
+ onEdit,
+}: {
+ shot: AppshotMeta;
+ revision: number;
+ onForget: () => void;
+ onEdit: () => void;
+}) {
const t = useT();
const time = new Date(shot.taken_at * 1000).toLocaleTimeString([], {
hour: "2-digit",
@@ -157,13 +169,19 @@ function LatestPreview({ shot, onForget }: { shot: AppshotMeta; onForget: () =>
const delivered = deliveredLabel(t, shot.delivered_to);
return (
<div className="flex h-full flex-col">
- <div className="flex aspect-[16/10] w-full items-center justify-center overflow-hidden rounded-lg bg-secondary/60 p-3">
+ <button
+ type="button"
+ onClick={onEdit}
+ title={t("appshots.editor.open")}
+ className="group flex aspect-[16/10] w-full items-center justify-center overflow-hidden rounded-lg bg-secondary/60 p-3 focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong"
+ data-testid="appshots-preview-edit"
+ >
<img
- src={latestAppshotImageUrl(shot.id)}
+ src={latestAppshotImageUrl(shot.id, revision)}
alt={t("appshots.preview_alt").replace("{0}", where)}
- className="max-h-full max-w-full rounded-md object-contain shadow-sm ring-1 ring-border"
+ className="max-h-full max-w-full rounded-md object-contain shadow-sm ring-1 ring-border transition-opacity group-hover:opacity-90"
/>
- </div>
+ </button>
<div className="mt-3 flex items-start justify-between gap-3">
<div className="min-w-0">
<p className="truncate text-base font-medium text-foreground">{where}</p>
@@ -171,10 +189,16 @@ function LatestPreview({ shot, onForget }: { shot: AppshotMeta; onForget: () =>
{[time, `${shot.width} × ${shot.height}`, delivered].filter(Boolean).join(" · ")}
</p>
</div>
- <Button type="button" variant="ghost" size="sm" onClick={onForget}>
- <Trash2 aria-hidden />
- {t("appshots.forget")}
- </Button>
+ <div className="flex shrink-0 items-center gap-1">
+ <Button type="button" variant="ghost" size="sm" onClick={onEdit}>
+ <PenLine aria-hidden />
+ {t("appshots.editor.open")}
+ </Button>
+ <Button type="button" variant="ghost" size="sm" onClick={onForget}>
+ <Trash2 aria-hidden />
+ {t("appshots.forget")}
+ </Button>
+ </div>
</div>
</div>
);
@@ -191,6 +215,10 @@ export function AppshotsView() {
const [saving, setSaving] = useState(false);
const [countdown, setCountdown] = useState<number | null>(null);
const [picking, setPicking] = useState(false);
+ const editorId = useAppshotEditor((s) => s.openId);
+ const openEditor = useAppshotEditor((s) => s.open);
+ const closeEditor = useAppshotEditor((s) => s.close);
+ const [revision, setRevision] = useState(0);
// While a shortcut field records (or refuses a gesture), its row says so
// in place of the description.
const [fieldStatus, setFieldStatus] = useState<{ window: string | null; region: string | null }>({
@@ -532,12 +560,34 @@ export function AppshotsView() {
<div className="rounded-xl border border-border bg-card p-5">
<p className="mb-3 text-base font-medium text-foreground">{t("appshots.preview_title")}</p>
- {latest ? <LatestPreview shot={latest} onForget={() => void forget()} /> : <PreviewDemo />}
+ {latest ? (
+ <LatestPreview
+ shot={latest}
+ revision={revision}
+ onForget={() => void forget()}
+ onEdit={() => openEditor(latest.id)}
+ />
+ ) : (
+ <PreviewDemo />
+ )}
</div>
</div>
<p className="mt-5 text-sm text-muted-foreground">{t("appshots.voice_hint")}</p>
</div>
+ {editorId !== null && (
+ <AppshotEditor
+ appshotId={editorId}
+ onClose={() => {
+ closeEditor();
+ // An applied edit changed the held picture: show the new one.
+ setRevision((n) => n + 1);
+ fetchLatestAppshot()
+ .then((body) => setLatest(body.appshot))
+ .catch(() => undefined);
+ }}
+ />
+ )}
</div>
);
}