From e8927d3bc54b63d402c3f083ba9c1f5546a4eb8b Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Fri, 11 Jul 2025 20:20:19 -0400 Subject: feat: toggle settings in the plugin ui --- src/index.tsx | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 173 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/index.tsx b/src/index.tsx index 8465426..bddedf9 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,7 +2,9 @@ import { ButtonItem, PanelSection, PanelSectionRow, - staticClasses + staticClasses, + ToggleField, + SliderField } from "@decky/ui"; import { callable, @@ -25,6 +27,12 @@ const checkLsfgVkInstalled = callable<[], { installed: boolean; lib_exists: bool // Function to check if Lossless Scaling DLL is available const checkLosslessScalingDll = callable<[], { detected: boolean; path?: string; source?: string; message?: string; error?: string }>("check_lossless_scaling_dll"); +// Function to get lsfg configuration +const getLsfgConfig = callable<[], { success: boolean; config?: { enable_lsfg: boolean; multiplier: number; flow_scale: number; hdr: boolean }; error?: string }>("get_lsfg_config"); + +// Function to update lsfg configuration +const updateLsfgConfig = callable<[boolean, number, number, boolean], { success: boolean; message?: string; error?: string }>("update_lsfg_config"); + function Content() { const [isInstalled, setIsInstalled] = useState(false); const [isInstalling, setIsInstalling] = useState(false); @@ -33,6 +41,12 @@ function Content() { const [dllDetected, setDllDetected] = useState(false); const [dllDetectionStatus, setDllDetectionStatus] = useState(""); + // LSFG configuration state + const [enableLsfg, setEnableLsfg] = useState(true); + const [multiplier, setMultiplier] = useState(2); + const [flowScale, setFlowScale] = useState(1.0); + const [hdr, setHdr] = useState(false); + // Check installation status on component mount useEffect(() => { const checkInstallation = async () => { @@ -63,11 +77,24 @@ function Content() { } }; + const loadLsfgConfig = async () => { + try { + const result = await getLsfgConfig(); + if (result.success && result.config) { + setEnableLsfg(result.config.enable_lsfg); + setMultiplier(result.config.multiplier); + setFlowScale(result.config.flow_scale); + setHdr(result.config.hdr); + } + } catch (error) { + console.error("Error loading lsfg config:", error); + } + }; + checkInstallation(); checkDllDetection(); - }, []); - - const handleInstall = async () => { + loadLsfgConfig(); + }, []); const handleInstall = async () => { setIsInstalling(true); setInstallationStatus("Installing lsfg-vk..."); @@ -80,6 +107,19 @@ function Content() { title: "Installation Complete", body: "lsfg-vk has been installed successfully" }); + + // Reload lsfg config after installation + try { + const configResult = await getLsfgConfig(); + if (configResult.success && configResult.config) { + setEnableLsfg(configResult.config.enable_lsfg); + setMultiplier(configResult.config.multiplier); + setFlowScale(configResult.config.flow_scale); + setHdr(configResult.config.hdr); + } + } catch (error) { + console.error("Error reloading config after install:", error); + } } else { setInstallationStatus(`Installation failed: ${result.error}`); toaster.toast({ @@ -101,7 +141,7 @@ function Content() { const handleUninstall = async () => { setIsUninstalling(true); setInstallationStatus("Uninstalling lsfg-vk..."); - + try { const result = await uninstallLsfgVk(); if (result.success) { @@ -129,6 +169,48 @@ function Content() { } }; + const updateConfig = async (newEnableLsfg: boolean, newMultiplier: number, newFlowScale: number, newHdr: boolean) => { + try { + const result = await updateLsfgConfig(newEnableLsfg, newMultiplier, newFlowScale, newHdr); + if (result.success) { + toaster.toast({ + title: "Configuration Updated", + body: "lsfg script configuration has been updated" + }); + } else { + toaster.toast({ + title: "Update Failed", + body: result.error || "Failed to update configuration" + }); + } + } catch (error) { + toaster.toast({ + title: "Update Failed", + body: `Error: ${error}` + }); + } + }; + + const handleEnableLsfgChange = async (value: boolean) => { + setEnableLsfg(value); + await updateConfig(value, multiplier, flowScale, hdr); + }; + + const handleMultiplierChange = async (value: number) => { + setMultiplier(value); + await updateConfig(enableLsfg, value, flowScale, hdr); + }; + + const handleFlowScaleChange = async (value: number) => { + setFlowScale(value); + await updateConfig(enableLsfg, multiplier, value, hdr); + }; + + const handleHdrChange = async (value: boolean) => { + setHdr(value); + await updateConfig(enableLsfg, multiplier, flowScale, value); + }; + return ( @@ -175,6 +257,72 @@ function Content() { )} + + {/* Configuration Section - only show if installed */} + {isInstalled && ( + <> + +
+ LSFG Configuration +
+
+ + + + + + + + + + + + + + + + + + )}
- Add to your game's launch options in Steam: + Option 1: Use the lsfg script (recommended):
- ENABLE_LSFG=1 LSFG_MULTIPLIER=2 %COMMAND% + ~/lsfg && %COMMAND% +
+
+ Option 2: Manual environment variables: +
+
+ ENABLE_LSFG=1 LSFG_MULTIPLIER={multiplier} %COMMAND%
+ The lsfg script uses your current configuration settings. +
• ENABLE_LSFG=1 - Enables frame generation
• LSFG_MULTIPLIER=2-4 - FPS multiplier (start with 2)
- • LSFG_FLOW_SCALE=0.1-1.0 - Flow scale (optional, for performance) + • LSFG_FLOW_SCALE=0.25-1.0 - Flow scale (for performance) +
+ • LSFG_HDR=1 - HDR mode (only if using HDR)
-- cgit v1.2.3