From 234ac6e00c4e9e337e4c88829deee665d1a5303c Mon Sep 17 00:00:00 2001
From: xXJSONDeruloXx <danielhimebauch@gmail.com>
Date: Mon, 18 Aug 2025 12:08:21 -0400
Subject: lock profile selection if game is running

---
 src/components/ProfileManagement.tsx | 47 +++++++++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 9 deletions(-)

(limited to 'src/components/ProfileManagement.tsx')

diff --git a/src/components/ProfileManagement.tsx b/src/components/ProfileManagement.tsx
index 67f0645..46c507c 100644
--- a/src/components/ProfileManagement.tsx
+++ b/src/components/ProfileManagement.tsx
@@ -11,7 +11,9 @@ import {
   ButtonItem,
   ModalRoot,
   TextField,
-  Focusable
+  Focusable,
+  AppOverview,
+  Router
 } from "@decky/ui";
 import { 
   getProfiles, 
@@ -24,11 +26,6 @@ import {
 } from "../api/lsfgApi";
 import { showSuccessToast, showErrorToast } from "../utils/toastUtils";
 
-interface ProfileManagementProps {
-  currentProfile?: string;
-  onProfileChange?: (profileName: string) => void;
-}
-
 interface TextInputModalProps {
   title: string;
   description: string;
@@ -110,6 +107,7 @@ export function ProfileManagement({ currentProfile, onProfileChange }: ProfileMa
   const [profiles, setProfiles] = useState<string[]>([]);
   const [selectedProfile, setSelectedProfile] = useState<string>(currentProfile || "decky-lsfg-vk");
   const [isLoading, setIsLoading] = useState(false);
+  const [mainRunningApp, setMainRunningApp] = useState<AppOverview | undefined>(undefined);
 
   // Load profiles on component mount
   useEffect(() => {
@@ -123,6 +121,22 @@ export function ProfileManagement({ currentProfile, onProfileChange }: ProfileMa
     }
   }, [currentProfile]);
 
+  // Poll for running app every 2 seconds
+  useEffect(() => {
+    const checkRunningApp = () => {
+      setMainRunningApp(Router.MainRunningApp);
+    };
+
+    // Check immediately
+    checkRunningApp();
+
+    // Set up polling interval
+    const interval = setInterval(checkRunningApp, 2000);
+
+    // Cleanup interval on unmount
+    return () => clearInterval(interval);
+  }, []);
+
   const loadProfiles = async () => {
     try {
       const result: ProfilesResult = await getProfiles();
@@ -301,6 +315,21 @@ export function ProfileManagement({ currentProfile, onProfileChange }: ProfileMa
 
   return (
     <PanelSection title="Select Profile">
+      {/* Display currently running game info */}
+      {mainRunningApp && (
+        <PanelSectionRow>
+          <div style={{ 
+            padding: "8px 12px", 
+            backgroundColor: "rgba(0, 255, 0, 0.1)", 
+            borderRadius: "4px",
+            border: "1px solid rgba(0, 255, 0, 0.3)",
+            fontSize: "13px"
+          }}>
+            <strong>{mainRunningApp.display_name}</strong> running. Close game to change profile.
+          </div>
+        </PanelSectionRow>
+      )}
+      
       <PanelSectionRow>
         <Field
           label=""
@@ -311,7 +340,7 @@ export function ProfileManagement({ currentProfile, onProfileChange }: ProfileMa
             rgOptions={profileOptions}
             selectedOption={selectedProfile}
             onChange={handleDropdownChange}
-            disabled={isLoading}
+            disabled={isLoading || !!mainRunningApp}
           />
         </Field>
       </PanelSectionRow>
@@ -320,7 +349,7 @@ export function ProfileManagement({ currentProfile, onProfileChange }: ProfileMa
         <ButtonItem
           layout="below"
           onClick={handleRenameProfile}
-          disabled={isLoading || selectedProfile === "decky-lsfg-vk"}
+          disabled={isLoading || selectedProfile === "decky-lsfg-vk" || !!mainRunningApp}
         >
           Rename
         </ButtonItem>
@@ -330,7 +359,7 @@ export function ProfileManagement({ currentProfile, onProfileChange }: ProfileMa
         <ButtonItem
           layout="below"
           onClick={handleDeleteProfile}
-          disabled={isLoading || selectedProfile === "decky-lsfg-vk"}
+          disabled={isLoading || selectedProfile === "decky-lsfg-vk" || !!mainRunningApp}
         >
           Delete
         </ButtonItem>
-- 
cgit v1.2.3

