From 227acb969dc4b36cae427d2cf6a063ec51f41e13 Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Wed, 17 Sep 2025 15:03:57 -0400 Subject: feat: add clipboard readout and logging --- src/components/ClipboardDisplay.tsx | 139 ++++++++++++++++++++++++++++++++++++ src/components/Content.tsx | 2 + src/components/index.ts | 1 + 3 files changed, 142 insertions(+) create mode 100644 src/components/ClipboardDisplay.tsx (limited to 'src') diff --git a/src/components/ClipboardDisplay.tsx b/src/components/ClipboardDisplay.tsx new file mode 100644 index 0000000..852a50f --- /dev/null +++ b/src/components/ClipboardDisplay.tsx @@ -0,0 +1,139 @@ +import { useState, useEffect } from "react"; +import { PanelSectionRow } from "@decky/ui"; +import { FaClipboard, FaEye } from "react-icons/fa"; + +export function ClipboardDisplay() { + const [clipboardContent, setClipboardContent] = useState(""); + const [isReading, setIsReading] = useState(false); + + const readClipboard = async () => { + if (isReading) return; // Prevent concurrent reads + + setIsReading(true); + try { + console.log("ClipboardDisplay: Attempting to read clipboard..."); + + if (!navigator.clipboard) { + console.log("ClipboardDisplay: navigator.clipboard not available"); + setClipboardContent("Clipboard API not available"); + return; + } + + if (!navigator.clipboard.readText) { + console.log("ClipboardDisplay: navigator.clipboard.readText not available"); + setClipboardContent("Clipboard read not supported"); + return; + } + + console.log("ClipboardDisplay: Calling navigator.clipboard.readText()..."); + const content = await navigator.clipboard.readText(); + console.log("ClipboardDisplay: Successfully read clipboard:", content.length, "characters"); + setClipboardContent(content); + } catch (error) { + // This is expected if user hasn't granted clipboard permissions + // or if we're in a context where reading isn't allowed + console.log("ClipboardDisplay: Error reading clipboard:", error); + console.log("ClipboardDisplay: Error name:", (error as Error).name); + console.log("ClipboardDisplay: Error message:", (error as Error).message); + + // More specific error messages based on error type + if (error instanceof DOMException) { + switch (error.name) { + case 'NotAllowedError': + setClipboardContent("Clipboard access denied - check permissions"); + break; + case 'NotFoundError': + setClipboardContent("No clipboard data found"); + break; + case 'SecurityError': + setClipboardContent("Clipboard access blocked by security policy"); + break; + default: + setClipboardContent(`Clipboard error: ${error.name}`); + } + } else { + setClipboardContent("Unable to read clipboard"); + } + } finally { + setIsReading(false); + } + }; + + // Read clipboard on mount and then every 3 seconds + useEffect(() => { + readClipboard(); + + const interval = setInterval(() => { + readClipboard(); + }, 3000); + + return () => clearInterval(interval); + }, []); + + const truncateText = (text: string, maxLength: number = 60) => { + if (text.length <= maxLength) return text; + return text.substring(0, maxLength) + "..."; + }; + + const displayText = truncateText(clipboardContent); + + return ( + +
+
+ +
+ Current Clipboard +
+ {isReading && ( + + )} +
+
+ {displayText || "Reading clipboard..."} +
+
+ +
+ ); +} diff --git a/src/components/Content.tsx b/src/components/Content.tsx index e870dda..e82a7c3 100644 --- a/src/components/Content.tsx +++ b/src/components/Content.tsx @@ -12,6 +12,7 @@ import { WikiButton } from "./WikiButton"; import { ClipboardButton } from "./ClipboardButton"; import { SmartClipboardButton } from "./SmartClipboardButton"; import { FgmodClipboardButton } from "./FgmodClipboardButton"; +import { ClipboardDisplay } from "./ClipboardDisplay"; import { PluginUpdateChecker } from "./PluginUpdateChecker"; import { NerdStuffModal } from "./NerdStuffModal"; import { ConfigurationData } from "../config/configSchema"; @@ -100,6 +101,7 @@ export function Content() { {/* Clipboard buttons - only show if installed */} {isInstalled && ( <> + diff --git a/src/components/index.ts b/src/components/index.ts index 32bbb31..c3ace84 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -7,6 +7,7 @@ export { UsageInstructions } from "./UsageInstructions"; export { WikiButton } from "./WikiButton"; export { SmartClipboardButton } from "./SmartClipboardButton"; export { FgmodClipboardButton } from "./FgmodClipboardButton"; +export { ClipboardDisplay } from "./ClipboardDisplay"; export { PluginUpdateChecker } from "./PluginUpdateChecker"; export { NerdStuffModal } from "./NerdStuffModal"; export { ProfileManagement } from "./ProfileManagement"; -- cgit v1.2.3