import { ButtonItem, PanelSectionRow, SliderField, ToggleField } from "@decky/ui"; import { useEffect, useRef, useState } from "react"; import { RiArrowDownSFill, RiArrowUpSFill } from "react-icons/ri"; import type { WorkaroundState } from "../api/lsfgApi"; import t from "../i18n/i18n"; interface Props { state: WorkaroundState; disabled?: boolean; onChange: (state: WorkaroundState) => Promise; } const WORKAROUNDS_COLLAPSED_KEY = "lsfg-flatpak-workarounds-collapsed-v1"; export function FlatpakWorkaroundsSection({ state, disabled = false, onChange }: Props) { const [collapsed, setCollapsed] = useState(() => { try { return localStorage.getItem(WORKAROUNDS_COLLAPSED_KEY) !== "false"; } catch { return true; } }); const [fpsValue, setFpsValue] = useState(state.dxvkFrameRate); const timer = useRef(null); useEffect(() => { try { localStorage.setItem(WORKAROUNDS_COLLAPSED_KEY, String(collapsed)); } catch {} }, [collapsed]); useEffect(() => { setFpsValue(state.dxvkFrameRate); }, [state.dxvkFrameRate]); useEffect(() => () => { if (timer.current !== null) window.clearTimeout(timer.current); }, []); const update = (field: keyof WorkaroundState, value: boolean | number) => { void onChange({ ...state, [field]: value }); }; const updateFps = (value: number) => { setFpsValue(value); if (timer.current !== null) window.clearTimeout(timer.current); timer.current = window.setTimeout(() => { timer.current = null; void onChange({ ...state, dxvkFrameRate: value }); }, 250); }; const fpsLabel = fpsValue > 0 ? `${fpsValue} FPS` : t("CONFIG_BASE_FPS_CAP_OFF", "Off"); return ( <>
{t("CONFIG_WORKAROUNDS_TITLE", "Workarounds")}
setCollapsed((value) => !value)} > {collapsed ? : } {!collapsed && ( <> update("disableSteamdeckMode", value)} disabled={disabled} /> update("disableGamescopeWsi", value)} disabled={disabled} /> update("disableHdr", value)} disabled={disabled} /> update("disableVkbasalt", value)} disabled={disabled} /> update("enableZink", value)} disabled={disabled} /> )} ); }