From 711ae9703616376c578fcfcd8c9bfff3bab869b0 Mon Sep 17 00:00:00 2001
From: xXJSONDeruloXx <danielhimebauch@gmail.com>
Date: Sun, 26 Jan 2025 22:45:57 -0500
Subject: patch game from list on click

---
 src/index.tsx | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

(limited to 'src/index.tsx')

diff --git a/src/index.tsx b/src/index.tsx
index 98611a2..37acfb1 100755
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -231,16 +231,20 @@ function MainRunningApp() {
 }
 
 function InstalledGamesSection() {
-  const [games, setGames] = useState<{ appid: string; name: string }[]>([]);
-  const [clickedGame, setClickedGame] = useState<{ appid: string; name: string } | null>(null);
+  const [games, setGames] = useState<{ appid: number; name: string }[]>([]);
+  const [clickedGame, setClickedGame] = useState<{ appid: number; name: string } | null>(null);
+  const [result, setResult] = useState<string>('');
 
   useEffect(() => {
     const fetchGames = async () => {
       const result = await listInstalledGames();
       if (result.status === "success") {
-        const sortedGames = [...result.games].sort((a, b) => 
-          a.name.toLowerCase().localeCompare(b.name.toLowerCase())
-        );
+        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");
@@ -250,19 +254,33 @@ function InstalledGamesSection() {
     fetchGames();
   }, []);
 
+  const handleGameClick = async (game: { appid: number; name: string }) => {
+    setClickedGame(game);
+    try {
+      await SteamClient.Apps.SetAppLaunchOptions(game.appid, '/home/deck/fgmod/fgmod %COMMAND%');
+      setResult(`Launch options set successfully for ${game.name}. Restart the game to use FSR upscaling and frame gen.`);
+    } catch (error) {
+      if (error instanceof Error) {
+        setResult(`Error setting launch options: ${error.message}`);
+      } else {
+        setResult('Error setting launch options');
+      }
+    }
+  };
+
   return (
     <PanelSection title="Installed Games">
       {games.map((game) => (
         <PanelSectionRow key={game.appid}>
           <ButtonItem 
             layout="below"
-            onClick={() => setClickedGame(game)}
+            onClick={() => handleGameClick(game)}
           >
             {game.name} (AppID: {game.appid})
           </ButtonItem>
           {clickedGame?.appid === game.appid && (
             <div style={{ padding: '8px' }}>
-              You clicked {game.name} with AppID: {game.appid}
+              {result}
             </div>
           )}
         </PanelSectionRow>
-- 
cgit v1.2.3

