From 80a00a0d35655791a4e2bc697ad0748fe2c2f9ad Mon Sep 17 00:00:00 2001
From: AAGaming <aagaming@riseup.net>
Date: Tue, 12 Dec 2023 22:21:25 -0500
Subject: fix: Adjust tabs and toaster hooks to work on react 18, also half-fix
 Valve Internal

---
 frontend/src/developer.tsx | 48 +++++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

(limited to 'frontend/src/developer.tsx')

diff --git a/frontend/src/developer.tsx b/frontend/src/developer.tsx
index 43f550d7..50b3e4e4 100644
--- a/frontend/src/developer.tsx
+++ b/frontend/src/developer.tsx
@@ -9,32 +9,40 @@ const logger = new Logger('DeveloperMode');
 
 let removeSettingsObserver: () => void = () => {};
 
-export async function setShowValveInternal(show: boolean) {
-  let settingsMod: any;
-  while (!settingsMod) {
-    settingsMod = findModuleChild((m) => {
-      if (typeof m !== 'object') return undefined;
-      for (let prop in m) {
-        if (typeof m[prop]?.settings?.bIsValveEmail !== 'undefined') return m[prop];
-      }
-    });
-    if (!settingsMod) {
-      logger.debug('[ValveInternal] waiting for settingsMod');
-      await sleep(1000);
-    }
+declare global {
+  interface Window {
+    settingsStore: any;
   }
+}
 
+export async function setShowValveInternal(show: boolean) {
   if (show) {
-    removeSettingsObserver = settingsMod[
-      Object.getOwnPropertySymbols(settingsMod).find((x) => x.toString() == 'Symbol(mobx administration)') as any
-    ].observe((e: any) => {
-      e.newValue.bIsValveEmail = true;
-    });
-    settingsMod.m_Settings.bIsValveEmail = true;
+    const mobx =
+      window.settingsStore[
+        Object.getOwnPropertySymbols(window.settingsStore).find(
+          (x) => x.toString() == 'Symbol(mobx administration)',
+        ) as any
+      ];
+
+    if (mobx.observe_) {
+      // New style, currently broken
+      logger.log('Valve internal not yet supported on this build.');
+      // removeSettingsObserver = mobx.observe_(mobx, [(e: any) => {
+      //   console.log("got e", e)
+      //   e.newValue.bIsValveEmail = true;
+      // }]);
+    } else if (mobx.observe) {
+      // Old style
+      removeSettingsObserver = mobx.observe((e: any) => {
+        e.newValue.bIsValveEmail = true;
+      });
+    }
+
+    window.settingsStore.m_Settings.bIsValveEmail = true;
     logger.log('Enabled Valve Internal menu');
   } else {
     removeSettingsObserver();
-    settingsMod.m_Settings.bIsValveEmail = false;
+    window.settingsStore.m_Settings.bIsValveEmail = false;
     logger.log('Disabled Valve Internal menu');
   }
 }
-- 
cgit v1.2.3

