From 9f0354388f22a57e4562a76b9140d1dd604089f1 Mon Sep 17 00:00:00 2001 From: Siddharth Kumar Sah Date: Sat, 4 Apr 2026 16:33:10 +0800 Subject: [PATCH] fix: replace navigator.clipboard with copyToClipboard utility --- apps/web/src/components/settings/settings-dialog.tsx | 9 +++++---- .../web/src/components/tools/barcode-read-settings.tsx | 7 +++---- .../src/components/tools/color-palette-settings.tsx | 7 +++---- apps/web/src/components/tools/ocr-settings.tsx | 10 ++++++---- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/apps/web/src/components/settings/settings-dialog.tsx b/apps/web/src/components/settings/settings-dialog.tsx index 51aaa025..fab27dd4 100644 --- a/apps/web/src/components/settings/settings-dialog.tsx +++ b/apps/web/src/components/settings/settings-dialog.tsx @@ -24,7 +24,7 @@ import { } from "lucide-react"; import { useCallback, useEffect, useMemo, useState } from "react"; import { apiDelete, apiGet, apiPost, apiPut, clearToken } from "@/lib/api"; -import { cn } from "@/lib/utils"; +import { cn, copyToClipboard } from "@/lib/utils"; import { GemLogo } from "../common/gem-logo"; interface SettingsDialogProps { @@ -1144,11 +1144,12 @@ function ApiKeysSection() { } }, [keyName, loadKeys]); - const copyKey = useCallback((key: string) => { - navigator.clipboard.writeText(key).then(() => { + const copyKey = useCallback(async (key: string) => { + const ok = await copyToClipboard(key); + if (ok) { setCopied(true); setTimeout(() => setCopied(false), 2000); - }); + } }, []); const deleteKey = useCallback( diff --git a/apps/web/src/components/tools/barcode-read-settings.tsx b/apps/web/src/components/tools/barcode-read-settings.tsx index 27c37f90..87853913 100644 --- a/apps/web/src/components/tools/barcode-read-settings.tsx +++ b/apps/web/src/components/tools/barcode-read-settings.tsx @@ -1,5 +1,6 @@ import { Check, Copy, Loader2 } from "lucide-react"; import { useState } from "react"; +import { copyToClipboard } from "@/lib/utils"; import { useFileStore } from "@/stores/file-store"; function getToken(): string { @@ -44,12 +45,10 @@ export function BarcodeReadSettings() { const copyText = async () => { if (!result?.text) return; - try { - await navigator.clipboard.writeText(result.text); + const ok = await copyToClipboard(result.text); + if (ok) { setCopied(true); setTimeout(() => setCopied(false), 1500); - } catch { - // Fallback: silent fail } }; diff --git a/apps/web/src/components/tools/color-palette-settings.tsx b/apps/web/src/components/tools/color-palette-settings.tsx index cd3af660..d6475ee7 100644 --- a/apps/web/src/components/tools/color-palette-settings.tsx +++ b/apps/web/src/components/tools/color-palette-settings.tsx @@ -1,5 +1,6 @@ import { Check, Copy, Loader2 } from "lucide-react"; import { useState } from "react"; +import { copyToClipboard } from "@/lib/utils"; import { useFileStore } from "@/stores/file-store"; function getToken(): string { @@ -43,12 +44,10 @@ export function ColorPaletteSettings() { }; const copyColor = async (color: string, idx: number) => { - try { - await navigator.clipboard.writeText(color); + const ok = await copyToClipboard(color); + if (ok) { setCopiedIdx(idx); setTimeout(() => setCopiedIdx(null), 1500); - } catch { - // Fallback: silent fail } }; diff --git a/apps/web/src/components/tools/ocr-settings.tsx b/apps/web/src/components/tools/ocr-settings.tsx index 6c312f33..09d9ab66 100644 --- a/apps/web/src/components/tools/ocr-settings.tsx +++ b/apps/web/src/components/tools/ocr-settings.tsx @@ -1,7 +1,7 @@ import { Check, Copy } from "lucide-react"; import { useRef, useState } from "react"; import { ProgressCard } from "@/components/common/progress-card"; -import { generateId } from "@/lib/utils"; +import { copyToClipboard, generateId } from "@/lib/utils"; import { useFileStore } from "@/stores/file-store"; function getToken(): string { @@ -118,9 +118,11 @@ export function OcrSettings() { const handleCopy = async () => { if (text) { - await navigator.clipboard.writeText(text); - setCopied(true); - setTimeout(() => setCopied(false), 2000); + const ok = await copyToClipboard(text); + if (ok) { + setCopied(true); + setTimeout(() => setCopied(false), 2000); + } } };