From 9595f23da3df916dc5eafc5ca28c48de419eefa6 Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Mon, 3 Feb 2025 11:01:57 -0500 Subject: update frontend from main --- src/index.tsx | 143 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 60 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 851e003..61dc8a5 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"; @@ -51,7 +51,7 @@ function FGModInstallerSection() { checkPath(); // Initial check - const intervalId = setInterval(checkPath, 5000); // Check every 5 seconds + const intervalId = setInterval(checkPath, 3000); // Check every 3 seconds return () => clearInterval(intervalId); // Cleanup interval on component unmount }, []); @@ -155,7 +155,7 @@ function FGModInstallerSection() { )}
- Once the mod is installed, patch one of the games below to replace DLSS upscale and frame gen options with FSR 3 equivalents. *games with launchers not currently supported. + Once installed, patch a games below to replace DLSS upscale and frame gen options with FSR 3 equivalents. * NON STEAM GAMES, GAMES WITH LAUNCHERS, AND DX11 OR BELOW NOT SUPPORTED.
@@ -164,86 +164,109 @@ 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 () => { - const result = await listInstalledGames(); - if (result.status === "success") { - const sortedGames = [...result.games] - .map(game => ({ - ...game, - appid: parseInt(game.appid, 10), // Convert string to number - })) - .sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase())); - setGames(sortedGames); - } else { - console.error("Failed to fetch games"); + try { + const response = await listInstalledGames(); + if (response.status === "success") { + const sortedGames = [...response.games] + .map(game => ({ + ...game, + appid: parseInt(game.appid, 10), + })) + .sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase())); + setGames(sortedGames); + } + } catch (error) { + console.error("Error fetching games:", error); } }; 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 */} -
- handlePatchClick(game)} - > - Patch - - handleUnpatchClick(game)} - > - Unpatch - + + + ({ + 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}
+
+ + + Patch + + + + + Unpatch + + + + )} + + {result && ( + +
+ {result}
- {clickedGame?.appid === game.appid && ( -
- {result} -
- )}
- ))} + )}
); } @@ -251,7 +274,7 @@ function InstalledGamesSection() { export default definePlugin(() => ({ name: "Framegen Plugin", titleView:
Decky Framegen
, - alwaysRender: false, + alwaysRender: true, content: ( <> -- cgit v1.2.3