summaryrefslogtreecommitdiff
path: root/frontend/src/hooks
diff options
context:
space:
mode:
authorAAGaming <aagaming@riseup.net>2026-12-04 01:16:57 -0500
committerAAGaming <aagaming@riseup.net>2026-12-04 01:16:57 -0500
commit9c5801d53d28489af5f48c470daf52e90715fe79 (patch)
tree50c631c3a42c9cc8343307fd4d142425543d637e /frontend/src/hooks
parenta1bb3f74d3eb6e3612c6ba3cbfffc2c59980ead0 (diff)
downloaddecky-loader-9c5801d53d28489af5f48c470daf52e90715fe79.tar.gz
decky-loader-9c5801d53d28489af5f48c470daf52e90715fe79.zip
add tabs patching api
Diffstat (limited to 'frontend/src/hooks')
-rw-r--r--frontend/src/hooks/tabs.tsx92
-rw-r--r--frontend/src/hooks/vr-dashboard-bar.tsx2
2 files changed, 72 insertions, 22 deletions
diff --git a/frontend/src/hooks/tabs.tsx b/frontend/src/hooks/tabs.tsx
index 35f05472..802f2371 100644
--- a/frontend/src/hooks/tabs.tsx
+++ b/frontend/src/hooks/tabs.tsx
@@ -12,6 +12,8 @@ import {
import { QuickAccessVisibleStateProvider } from '../components/QuickAccessVisibleState';
import Logger from '../logger';
+import { DeckyQAMState, DeckyQAMStateContextProvider, Tab, TabData, TabPatch, useDeckyQAMState } from '../components/DeckyQAMState';
+import { cloneElement, createElement, ReactNode } from 'react';
declare global {
interface Window {
@@ -19,18 +21,13 @@ declare global {
}
}
-interface Tab {
- id: QuickAccessTab | number;
- title: any;
- content: any;
- icon: any;
-}
+const isPatched = Symbol('is patched');
class TabsHook extends Logger {
- // private keys = 7;
- tabs: Tab[] = [];
+ private qamState: DeckyQAMState = new DeckyQAMState();
private qamBrowserViewPatch?: Patch;
private qamEmbeddedPatch?: Patch;
+ private toReplace = new Map<QuickAccessTab | number, ReactNode>();
constructor() {
super('TabsHook');
@@ -49,12 +46,19 @@ class TabsHook extends Logger {
e?.type?.toString?.()?.includes('QuickAccessMenuEmbedded'),
);
+ const DeckyQAMWrapper = this.render.bind(this);
+
const patchHandler = createReactTreePatcher(
[(tree) => findInReactTree(tree, (node) => node?.props?.onFocusNavDeactivated)],
(args, ret) => {
- const tabs = findInReactTree(ret, (x) => x?.props?.tabs);
- this.render(tabs.props.tabs, args[0].visible);
- return ret;
+ if (ret._decky) {
+ return ret;
+ }
+ const returnVal = <DeckyQAMStateContextProvider deckyQAMState={this.qamState} visible={args[0].visible}>
+ <DeckyQAMWrapper>{ret}</DeckyQAMWrapper>
+ </DeckyQAMStateContextProvider>
+ (returnVal as any)._decky = true;
+ return returnVal;
},
'TabsHook',
);
@@ -87,18 +91,61 @@ class TabsHook extends Logger {
}
add(tab: Tab) {
- this.debug('Adding tab', tab.id, 'to render array');
- this.tabs.push(tab);
+ return this.qamState.add(tab);
+ }
+
+ removeById(id: QuickAccessTab | number) {
+ return this.qamState.removeById(id);
+ }
+
+ addPatch(tab: QuickAccessTab | number, patch: TabPatch) {
+ return this.qamState.addPatch(tab, patch);
}
- removeById(id: number) {
- this.debug('Removing tab', id);
- this.tabs = this.tabs.filter((tab) => tab.id !== id);
+ removePatch(tab: QuickAccessTab | number, patch: TabPatch) {
+ return this.qamState.removePatch(tab, patch);
}
- render(existingTabs: any[], visible: boolean) {
+ private render({children}: {children: any[]}) {
+ const { tabs, patches, visible } = useDeckyQAMState();
+ const existingTabs = findInReactTree(children, (x) => x?.props?.tabs).props.tabs;
let deckyTabAmount = existingTabs.reduce((prev: any, cur: any) => (cur.decky ? prev + 1 : prev), 0);
- if (deckyTabAmount == this.tabs.length) {
+ for (const tabKey in existingTabs) {
+ let tab = existingTabs[tabKey];
+ if (!tab) continue;
+
+ const replaced = this.toReplace.get(tab.key);
+ if (replaced) {
+ existingTabs[tabKey].panel = replaced;
+ this.toReplace.delete(tab.key);
+ }
+ if (tab.key && patches.has(tab.key)) {
+ this.toReplace.set(
+ tab.key,
+ // @ts-ignore
+ existingTabs[tabKey].panel,
+ );
+ patches.get(tab.key)?.forEach((patch) => {
+ const oType = existingTabs[tabKey].panel.type;
+ existingTabs[tabKey].panel = patch({
+ ...existingTabs[tabKey].props,
+ panel: {
+ ...cloneElement(existingTabs[tabKey].panel),
+ type: existingTabs[tabKey].panel[isPatched] ? oType : (props) => createElement(oType, props),
+ },
+ }).panel;
+ existingTabs[tabKey].panel[isPatched] = true;
+ });
+ }
+
+ if (patches.has(tab?.key)){
+ const patchList = patches.get(tab?.key)!;
+ for (const patch of patchList) {
+ existingTabs[tabKey] = tab = patch(tab);
+ }
+ }
+ }
+ if (deckyTabAmount == tabs.length) {
for (let tab of existingTabs) {
if (tab?.decky) {
if (tab?.qAMVisibilitySetter) {
@@ -108,15 +155,17 @@ class TabsHook extends Logger {
}
}
}
- return;
+ return children;
}
- for (const { title, icon, content, id } of this.tabs) {
- const tab: any = {
+
+ for (const { title, icon, content, id } of tabs) {
+ const tab: TabData = {
key: id,
title,
tab: icon,
decky: true,
initialVisibility: visible,
+ panel: null
};
tab.panel = (
<ErrorBoundary>
@@ -125,6 +174,7 @@ class TabsHook extends Logger {
);
existingTabs.push(tab);
}
+ return children;
}
}
diff --git a/frontend/src/hooks/vr-dashboard-bar.tsx b/frontend/src/hooks/vr-dashboard-bar.tsx
index 3fe1ad73..8ff551bd 100644
--- a/frontend/src/hooks/vr-dashboard-bar.tsx
+++ b/frontend/src/hooks/vr-dashboard-bar.tsx
@@ -84,7 +84,7 @@ class VRDashboardBarHook extends Logger {
this.renderRightSideButtons();
}
- renderRightSideButtons() {
+ private renderRightSideButtons() {
const arr = [];
for (const button of this.rightSideButtons) {
arr.push(