summaryrefslogtreecommitdiff
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
parenta1bb3f74d3eb6e3612c6ba3cbfffc2c59980ead0 (diff)
downloaddecky-loader-9c5801d53d28489af5f48c470daf52e90715fe79.tar.gz
decky-loader-9c5801d53d28489af5f48c470daf52e90715fe79.zip
add tabs patching api
-rw-r--r--frontend/package.json4
-rw-r--r--frontend/pnpm-lock.yaml22
-rw-r--r--frontend/src/components/DeckyQAMState.tsx124
-rw-r--r--frontend/src/hooks/tabs.tsx92
-rw-r--r--frontend/src/hooks/vr-dashboard-bar.tsx2
-rw-r--r--frontend/src/plugin-loader.tsx9
6 files changed, 216 insertions, 37 deletions
diff --git a/frontend/package.json b/frontend/package.json
index 6c34acd7..90137fba 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -13,7 +13,7 @@
"localize": "i18next"
},
"devDependencies": {
- "@decky/api": "^1.1.3",
+ "@decky/api": "^1.2.0",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-image": "^3.0.3",
"@rollup/plugin-json": "^6.1.0",
@@ -47,7 +47,7 @@
}
},
"dependencies": {
- "@decky/ui": "^5.0.0",
+ "@decky/ui": "^5.0.3",
"compare-versions": "^6.1.1",
"filesize": "^10.1.2",
"i18next": "^25.6.0",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index b0b551ad..2b3d507c 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -9,8 +9,8 @@ importers:
.:
dependencies:
'@decky/ui':
- specifier: ^5.0.0
- version: 5.0.0
+ specifier: ^5.0.3
+ version: 5.0.3
compare-versions:
specifier: ^6.1.1
version: 6.1.1
@@ -40,8 +40,8 @@ importers:
version: 4.0.0(supports-color@7.2.0)
devDependencies:
'@decky/api':
- specifier: ^1.1.3
- version: 1.1.3
+ specifier: ^1.2.0
+ version: 1.2.0
'@rollup/plugin-commonjs':
specifier: ^26.0.1
version: 26.0.1(rollup@4.22.4)
@@ -219,11 +219,11 @@ packages:
resolution: {integrity: sha512-XEFXSlxiG5td2EJRe8vOmRbaXVgfcBlszKujvVmWIK/UpywWljQCfzAv3RQCGujWQ1RD4YYWEAqDXfuJiy8f5Q==}
engines: {node: '>=6.9.0'}
- '@decky/api@1.1.3':
- resolution: {integrity: sha512-XsPCZxfxk5I1UtylIUN3qaWQI31siQbKfbLIskkI5innEatY1m4NQqBv/6hwPaO9mKMbdqYpnh5PSJDeMEOOBA==}
+ '@decky/api@1.2.0':
+ resolution: {integrity: sha512-QT+kayqA32YQQNgGwqqoRZ2iAfmdyYa9BgCtpGojyPn/QdhGxG9Lu4+EVek9ZI2CC7ppWgvsoh+sOe1Hodzg4w==}
- '@decky/ui@5.0.0':
- resolution: {integrity: sha512-gOgB49uv4qSaMhIspfpqS5qJVbo7XXOgDFbIkaQ+bbOeqykC4CA39pUs8SiwaJL1gsRNtMh7Ed3DkRbTcLhgRA==}
+ '@decky/ui@5.0.3':
+ resolution: {integrity: sha512-x7vaf4GFVqj+ejeRjqkn6/DJzNkYEDX7S3qB9xLMFs1Dda2noI4HXbUAO/3bWMYLU1JFjnm4kepa5fBrti0RDg==}
'@esbuild/aix-ppc64@0.20.2':
resolution: {integrity: sha512-D+EBOJHXdNZcLJRBkhENNG8Wji2kgc9AZ9KiPr1JuZjsNtyHzrsfLRrY0tk2H2aoFu6RANO1y1iPPUCDYWkb5g==}
@@ -2321,9 +2321,11 @@ snapshots:
'@babel/helper-validator-identifier': 7.24.7
to-fast-properties: 2.0.0
- '@decky/api@1.1.3': {}
+ '@decky/api@1.2.0':
+ dependencies:
+ '@decky/ui': 5.0.3
- '@decky/ui@5.0.0': {}
+ '@decky/ui@5.0.3': {}
'@esbuild/aix-ppc64@0.20.2':
optional: true
diff --git a/frontend/src/components/DeckyQAMState.tsx b/frontend/src/components/DeckyQAMState.tsx
new file mode 100644
index 00000000..48dd8971
--- /dev/null
+++ b/frontend/src/components/DeckyQAMState.tsx
@@ -0,0 +1,124 @@
+import { QuickAccessTab } from '@decky/ui';
+import { FC, ReactNode, createContext, useContext, useEffect, useState } from 'react';
+import Logger from '../logger';
+
+export interface Tab {
+ id: QuickAccessTab | number;
+ title: ReactNode;
+ content: ReactNode;
+ icon: ReactNode;
+}
+
+export interface TabData {
+ key: QuickAccessTab | number;
+ title: ReactNode;
+ tab: ReactNode;
+ panel: ReactNode; // the component
+ decky?: boolean;
+ initialVisibility?: boolean;
+}
+
+export type TabPatch = (tab: TabData) => TabData;
+
+interface PublicDeckyQAMState {
+ tabs: Tab[];
+ patches: Map<QuickAccessTab | number, Set<TabPatch>>;
+}
+
+export class DeckyQAMState extends Logger {
+ private _tabs: Tab[] = [];
+ private _patches = new Map<QuickAccessTab | number, Set<TabPatch>>();
+
+ public eventBus = new EventTarget();
+
+ constructor() {
+ super('DeckyQAMState');
+ }
+
+ publicState(): PublicDeckyQAMState {
+ return { tabs: this._tabs, patches: this._patches };
+ }
+
+ add(tab: Tab) {
+ this.debug('Adding tab', tab.id, 'to render array');
+ this._tabs.push(tab);
+ this.notifyUpdate();
+ }
+
+ removeById(id: QuickAccessTab | number) {
+ this.debug('Removing tab', id);
+ this._tabs = this._tabs.filter((tab) => tab.id !== id);
+ this.notifyUpdate();
+ }
+
+ addPatch(tab: QuickAccessTab | number, patch: TabPatch) {
+ let patchList = this._patches.get(tab);
+ if (!patchList) {
+ patchList = new Set();
+ this._patches.set(tab, patchList);
+ }
+ patchList.add(patch);
+ this.notifyUpdate();
+ return patch;
+ }
+
+ removePatch(tab: QuickAccessTab | number, patch: TabPatch) {
+ const patchList = this._patches.get(tab);
+ patchList?.delete(patch);
+ if (patchList?.size == 0) {
+ this._patches.delete(tab);
+ }
+ this.notifyUpdate();
+ }
+
+ private notifyUpdate() {
+ this.eventBus.dispatchEvent(new Event('update'));
+ }
+}
+
+interface DeckyQAMStateContext extends PublicDeckyQAMState {
+ add(tab: Tab): void;
+ removeById(id: QuickAccessTab | number): void;
+ addPatch(tab: QuickAccessTab | number, patch: TabPatch): TabPatch;
+ removePatch(tab: QuickAccessTab | number, patch: TabPatch): void;
+ visible: boolean;
+}
+
+const DeckyQAMStateContext = createContext<DeckyQAMStateContext>(null as any);
+
+export const useDeckyQAMState = () => useContext(DeckyQAMStateContext);
+
+interface Props {
+ deckyQAMState: DeckyQAMState;
+ visible: boolean;
+ children: ReactNode;
+}
+
+export const DeckyQAMStateContextProvider: FC<Props> = ({ children, deckyQAMState, visible }) => {
+ const [publicDeckyQAMState, setPublicDeckyQAMState] = useState<PublicDeckyQAMState>({
+ ...deckyQAMState.publicState(),
+ });
+
+ useEffect(() => {
+ function onUpdate() {
+ setPublicDeckyQAMState({ ...deckyQAMState.publicState() });
+ }
+
+ deckyQAMState.eventBus.addEventListener('update', onUpdate);
+
+ return () => deckyQAMState.eventBus.removeEventListener('update', onUpdate);
+ }, []);
+
+ const add = deckyQAMState.add.bind(deckyQAMState);
+ const removeById = deckyQAMState.removeById.bind(deckyQAMState);
+ const addPatch = deckyQAMState.addPatch.bind(deckyQAMState);
+ const removePatch = deckyQAMState.removePatch.bind(deckyQAMState);
+
+ return (
+ <DeckyQAMStateContext.Provider
+ value={{ ...publicDeckyQAMState, add, removeById, addPatch, removePatch, visible }}
+ >
+ {children}
+ </DeckyQAMStateContext.Provider>
+ );
+};
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(
diff --git a/frontend/src/plugin-loader.tsx b/frontend/src/plugin-loader.tsx
index b16e1bb1..1427cf10 100644
--- a/frontend/src/plugin-loader.tsx
+++ b/frontend/src/plugin-loader.tsx
@@ -755,7 +755,7 @@ class PluginLoader extends Logger {
// Things will break *very* badly if plugin code touches this outside of @decky/api, so lets make that clear.
window.__DECKY_SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_deckyLoaderAPIInit = {
connect: (version: number, pluginName: string) => {
- if (version < 1 || version > 2) {
+ if (version < 1 || version > 3) {
console.warn(`Plugin ${pluginName} requested unsupported api version ${version}.`);
}
@@ -804,6 +804,11 @@ class PluginLoader extends Logger {
backendAPI.useQuickAccessVisible = useQuickAccessVisible;
}
+ if (version >= 3) {
+ backendAPI._version = 3;
+ backendAPI.tabsHook = this.tabsHook;
+ }
+
// Note: version info not available at connection time
this.debug(`Plugin ${pluginName} connected to loader API.`);
return backendAPI;
@@ -829,8 +834,6 @@ class PluginLoader extends Logger {
}
})();
}
- } else {
- this.warn(`event ${event} has no listeners`);
}
};