From 77d4d13a06cddc879d238d5cc89e47608d633921 Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Fri, 31 Jan 2025 22:54:15 -0500 Subject: Feat: initial dropdown menu implementation --- src/index.tsx | 101 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 42 deletions(-) (limited to 'src/index.tsx') diff --git a/src/index.tsx b/src/index.tsx index 52c3128..8c48ad5 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -3,7 +3,7 @@ import { PanelSection, PanelSectionRow, ButtonItem, - // Router + DropdownItem } from "@decky/ui"; import { definePlugin, callable } from "@decky/api"; import { RiAiGenerate } from "react-icons/ri"; @@ -164,25 +164,21 @@ function FGModInstallerSection() { function InstalledGamesSection() { const [games, setGames] = useState<{ appid: number; name: string }[]>([]); - const [clickedGame, setClickedGame] = useState<{ appid: number; name: string } | null>(null); + const [selectedGame, setSelectedGame] = useState<{ appid: number; name: string } | null>(null); const [result, setResult] = useState(''); useEffect(() => { const fetchGames = async () => { try { const response = await listInstalledGames(); - console.log("listInstalledGames response:", response); if (response.status === "success") { const sortedGames = [...response.games] .map(game => ({ ...game, - appid: parseInt(game.appid, 10), // Convert string to number + appid: parseInt(game.appid, 10), })) .sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase())); - console.log("Fetched games successfully:", sortedGames.length); setGames(sortedGames); - } else { - console.error("Failed to fetch games:", response); } } catch (error) { console.error("Error fetching games:", error); @@ -192,64 +188,85 @@ function InstalledGamesSection() { fetchGames(); }, []); - const handlePatchClick = async (game: { appid: number; name: string }) => { - setClickedGame(game); + const handlePatchClick = async () => { + if (!selectedGame) return; + try { - await SteamClient.Apps.SetAppLaunchOptions(game.appid, '~/fgmod/fgmod %COMMAND%'); - setResult(`Launch options set successfully for ${game.name}. You can now select DLSS in the game's menu to use FSR Upscaling and FrameGen equivalents.`); + await SteamClient.Apps.SetAppLaunchOptions(selectedGame.appid, '~/fgmod/fgmod %COMMAND%'); + setResult(`Launch options set successfully for ${selectedGame.name}. You can now select DLSS in the game's menu to use FSR Upscaling and FrameGen equivalents.`); } catch (error) { - if (error instanceof Error) { - setResult(`Error setting launch options: ${error.message}`); - } else { - setResult('Error setting launch options'); - } + setResult(error instanceof Error ? `Error setting launch options: ${error.message}` : 'Error setting launch options'); } }; - const handleUnpatchClick = async (game: { appid: number; name: string }) => { - setClickedGame(game); + const handleUnpatchClick = async () => { + if (!selectedGame) return; + try { - await SteamClient.Apps.SetAppLaunchOptions(game.appid, '~/fgmod/fgmod-uninstaller.sh %COMMAND%'); - setResult(`DLSS mods will uninstall on next launch of ${game.name}. The game is now unpatched.`); + await SteamClient.Apps.SetAppLaunchOptions(selectedGame.appid, '~/fgmod/fgmod-uninstaller.sh %COMMAND%'); + setResult(`DLSS mods will uninstall on next launch of ${selectedGame.name}. The game is now unpatched.`); } catch (error) { - if (error instanceof Error) { - setResult(`Error clearing launch options: ${error.message}`); - } else { - setResult('Error clearing launch options'); - } + setResult(error instanceof Error ? `Error clearing launch options: ${error.message}` : 'Error clearing launch options'); } }; return ( - - {games.map((game) => ( - -
- {/* Game Name as Bold Subheader */} -
{game.name}
- {/* Buttons Stacked Vertically */} -
+ + + ({ + data: game.appid, + label: game.name + }))} + selectedOption={selectedGame?.appid} + onChange={(option) => { + const game = games.find(g => g.appid === option.data); + setSelectedGame(game || null); + setResult(''); + }} + strDefaultLabel="Select a game..." + menuLabel="Installed Games" + /> + + + {selectedGame && ( + <> + +
+ {selectedGame.name} +
+
+ +
handlePatchClick(game)} + onClick={handlePatchClick} > Patch handleUnpatchClick(game)} + onClick={handleUnpatchClick} > Unpatch
+
+ + )} + + {result && ( + +
+ {result}
- {clickedGame?.appid === game.appid && ( -
- {result} -
- )}
- ))} + )}
); } @@ -257,7 +274,7 @@ function InstalledGamesSection() { export default definePlugin(() => ({ name: "Framegen Plugin", titleView:
Decky Framegen
, - alwaysRender: false, + alwaysRender: true, content: ( <> -- cgit v1.2.3