Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add toast notifications for screenshot actions

Richie McIlroyf8f1d01c62d0
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx
index 54bd7d363..3d60180ba 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx
@@ -3,6 +3,7 @@ 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 toast from "solid-toast";
import {
type CaptureDisplayWithThumbnail,
type CaptureWindowWithThumbnail,
@@ -201,24 +202,35 @@ export default function TargetCard(props: TargetCardProps) {
e.stopPropagation();
const screenshot = screenshotTarget();
if (!screenshot) return;
- await commands.copyScreenshotToClipboard(screenshot.path);
+ try {
+ await commands.copyScreenshotToClipboard(screenshot.path);
+ toast.success("Screenshot copied to clipboard");
+ } catch (error) {
+ console.error("Failed to copy screenshot:", error);
+ toast.error("Failed to copy screenshot");
+ }
};
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) {
+ try {
+ const path = await save({
+ defaultPath: `${screenshot.pretty_name}.png`,
+ filters: [
+ {
+ name: "Image",
+ extensions: ["png"],
+ },
+ ],
+ });
+ if (!path) return;
await commands.copyFileToPath(screenshot.path, path);
+ toast.success("Screenshot saved");
+ } catch (error) {
+ console.error("Failed to save screenshot:", error);
+ toast.error("Failed to save screenshot");
}
};
@@ -236,33 +248,37 @@ export default function TargetCard(props: TargetCardProps) {
>
<div class="relative h-[4.75rem] w-full overflow-hidden bg-gray-4/40">
<Show
- when={thumbnailSrc() && imageExists()}
+ when={imageExists() ? thumbnailSrc() : undefined}
fallback={
<div class="flex justify-center items-center w-full h-full bg-gray-4">
{renderIcon("size-6 text-gray-9 opacity-70")}
</div>
}
>
- <img
- src={thumbnailSrc()!}
- alt={`${
- local.variant === "display" ? "Display" : "Window"
- } preview for ${label()}`}
- class="object-cover w-full h-full"
- loading="lazy"
- draggable={false}
- onError={() => setImageExists(false)}
- />
- </Show>
- <Show when={appIconSrc()}>
- <div class="flex absolute inset-0 justify-center items-center pointer-events-none bg-black/45">
+ {(src) => (
<img
- src={appIconSrc()!}
- alt={`${label()} icon`}
- class="h-16 w-16 max-h-[55%] max-w-[55%] rounded-lg border border-black/20 object-contain shadow-lg shadow-black/30"
+ src={src}
+ alt={`${
+ local.variant === "display" ? "Display" : "Window"
+ } preview for ${label()}`}
+ class="object-cover w-full h-full"
+ loading="lazy"
draggable={false}
+ onError={() => setImageExists(false)}
/>
- </div>
+ )}
+ </Show>
+ <Show when={appIconSrc()}>
+ {(src) => (
+ <div class="flex absolute inset-0 justify-center items-center pointer-events-none bg-black/45">
+ <img
+ src={src}
+ alt={`${label()} icon`}
+ class="h-16 w-16 max-h-[55%] max-w-[55%] rounded-lg border border-black/20 object-contain shadow-lg shadow-black/30"
+ draggable={false}
+ />
+ </div>
+ )}
</Show>
<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" />
@@ -287,30 +303,33 @@ export default function TargetCard(props: TargetCardProps) {
</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"
+ <div
+ role="button"
+ tabIndex={-1}
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"
+ </div>
+ <div
+ role="button"
+ tabIndex={-1}
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"
+ </div>
+ <div
+ role="button"
+ tabIndex={-1}
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>
</div>
</Show>
</div>