import { useState } from "react"; import { PanelSectionRow, ButtonItem } from "@decky/ui"; import { FaClipboard, FaRocket } from "react-icons/fa"; import { toaster } from "@decky/api"; import { getLaunchOption, copyToSystemClipboard } from "../api/lsfgApi"; 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(); // Strategy 1: Try direct navigator.clipboard first (fastest) let directSuccess = false; try { await navigator.clipboard.writeText(text); // Verify it worked const readBack = await navigator.clipboard.readText(); directSuccess = readBack === text; } catch (e) { // Direct clipboard failed, will try alternatives } if (directSuccess) { toaster.toast({ title: "Copied to Clipboard!", body: "Launch option ready to paste" }); return; } // Strategy 2: Try backend system clipboard try { const result = await copyToSystemClipboard(text); if (result.success) { toaster.toast({ title: "Copied to Clipboard!", body: `Using ${result.method || "system clipboard"}` }); return; } } catch (e) { // Backend failed, fall back to browser } // Strategy 3: Fall back to optimized browser window const htmlContent = ` Quick Copy - Steam Deck Clipboard Helper

🚀 Steam Deck Clipboard Helper

Copy this launch option for your Steam games:
${text}
⏳ Copying to clipboard...
`; const dataUrl = 'data:text/html;charset=utf-8,' + encodeURIComponent(htmlContent); window.open(dataUrl, '_blank', 'width=600,height=400,scrollbars=no,resizable=yes'); toaster.toast({ title: "Browser Helper Opened", body: "Clipboard helper window opened with auto-copy" }); } catch (error) { toaster.toast({ title: "Copy Failed", body: `Error: ${String(error)}` }); } finally { setIsLoading(false); } }; return (
{isLoading ? : }
{isLoading ? "Copying..." : "Smart Clipboard Copy"}
); }