import { useState } from "react"; import { PanelSectionRow, ButtonItem } from "@decky/ui"; import { FaClipboard } from "react-icons/fa"; import { getLaunchOption } from "../api/lsfgApi"; import { showClipboardSuccessToast, showClipboardErrorToast, showSuccessToast } from "../utils/toastUtils"; import { copyWithVerification } from "../utils/clipboardUtils"; export function SmartClipboardButton() { const [isLoading, setIsLoading] = useState(false); const getLaunchOptionText = async (): Promise => { try { const result = await getLaunchOption(); return result.launch_option || "~/lsfg %command%"; } catch (error) { return "~/lsfg %command%"; } }; const copyToClipboard = async () => { if (isLoading) return; setIsLoading(true); try { const text = await getLaunchOptionText(); const { success, verified } = await copyWithVerification(text); if (success) { if (verified) { showClipboardSuccessToast(); } else { showSuccessToast("Copied to Clipboard!", "Launch option copied (verification unavailable)"); } } else { showClipboardErrorToast(); } } catch (error) { showClipboardErrorToast(); } finally { setIsLoading(false); } }; return (
{isLoading ? ( ) : ( )}
{isLoading ? "Copying..." : "Copy Launch Option"}
); }