Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Add screenshot support to target selection UI
Richie McIlroyf92090aed32d
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsxindex 85c07c4db..54bd7d363 100644--- a/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx+++ b/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx@@ -1,17 +1,25 @@import { convertFileSrc } from "@tauri-apps/api/core";+import { save } from "@tauri-apps/plugin-dialog";import { cx } from "cva";import type { ComponentProps } from "solid-js";import { createMemo, createSignal, Show, splitProps } from "solid-js";-import type {- CaptureDisplayWithThumbnail,- CaptureWindowWithThumbnail,- RecordingMetaWithMetadata,+import {+ type CaptureDisplayWithThumbnail,+ type CaptureWindowWithThumbnail,+ commands,+ type RecordingMeta,+ type RecordingMetaWithMetadata,} from "~/utils/tauri";import IconLucideAppWindowMac from "~icons/lucide/app-window-mac";+import IconLucideCopy from "~icons/lucide/copy";+import IconLucideEdit from "~icons/lucide/edit";+import IconLucideImage from "~icons/lucide/image";+import IconLucideSave from "~icons/lucide/save";import IconLucideSquarePlay from "~icons/lucide/square-play";import IconMdiMonitor from "~icons/mdi/monitor";export type RecordingWithPath = RecordingMetaWithMetadata & { path: string };+export type ScreenshotWithPath = RecordingMeta & { path: string };function formatResolution(width?: number, height?: number) {if (!width || !height) return undefined;@@ -43,6 +51,10 @@ type TargetCardProps = (variant: "recording";target: RecordingWithPath;}+ | {+ variant: "screenshot";+ target: ScreenshotWithPath;+ }) &Omit<ComponentProps<"button">, "children"> & {highlightQuery?: string;@@ -73,13 +85,20 @@ export default function TargetCard(props: TargetCardProps) {return local.target as RecordingWithPath;});+ const screenshotTarget = createMemo(() => {+ if (local.variant !== "screenshot") return undefined;+ return local.target as ScreenshotWithPath;+ });+const renderIcon = (className: string) =>local.variant === "display" ? (<IconMdiMonitor class={className} />) : local.variant === "window" ? (<IconLucideAppWindowMac class={className} />- ) : (+ ) : local.variant === "recording" ? (<IconLucideSquarePlay class={className} />+ ) : (+ <IconLucideImage class={className} />);const label = createMemo(() => {@@ -88,7 +107,9 @@ export default function TargetCard(props: TargetCardProps) {const target = windowTarget();if (target) return target.name || target.owner_name;const recording = recordingTarget();- return recording?.pretty_name;+ if (recording) return recording.pretty_name;+ const screenshot = screenshotTarget();+ return screenshot?.pretty_name;});const subtitle = createMemo(() => {@@ -127,6 +148,10 @@ export default function TargetCard(props: TargetCardProps) {`${recording.path}/screenshots/display.jpg`,)}?t=${Date.now()}`;}+ const screenshot = screenshotTarget();+ if (screenshot) {+ return `${convertFileSrc(screenshot.path)}?t=${Date.now()}`;+ }const target = displayTarget() ?? windowTarget();if (!target?.thumbnail) return undefined;return `data:image/png;base64,${target.thumbnail}`;@@ -161,6 +186,42 @@ export default function TargetCard(props: TargetCardProps) {});};+ const handleOpenEditor = (e: MouseEvent) => {+ e.stopPropagation();+ const screenshot = screenshotTarget();+ if (!screenshot) return;+ commands.showWindow({+ ScreenshotEditor: {+ path: screenshot.path,+ },+ });+ };++ const handleCopy = async (e: MouseEvent) => {+ e.stopPropagation();+ const screenshot = screenshotTarget();+ if (!screenshot) return;+ await commands.copyScreenshotToClipboard(screenshot.path);+ };++ const handleSave = async (e: MouseEvent) => {+ e.stopPropagation();+ const screenshot = screenshotTarget();+ if (!screenshot) return;+ const path = await save({+ defaultPath: screenshot.pretty_name + ".png",+ filters: [+ {+ name: "Image",+ extensions: ["png"],+ },+ ],+ });+ if (path) {+ await commands.copyFileToPath(screenshot.path, path);+ }+ };+return (<buttontype="button"@@ -206,22 +267,52 @@ export default function TargetCard(props: TargetCardProps) {<div class="absolute inset-0 border opacity-60 pointer-events-none border-black/5" /><div class="absolute inset-x-0 bottom-0 h-10 bg-gradient-to-t to-transparent pointer-events-none from-black/40" /></div>- <div class="flex flex-row items-start gap-2 px-2 py-1.5">- <div class="flex-1 min-w-0">- <p class="truncate text-[11px] font-medium text-gray-12">- {highlight(label())}- </p>- <Show when={subtitle()}>- <p class="truncate text-[11px] text-gray-11">- {highlight(subtitle())}- </p>- </Show>- <Show when={metadata()}>- <p class="truncate text-[11px] text-gray-10">- {highlight(metadata())}+ <div class="flex flex-col w-full">+ <div class="flex flex-row items-start gap-2 px-2 py-1.5">+ <div class="flex-1 min-w-0">+ <p class="truncate text-[11px] font-medium text-gray-12">+ {highlight(label())}</p>- </Show>+ <Show when={subtitle()}>+ <p class="truncate text-[11px] text-gray-11">+ {highlight(subtitle())}+ </p>+ </Show>+ <Show when={metadata()}>+ <p class="truncate text-[11px] text-gray-10">+ {highlight(metadata())}+ </p>+ </Show>+ </div></div>+ <Show when={local.variant === "screenshot"}>+ <div class="flex items-center justify-between px-2 pb-1.5 pt-0.5 gap-1">+ <button+ type="button"+ onClick={handleOpenEditor}+ class="flex-1 flex items-center justify-center p-1 rounded hover:bg-gray-5 text-gray-11 hover:text-gray-12 transition-colors"+ title="Editor"+ >+ <IconLucideEdit class="size-3.5" />+ </button>+ <button+ type="button"+ onClick={handleCopy}+ class="flex-1 flex items-center justify-center p-1 rounded hover:bg-gray-5 text-gray-11 hover:text-gray-12 transition-colors"+ title="Copy to clipboard"+ >+ <IconLucideCopy class="size-3.5" />+ </button>+ <button+ type="button"+ onClick={handleSave}+ class="flex-1 flex items-center justify-center p-1 rounded hover:bg-gray-5 text-gray-11 hover:text-gray-12 transition-colors"+ title="Save as..."+ >+ <IconLucideSave class="size-3.5" />+ </button>+ </div>+ </Show></div></button>);diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsxindex 13487a43c..455a723e0 100644--- a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx+++ b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx@@ -1,7 +1,7 @@import { Button } from "@cap/ui-solid";import { createEventListener } from "@solid-primitives/event-listener";import { useNavigate } from "@solidjs/router";-import { createMutation, useQuery } from "@tanstack/solid-query";+import { createMutation, queryOptions, useQuery } from "@tanstack/solid-query";import { listen } from "@tauri-apps/api/event";import {getAllWebviewWindows,@@ -73,7 +73,7 @@ import CameraSelect from "./CameraSelect";import ChangelogButton from "./ChangeLogButton";import MicrophoneSelect from "./MicrophoneSelect";import SystemAudio from "./SystemAudio";-import type { RecordingWithPath } from "./TargetCard";+import type { RecordingWithPath, ScreenshotWithPath } from "./TargetCard";import TargetDropdownButton from "./TargetDropdownButton";import TargetMenuGrid from "./TargetMenuGrid";import TargetTypeButton from "./TargetTypeButton";@@ -149,6 +149,12 @@ type TargetMenuPanelProps =targets?: RecordingWithPath[];onSelect: (target: RecordingWithPath) => void;onViewAll: () => void;+ }+ | {+ variant: "screenshot";+ targets?: ScreenshotWithPath[];+ onSelect: (target: ScreenshotWithPath) => void;+ onViewAll: () => void;};type SharedTargetMenuProps = {@@ -167,13 +173,17 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {? "Search displays": props.variant === "window"? "Search windows"- : "Search recordings";+ : props.variant === "recording"+ ? "Search recordings"+ : "Search screenshots";const noResultsMessage =props.variant === "display"? "No matching displays": props.variant === "window"? "No matching windows"- : "No matching recordings";+ : props.variant === "recording"+ ? "No matching recordings"+ : "No matching screenshots";const filteredDisplayTargets = createMemo<CaptureDisplayWithThumbnail[]>(() => {@@ -220,6 +230,18 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {return targets.filter((target) => matchesQuery(target.pretty_name));});+ const filteredScreenshotTargets = createMemo<ScreenshotWithPath[]>(() => {+ if (props.variant !== "screenshot") return [];+ const query = normalizedQuery();+ const targets = props.targets ?? [];+ if (!query) return targets;++ const matchesQuery = (value?: string | null) =>+ !!value && value.toLowerCase().includes(query);++ return targets.filter((target) => matchesQuery(target.pretty_name));+ });+return (<div class="flex flex-col w-full h-full min-h-0"><div class="flex gap-3 justify-between items-center mt-3">@@ -234,7 +256,9 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {</div><div class="relative flex-1 min-w-0 h-[36px] flex items-center"><Show- when={props.variant === "recording"}+ when={+ props.variant === "recording" || props.variant === "screenshot"+ }fallback={<><IconLucideSearch class="absolute left-2 top-[48%] -translate-y-1/2 pointer-events-none size-3 text-gray-10" />@@ -266,8 +290,14 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {if ("onViewAll" in props) props.onViewAll();}}>- <IconLucideSquarePlay class="mr-2 size-3" />- View All Recordings+ {props.variant === "recording" ? (+ <IconLucideSquarePlay class="mr-2 size-3" />+ ) : (+ <IconLucideImage class="mr-2 size-3" />+ )}+ {props.variant === "recording"+ ? "View All Recordings"+ : "View All Screenshots"}</button></Show></div>@@ -296,7 +326,7 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {highlightQuery={trimmedSearch()}emptyMessage={trimmedSearch() ? noResultsMessage : undefined}/>- ) : (+ ) : props.variant === "recording" ? (<TargetMenuGridvariant="recording"targets={filteredRecordingTargets()}@@ -307,9 +337,22 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {highlightQuery={trimmedSearch()}emptyMessage={trimmedSearch() ? noResultsMessage : undefined}/>+ ) : (+ <TargetMenuGrid+ variant="screenshot"+ targets={filteredScreenshotTargets()}+ isLoading={props.isLoading}+ errorMessage={props.errorMessage}+ onSelect={props.onSelect}+ disabled={props.disabled}+ highlightQuery={trimmedSearch()}+ emptyMessage={trimmedSearch() ? noResultsMessage : undefined}+ />)}</div>- <Show when={props.variant === "recording"}>+ <Show+ when={props.variant === "recording" || props.variant === "screenshot"}+ >{/* Removed sticky footer button */}</Show></div>@@ -387,14 +430,16 @@ function Page() {const [displayMenuOpen, setDisplayMenuOpen] = createSignal(false);const [windowMenuOpen, setWindowMenuOpen] = createSignal(false);const [recordingsMenuOpen, setRecordingsMenuOpen] = createSignal(false);- const activeMenu = createMemo<"display" | "window" | "recording" | null>(- () => {- if (displayMenuOpen()) return "display";- if (windowMenuOpen()) return "window";- if (recordingsMenuOpen()) return "recording";- return null;- },- );+ const [screenshotsMenuOpen, setScreenshotsMenuOpen] = createSignal(false);+ const activeMenu = createMemo<+ "display" | "window" | "recording" | "screenshot" | null+ >(() => {+ if (displayMenuOpen()) return "display";+ if (windowMenuOpen()) return "window";+ if (recordingsMenuOpen()) return "recording";+ if (screenshotsMenuOpen()) return "screenshot";+ return null;+ });const [hasOpenedDisplayMenu, setHasOpenedDisplayMenu] = createSignal(false);const [hasOpenedWindowMenu, setHasOpenedWindowMenu] = createSignal(false);@@ -412,6 +457,19 @@ function Page() {}));const recordings = useQuery(() => listRecordings);+ const screenshots = useQuery(() =>+ queryOptions({+ queryKey: ["screenshots"],+ queryFn: async () => {+ const result = await commands+ .listScreenshots()+ .catch(() => [] as const);++ return result.map(([path, meta]) => ({ ...meta, path }));+ },+ refetchInterval: 2000,+ }),+ );const screens = useQuery(() => listScreens);const windows = useQuery(() => listWindows);@@ -457,6 +515,12 @@ function Page() {.map(([path, meta]) => ({ ...meta, path }) as RecordingWithPath);});+ const screenshotsData = createMemo(() => {+ const data = screenshots.data;+ if (!data) return [];+ return data.slice(0, 20) as ScreenshotWithPath[];+ });+const displayMenuLoading = () =>!hasDisplayTargetsData() &&(displayTargets.status === "pending" ||@@ -509,6 +573,7 @@ function Page() {setDisplayMenuOpen(false);setWindowMenuOpen(false);setRecordingsMenuOpen(false);+ setScreenshotsMenuOpen(false);});createUpdateCheck();@@ -889,6 +954,7 @@ function Page() {if (next) {setDisplayMenuOpen(false);setWindowMenuOpen(false);+ setScreenshotsMenuOpen(false);}return next;});@@ -901,11 +967,16 @@ function Page() {<Tooltip content={<span>Screenshots</span>}><buttontype="button"- onClick={async () => {- await commands.showWindow({- Settings: { page: "screenshots" },+ onClick={() => {+ setScreenshotsMenuOpen((prev) => {+ const next = !prev;+ if (next) {+ setDisplayMenuOpen(false);+ setWindowMenuOpen(false);+ setRecordingsMenuOpen(false);+ }+ return next;});- getCurrentWindow().hide();}}class="flex justify-center items-center size-5">@@ -1020,7 +1091,7 @@ function Page() {windowTriggerRef?.focus();}}/>- ) : (+ ) : variant === "recording" ? (<TargetMenuPanelvariant="recording"targets={recordingsData()}@@ -1051,6 +1122,33 @@ function Page() {getCurrentWindow().hide();}}/>+ ) : (+ <TargetMenuPanel+ variant="screenshot"+ targets={screenshotsData()}+ isLoading={screenshots.isPending}+ errorMessage={+ screenshots.error ? "Failed to load screenshots" : undefined+ }+ onSelect={async (screenshot) => {+ await commands.showWindow({+ ScreenshotEditor: {+ path: screenshot.path,+ },+ });+ // getCurrentWindow().hide(); // Maybe keep open?+ }}+ disabled={isRecording()}+ onBack={() => {+ setScreenshotsMenuOpen(false);+ }}+ onViewAll={async () => {+ await commands.showWindow({+ Settings: { page: "screenshots" },+ });+ getCurrentWindow().hide();+ }}+ />)}</Show>