) => void;
};
@@ -14,6 +15,7 @@ const handles: readonly ResizeHandle[] = ["nw", "n", "ne", "e", "se", "s", "sw",
export function SelectionFrame({
rect,
children,
+ motionStyle,
onMoveStart,
onResizeStart,
}: SelectionFrameProps): React.JSX.Element {
@@ -21,7 +23,7 @@ export function SelectionFrame({
{children}
diff --git a/apps/desktop/src/components/dashboard/DashboardPanel.test.tsx b/apps/desktop/src/components/dashboard/DashboardPanel.test.tsx
index abe61c8..0d9a3ad 100644
--- a/apps/desktop/src/components/dashboard/DashboardPanel.test.tsx
+++ b/apps/desktop/src/components/dashboard/DashboardPanel.test.tsx
@@ -117,7 +117,7 @@ describe("DashboardPanel", () => {
resets += screen.getAllByRole("button", { name: "Reset this section" }).length;
}
- expect(resets).toBe(11);
+ expect(resets).toBe(12);
});
it("provides inline resets for overlay tint and individual shortcuts", () => {
@@ -391,7 +391,7 @@ describe("DashboardPanel", () => {
/** Section titles per tab, in the order each tab shows them. */
const sectionTitles = {
- General: ["Open at startup", "Theme accent", "Saved captures", "Saved recordings"],
+ General: ["Open at startup", "Keep CapKit current", "Theme accent", "Saved captures", "Saved recordings"],
Screenshots: [
"Choose what stays within reach",
"Colors & default size",
diff --git a/apps/desktop/src/components/dashboard/DashboardPanel.tsx b/apps/desktop/src/components/dashboard/DashboardPanel.tsx
index 311436c..55b64f9 100644
--- a/apps/desktop/src/components/dashboard/DashboardPanel.tsx
+++ b/apps/desktop/src/components/dashboard/DashboardPanel.tsx
@@ -1,13 +1,15 @@
import { getVersion } from "@tauri-apps/api/app";
import { invoke, isTauri } from "@tauri-apps/api/core";
-import { useEffect, useState } from "react";
+import { useCallback, useEffect, useState } from "react";
import { useSnaphubSettings } from "../../domain/settings";
-import { updateGlobalShortcuts } from "../../lib/tauri";
+import { listSavedCaptures, listenForShowcaseRequest, takePendingShowcase, updateGlobalShortcuts } from "../../lib/tauri";
import { SettingsView } from "./SettingsView";
+import { UpdateNotice } from "./UpdateNotice";
+import { useUpdateStatus } from "./useUpdateStatus";
import { SavedCapturesView } from "./SavedCapturesView";
import { ShowcaseView } from "./ShowcaseView";
import { RecordView } from "./RecordView";
-import type { SavedCapture } from "../../domain/capture";
+import { findSavedCapture, type SavedCapture } from "../../domain/capture";
import {
Image,
Moon,
@@ -30,8 +32,13 @@ const navigation = [
export function DashboardPanel(): React.JSX.Element {
const [activeTab, setActiveTab] = useState("screenshots");
const [showcaseCapture, setShowcaseCapture] = useState(null);
+ const [isShowcaseStylePending, setIsShowcaseStylePending] = useState(false);
const [version, setVersion] = useState(null);
const { settings, updateSettings } = useSnaphubSettings();
+ const updates = useUpdateStatus(settings.updates.autoCheck);
+ const clearShowcaseStylePending = useCallback((): void => {
+ setIsShowcaseStylePending(false);
+ }, []);
useEffect(() => {
let cancelled = false;
@@ -57,6 +64,34 @@ export function DashboardPanel(): React.JSX.Element {
return (): void => window.cancelAnimationFrame(frame);
}, []);
+ // A capture sent from the completion rail. Pulled on mount, because a freshly
+ // built dashboard missed the event, and again whenever an open one is asked.
+ // The take is one-shot, so the result is applied even after a cleanup:
+ // StrictMode's rehearsal unmount would otherwise discard the only copy.
+ useEffect(() => {
+ if (!isTauri()) return;
+ const openPending = async (): Promise => {
+ const path = await takePendingShowcase();
+ if (path === null) return;
+ const captures = await listSavedCaptures();
+ setShowcaseCapture(findSavedCapture(captures, path));
+ setIsShowcaseStylePending(true);
+ setActiveTab("showcase");
+ };
+ const report = (error: unknown): void => {
+ console.error("SH-SHOWCASE-PENDING-001", error);
+ };
+ void openPending().catch(report);
+ const unlisten = listenForShowcaseRequest(() => {
+ void openPending().catch(report);
+ });
+ return (): void => {
+ void unlisten.then((stop) => {
+ stop();
+ });
+ };
+ }, []);
+
useEffect(() => {
if (!isTauri()) return;
void updateGlobalShortcuts(settings.shortcuts).catch((error: unknown) => {
@@ -126,6 +161,7 @@ export function DashboardPanel(): React.JSX.Element {
);
})}
+
Ready in the system tray
@@ -139,11 +175,16 @@ export function DashboardPanel(): React.JSX.Element {
{
setShowcaseCapture(capture ?? null);
+ setIsShowcaseStylePending(true);
setActiveTab("showcase");
}}
/>
) : activeTab === "showcase" ? (
-
+
) : activeTab === "settings" ? (
) : (
diff --git a/apps/desktop/src/components/dashboard/RecordView.test.tsx b/apps/desktop/src/components/dashboard/RecordView.test.tsx
index a641a0d..5343d94 100644
--- a/apps/desktop/src/components/dashboard/RecordView.test.tsx
+++ b/apps/desktop/src/components/dashboard/RecordView.test.tsx
@@ -26,6 +26,8 @@ const track: CursorTrack = {
ys: [10, 300],
events: [{ time: 1, kind: "down", button: "left", x: 400, y: 300 }],
shapes: [{ time: 0, shape: "default" }],
+ keysRecorded: false,
+ keys: [],
displayBounds: { x: 0, y: 0, width: 1920, height: 1080 },
scaleFactor: 1,
};
diff --git a/apps/desktop/src/components/dashboard/RecordingPreview.test.tsx b/apps/desktop/src/components/dashboard/RecordingPreview.test.tsx
index 574c206..f0ade04 100644
--- a/apps/desktop/src/components/dashboard/RecordingPreview.test.tsx
+++ b/apps/desktop/src/components/dashboard/RecordingPreview.test.tsx
@@ -26,6 +26,8 @@ const track: CursorTrack = {
ys: [10, 300],
events: [],
shapes: [{ time: 0, shape: "default" }],
+ keysRecorded: false,
+ keys: [],
displayBounds: { x: 0, y: 0, width: 1920, height: 1080 },
scaleFactor: 1,
};
diff --git a/apps/desktop/src/components/dashboard/SavedCapturesView.test.tsx b/apps/desktop/src/components/dashboard/SavedCapturesView.test.tsx
index 8677b2b..788c424 100644
--- a/apps/desktop/src/components/dashboard/SavedCapturesView.test.tsx
+++ b/apps/desktop/src/components/dashboard/SavedCapturesView.test.tsx
@@ -1,8 +1,10 @@
-import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { SavedCapturesView } from "./SavedCapturesView";
const mocks = vi.hoisted(() => ({
+ copyCapture: vi.fn<(path: string) => Promise>(() => Promise.resolve()),
+ startDrag: vi.fn<(path: string) => Promise>(() => Promise.resolve()),
deleteCapture: vi.fn<() => Promise>(() => Promise.resolve()),
listCaptures: vi.fn(() => Promise.resolve([{
path: "C:/Pictures/Snaphub/capture.png",
@@ -19,6 +21,8 @@ const mocks = vi.hoisted(() => ({
}));
vi.mock("../../lib/tauri", () => ({
+ copySavedCapture: mocks.copyCapture,
+ startSavedCaptureDrag: mocks.startDrag,
deleteSavedCapture: mocks.deleteCapture,
describeInvokeError: (_error: unknown, fallback: string): string => fallback,
getSaveDirectory: (): Promise => Promise.resolve("C:/Pictures/Snaphub"),
@@ -31,7 +35,13 @@ vi.mock("../../lib/tauri", () => ({
vi.mock("@tauri-apps/plugin-dialog", () => ({ confirm: (): Promise => Promise.resolve(true) }));
describe("SavedCapturesView", () => {
- afterEach(() => cleanup());
+ afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+ mocks.copyCapture.mockClear();
+ mocks.startDrag.mockClear();
+ mocks.openCapture.mockClear();
+ });
it("opens folders and images and exposes the requested context actions", async () => {
const onShowcase = vi.fn();
@@ -83,4 +93,92 @@ describe("SavedCapturesView", () => {
const grid = document.querySelector("section div.mt-5.grid");
expect(grid?.className).toContain("2xl:grid-cols-5");
});
+
+ it("copies from the card button without opening the image, then shows Copied for 1.5 s", async () => {
+ render();
+ await screen.findByRole("button", { name: "View capture.png" });
+ vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
+
+ await act(async () => {
+ fireEvent.click(screen.getByRole("button", { name: "Copy capture.png" }));
+ await Promise.resolve();
+ });
+ expect(mocks.copyCapture).toHaveBeenCalledWith("C:/Pictures/Snaphub/capture.png");
+ expect(mocks.openCapture).not.toHaveBeenCalled();
+ expect(screen.getByRole("button", { name: "Copy capture.png" })).toHaveTextContent("Copied");
+
+ act(() => {
+ vi.advanceTimersByTime(1500);
+ });
+ expect(screen.getByRole("button", { name: "Copy capture.png" })).toHaveTextContent("Copy");
+ expect(screen.getByRole("button", { name: "Copy capture.png" })).not.toHaveTextContent("Copied");
+ });
+
+ it("copies from the context menu and closes it", async () => {
+ render();
+ const capture = await screen.findByRole("button", { name: "View capture.png" });
+ fireEvent.contextMenu(capture, { clientX: 140, clientY: 120 });
+ const items = screen.getAllByRole("menuitem").map((item) => item.textContent);
+ expect(items).toEqual(["View", "Copy", "Showcase", "Delete"]);
+
+ fireEvent.click(screen.getByRole("menuitem", { name: "Copy" }));
+ await waitFor(() => expect(mocks.copyCapture).toHaveBeenCalledOnce());
+ expect(screen.queryByRole("menu")).toBeNull();
+ });
+
+ it("copies the focused card with Ctrl+C", async () => {
+ render();
+ const capture = await screen.findByRole("button", { name: "View capture.png" });
+ fireEvent.keyDown(capture, { key: "c", ctrlKey: true });
+ await waitFor(() => expect(mocks.copyCapture).toHaveBeenCalledOnce());
+ fireEvent.keyDown(document.body, { key: "c", ctrlKey: true });
+ expect(mocks.copyCapture).toHaveBeenCalledOnce();
+ });
+
+ it("shows the error banner and refreshes when a copy fails", async () => {
+ mocks.copyCapture.mockRejectedValueOnce(new Error("gone"));
+ render();
+ await screen.findByRole("button", { name: "View capture.png" });
+ const listCalls = mocks.listCaptures.mock.calls.length;
+
+ fireEvent.click(screen.getByRole("button", { name: "Copy capture.png" }));
+ expect(await screen.findByRole("alert")).toHaveTextContent("Couldn't copy this capture.");
+ await waitFor(() => expect(mocks.listCaptures.mock.calls.length).toBeGreaterThan(listCalls));
+ });
+
+ it("opens the image when the pointer moves less than 5 px", async () => {
+ render();
+ const capture = await screen.findByRole("button", { name: "View capture.png" });
+ fireEvent.pointerDown(capture, { button: 0, buttons: 1, clientX: 10, clientY: 10, pointerId: 1 });
+ fireEvent.pointerMove(capture, { buttons: 1, clientX: 13, clientY: 12, pointerId: 1 });
+ fireEvent.pointerUp(capture, { button: 0, clientX: 13, clientY: 12, pointerId: 1 });
+ fireEvent.click(capture);
+ expect(mocks.startDrag).not.toHaveBeenCalled();
+ expect(mocks.openCapture).toHaveBeenCalledOnce();
+ });
+
+ it("starts one native drag after 5 px of movement and suppresses the following click", async () => {
+ render();
+ const capture = await screen.findByRole("button", { name: "View capture.png" });
+ fireEvent.pointerDown(capture, { button: 0, buttons: 1, clientX: 10, clientY: 10, pointerId: 1 });
+ fireEvent.pointerMove(capture, { buttons: 1, clientX: 16, clientY: 10, pointerId: 1 });
+ fireEvent.pointerMove(capture, { buttons: 1, clientX: 30, clientY: 10, pointerId: 1 });
+ expect(mocks.startDrag).toHaveBeenCalledOnce();
+ expect(mocks.startDrag).toHaveBeenCalledWith("C:/Pictures/Snaphub/capture.png");
+
+ fireEvent.click(capture);
+ expect(mocks.openCapture).not.toHaveBeenCalled();
+ fireEvent.pointerDown(capture, { button: 0, buttons: 1, clientX: 10, clientY: 10, pointerId: 2 });
+ fireEvent.click(capture);
+ expect(mocks.openCapture).toHaveBeenCalledOnce();
+ });
+
+ it("shows an error banner when the drag cannot start", async () => {
+ mocks.startDrag.mockRejectedValueOnce(new Error("no"));
+ render();
+ const capture = await screen.findByRole("button", { name: "View capture.png" });
+ fireEvent.pointerDown(capture, { button: 0, buttons: 1, clientX: 0, clientY: 0, pointerId: 1 });
+ fireEvent.pointerMove(capture, { buttons: 1, clientX: 20, clientY: 0, pointerId: 1 });
+ expect(await screen.findByRole("alert")).toHaveTextContent("Couldn't start dragging this capture.");
+ });
});
diff --git a/apps/desktop/src/components/dashboard/SavedCapturesView.tsx b/apps/desktop/src/components/dashboard/SavedCapturesView.tsx
index 52ab0a7..1c7321f 100644
--- a/apps/desktop/src/components/dashboard/SavedCapturesView.tsx
+++ b/apps/desktop/src/components/dashboard/SavedCapturesView.tsx
@@ -2,6 +2,7 @@ import { confirm } from "@tauri-apps/plugin-dialog";
import { useCallback, useEffect, useRef, useState } from "react";
import type { SavedCapture } from "../../domain/capture";
import {
+ copySavedCapture,
describeInvokeError,
deleteSavedCapture,
getSaveDirectory,
@@ -9,9 +10,12 @@ import {
listenForSavedCapture,
openSaveDirectory,
openSavedCapture,
+ startSavedCaptureDrag,
} from "../../lib/tauri";
import {
Clock as Clock3,
+ Copy,
+ Tick as Check,
Delete as Trash2,
FolderOpen,
HardDrive,
@@ -96,6 +100,27 @@ export function SavedCapturesView({ onShowcase }: SavedCapturesViewProps): React
}
}
+ async function copyCapture(capture: SavedCapture): Promise {
+ setMenu(null);
+ setActionError(null);
+ try {
+ await copySavedCapture(capture.path);
+ return true;
+ } catch {
+ setActionError("Couldn't copy this capture.");
+ void refresh();
+ return false;
+ }
+ }
+
+ function dragCapture(capture: SavedCapture): void {
+ setActionError(null);
+ startSavedCaptureDrag(capture.path).catch(() => {
+ setActionError("Couldn't start dragging this capture.");
+ void refresh();
+ });
+ }
+
async function openFolder(): Promise {
setActionError(null);
try {
@@ -123,7 +148,7 @@ export function SavedCapturesView({ onShowcase }: SavedCapturesViewProps): React
function showContextMenu(event: React.MouseEvent, capture: SavedCapture): void {
event.preventDefault();
const menuWidth = 196;
- const menuHeight = 164;
+ const menuHeight = 200;
setMenu({
capture,
left: Math.max(8, Math.min(event.clientX, window.innerWidth - menuWidth - 8)),
@@ -167,12 +192,13 @@ export function SavedCapturesView({ onShowcase }: SavedCapturesViewProps): React
{library.status !== "loading" && library.captures.length === 0 ? : null}
{library.captures.length > 0 ? (
- {library.captures.map((capture) => void viewCapture(selected)} />)}
+ {library.captures.map((capture) => void viewCapture(selected)} />)}
) : null}
{menu === null ? null : (
void viewCapture(menu.capture)} />
+ void copyCapture(menu.capture)} />
{ setMenu(null); onShowcase(menu.capture); }} />
void deleteCapture(menu.capture)} />
@@ -185,24 +211,86 @@ export function SavedCapturesView({ onShowcase }: SavedCapturesViewProps): React
type CaptureCardProps = {
capture: SavedCapture;
onView: (capture: SavedCapture) => void;
+ onCopy: (capture: SavedCapture) => Promise;
+ onDrag: (capture: SavedCapture) => void;
onContextMenu: (event: React.MouseEvent, capture: SavedCapture) => void;
};
-function CaptureCard({ capture, onView, onContextMenu }: CaptureCardProps): React.JSX.Element {
+const dragThresholdPx = 5;
+const copiedLabelMs = 1500;
+
+function CaptureCard({ capture, onView, onCopy, onDrag, onContextMenu }: CaptureCardProps): React.JSX.Element {
+ const [copied, setCopied] = useState(false);
+ const copiedTimer = useRef(null);
+ const pressStart = useRef<{ x: number; y: number } | null>(null);
+ const dragStarted = useRef(false);
+
+ useEffect(() => (): void => {
+ if (copiedTimer.current !== null) window.clearTimeout(copiedTimer.current);
+ }, []);
+
+ async function copy(): Promise {
+ const succeeded = await onCopy(capture);
+ if (!succeeded) return;
+ setCopied(true);
+ if (copiedTimer.current !== null) window.clearTimeout(copiedTimer.current);
+ copiedTimer.current = window.setTimeout(() => setCopied(false), copiedLabelMs);
+ }
+
+ function handleKeyDown(event: React.KeyboardEvent): void {
+ if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "c") {
+ event.preventDefault();
+ void copy();
+ }
+ }
+
+ // No pointer capture here: the OS drag needs the button still down and the
+ // webview must keep seeing the moves.
+ function handlePointerDown(event: React.PointerEvent): void {
+ if (event.button !== 0) return;
+ dragStarted.current = false;
+ pressStart.current = { x: event.clientX, y: event.clientY };
+ }
+
+ function handlePointerMove(event: React.PointerEvent): void {
+ const start = pressStart.current;
+ if (start === null || dragStarted.current || (event.buttons & 1) === 0) return;
+ if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < dragThresholdPx) return;
+ dragStarted.current = true;
+ pressStart.current = null;
+ onDrag(capture);
+ }
+
+ function handleClick(event: React.MouseEvent): void {
+ pressStart.current = null;
+ if (dragStarted.current) {
+ dragStarted.current = false;
+ event.preventDefault();
+ return;
+ }
+ onView(capture);
+ }
+
return (
-