fix friends menu focusing itself

This commit is contained in:
AAGaming
2022-10-01 21:22:30 -04:00
parent 21e1d8504a
commit 3c00eb8cf4
3 changed files with 33 additions and 2 deletions

View File

@@ -32,7 +32,7 @@ const PluginView: VFC = () => {
.map(({ name, icon }) => (
<PanelSectionRow key={name}>
<ButtonItem layout="below" onClick={() => setActivePlugin(name)}>
<div style={{ display: 'flex', alignItems: "center", justifyContent: 'space-between' }}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
{icon}
<div>{name}</div>
<NotificationBadge show={updates?.has(name)} style={{ top: '-5px', right: '-5px' }} />

View File

@@ -101,6 +101,7 @@ class TabsHook extends Logger {
});
this.cNode = scrollRoot;
this.cNode.stateNode.forceUpdate();
this.log('Finished initial injection');
})();
}

View File

@@ -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;
}