import { useState, useEffect } from "react"; import { ModalRoot, Field, Focusable, Button } from "@decky/ui"; import { getDllStats, DllStatsResult, getConfigFileContent, getLaunchScriptContent, FileContentResult } from "../api/lsfgApi"; interface NerdStuffModalProps { closeModal?: () => void; } export function NerdStuffModal({ closeModal }: NerdStuffModalProps) { const [dllStats, setDllStats] = useState(null); const [configContent, setConfigContent] = useState(null); const [scriptContent, setScriptContent] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const loadData = async () => { try { setLoading(true); setError(null); // Load all data in parallel const [dllResult, configResult, scriptResult] = await Promise.all([ getDllStats(), getConfigFileContent(), getLaunchScriptContent() ]); setDllStats(dllResult); setConfigContent(configResult); setScriptContent(scriptResult); } catch (err) { setError(err instanceof Error ? err.message : "Failed to load data"); } finally { setLoading(false); } }; loadData(); }, []); const formatSHA256 = (hash: string) => { // Format SHA256 hash for better readability (add spaces every 8 characters) return hash.replace(/(.{8})/g, '$1 ').trim(); }; const copyToClipboard = async (text: string) => { try { await navigator.clipboard.writeText(text); // Could add a toast notification here if desired } catch (err) { console.error("Failed to copy to clipboard:", err); } }; return ( {loading && (
Loading information...
)} {error && (
Error: {error}
)} {!loading && !error && ( <> {/* DLL Stats Section */} {dllStats && ( <> {!dllStats.success ? (
{dllStats.error || "Failed to get DLL stats"}
) : (
dllStats.dll_path && copyToClipboard(dllStats.dll_path)} onActivate={() => dllStats.dll_path && copyToClipboard(dllStats.dll_path)} > {dllStats.dll_path || "Not available"} dllStats.dll_sha256 && copyToClipboard(dllStats.dll_sha256)} onActivate={() => dllStats.dll_sha256 && copyToClipboard(dllStats.dll_sha256)} > {dllStats.dll_sha256 ? formatSHA256(dllStats.dll_sha256) : "Not available"} {dllStats.dll_source && (
{dllStats.dll_source}
)}
)} )} {/* Launch Script Section */} {scriptContent && ( {!scriptContent.success ? (
Script not found: {scriptContent.error}
) : (
Path: {scriptContent.path}
scriptContent.content && copyToClipboard(scriptContent.content)} onActivate={() => scriptContent.content && copyToClipboard(scriptContent.content)} >
                      {scriptContent.content || "No content"}
                    
)}
)} {/* Config File Section */} {configContent && ( {!configContent.success ? (
Config not found: {configContent.error}
) : (
Path: {configContent.path}
configContent.content && copyToClipboard(configContent.content)} onActivate={() => configContent.content && copyToClipboard(configContent.content)} >
                      {configContent.content || "No content"}
                    
)}
)} )}
); }