From 3c00eb8cf4f5b02b8ec87fc1d9ccdd70221dd916 Mon Sep 17 00:00:00 2001
From: AAGaming <aa@mail.catvibers.me>
Date: Sat, 1 Oct 2022 21:22:30 -0400
Subject: fix friends menu focusing itself

---
 frontend/src/toaster.tsx | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

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

diff --git a/frontend/src/toaster.tsx b/frontend/src/toaster.tsx
index fcf89abb..d03163eb 100644
--- a/frontend/src/toaster.tsx
+++ b/frontend/src/toaster.tsx
@@ -1,4 +1,14 @@
-import { Patch, ToastData, afterPatch, findInReactTree, findModuleChild, sleep } from 'decky-frontend-lib';
+import {
+  Patch,
+  ToastData,
+  afterPatch,
+  callOriginal,
+  findInReactTree,
+  findModuleChild,
+  replacePatch,
+  sleep,
+  staticClasses,
+} from 'decky-frontend-lib';
 import { ReactNode } from 'react';
 
 import Toast from './components/Toast';
@@ -27,6 +37,25 @@ class Toaster extends Logger {
 
   async init() {
     let instance: any;
+    const focusManager = findModuleChild((m) => {
+      if (typeof m !== 'object') return false;
+      for (let prop in m) {
+        if (m[prop]?.prototype?.TakeFocus) return m[prop];
+      }
+      return false;
+    });
+
+    const focusWorkaroundPatch = replacePatch(focusManager.prototype, 'BFocusWithin', function () {
+      // @ts-ignore
+      console.log(this as any);
+      // @ts-ignore
+      if (this.m_node?.m_element && this.m_node?.m_element.classList.contains(staticClasses.TabGroupPanel)) {
+        console.log('got the focus hook');
+        return true;
+      }
+
+      return callOriginal;
+    });
     while (true) {
       instance = findInReactTree(
         (document.getElementById('root') as any)._reactRootContainer._internalRoot.current,
@@ -71,6 +100,7 @@ class Toaster extends Logger {
         if (typeof m[prop]?.settings && m[prop]?.communityPreferences) return m[prop];
       }
     });
+    focusWorkaroundPatch.unpatch();
     this.log('Initialized');
     this.ready = true;
   }
-- 
cgit v1.2.3

