fix: replace navigator.clipboard with copyToClipboard utility

This commit is contained in:
Siddharth Kumar Sah
2026-04-04 16:33:10 +08:00
parent b650dcd791
commit 9f0354388f
4 changed files with 17 additions and 16 deletions
@@ -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(
@@ -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
}
};
@@ -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
}
};
@@ -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);
}
}
};