mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-06-17 08:47:49 +00:00
Replace tabs hook, fix panels, bump lib
This commit is contained in:
+2
-2
@@ -167,8 +167,8 @@ pnpmtransbundle() {
|
|||||||
pnpm i &> '/dev/null'
|
pnpm i &> '/dev/null'
|
||||||
pnpm run build &> '/dev/null'
|
pnpm run build &> '/dev/null'
|
||||||
elif [[ "$2" == "template" ]]; then
|
elif [[ "$2" == "template" ]]; then
|
||||||
pnpm i
|
pnpm i &> '/dev/null'
|
||||||
pnpm run build
|
pnpm run build &> '/dev/null'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"decky-frontend-lib": "^0.10.2",
|
"decky-frontend-lib": "^0.11.0",
|
||||||
"react-icons": "^4.4.0"
|
"react-icons": "^4.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,10 +117,10 @@ class PluginLoader extends Logger {
|
|||||||
private async importReactPlugin(name: string) {
|
private async importReactPlugin(name: string) {
|
||||||
let res = await fetch(`http://127.0.0.1:1337/plugins/${name}/frontend_bundle`);
|
let res = await fetch(`http://127.0.0.1:1337/plugins/${name}/frontend_bundle`);
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
let { name: _, content } = await eval(await res.text())(this.createPluginAPI(name));
|
let plugin = await eval(await res.text())(this.createPluginAPI(name));
|
||||||
this.plugins.push({
|
this.plugins.push({
|
||||||
name: name,
|
name: name,
|
||||||
...content,
|
...plugin,
|
||||||
});
|
});
|
||||||
} else throw new Error(`${name} frontend_bundle not OK`);
|
} else throw new Error(`${name} frontend_bundle not OK`);
|
||||||
}
|
}
|
||||||
|
|||||||
+75
-10
@@ -1,3 +1,6 @@
|
|||||||
|
import { afterPatch, sleep, unpatch } from 'decky-frontend-lib';
|
||||||
|
import { memo } from 'react';
|
||||||
|
|
||||||
import Logger from './logger';
|
import Logger from './logger';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@@ -11,7 +14,7 @@ declare global {
|
|||||||
|
|
||||||
const isTabsArray = (tabs: any) => {
|
const isTabsArray = (tabs: any) => {
|
||||||
const length = tabs.length;
|
const length = tabs.length;
|
||||||
return length === 7 && tabs[length - 1]?.key === 6 && tabs[length - 1]?.tab;
|
return length >= 7 && tabs[length - 1]?.tab;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Tab {
|
interface Tab {
|
||||||
@@ -24,24 +27,86 @@ interface Tab {
|
|||||||
class TabsHook extends Logger {
|
class TabsHook extends Logger {
|
||||||
// private keys = 7;
|
// private keys = 7;
|
||||||
tabs: Tab[] = [];
|
tabs: Tab[] = [];
|
||||||
|
private quickAccess: any;
|
||||||
|
private tabRenderer: any;
|
||||||
|
private memoizedQuickAccess: any;
|
||||||
|
private cNode: any;
|
||||||
|
|
||||||
|
private qAPTree: any;
|
||||||
|
private rendererTree: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super('TabsHook');
|
super('TabsHook');
|
||||||
|
|
||||||
this.log('Initialized');
|
this.log('Initialized');
|
||||||
|
window.__TABS_HOOK_INSTANCE?.deinit?.();
|
||||||
window.__TABS_HOOK_INSTANCE = this;
|
window.__TABS_HOOK_INSTANCE = this;
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
const tree = (document.getElementById('root') as any)._reactRootContainer._internalRoot.current;
|
||||||
const filter = Array.prototype.__filter ?? Array.prototype.filter;
|
let scrollRoot: any;
|
||||||
Array.prototype.__filter = filter;
|
let currentNode = tree;
|
||||||
Array.prototype.filter = function (...args: any[]) {
|
(async () => {
|
||||||
if (isTabsArray(this)) {
|
let iters = 0;
|
||||||
self.render(this);
|
while (!scrollRoot) {
|
||||||
|
iters++;
|
||||||
|
currentNode = currentNode?.child;
|
||||||
|
if (iters >= 30 || !currentNode) {
|
||||||
|
iters = 0;
|
||||||
|
currentNode = tree;
|
||||||
|
await sleep(5000);
|
||||||
|
}
|
||||||
|
if (currentNode?.type?.prototype?.RemoveSmartScrollContainer) scrollRoot = currentNode;
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
let newQA: any;
|
||||||
return filter.call(this, ...args);
|
let newQATabRenderer: any;
|
||||||
};
|
afterPatch(scrollRoot.stateNode, 'render', (_: any, ret: any) => {
|
||||||
|
if (!this.quickAccess && ret.props.children.props.children[4]) {
|
||||||
|
this.quickAccess = ret?.props?.children?.props?.children[4].type;
|
||||||
|
newQA = (...args: any) => {
|
||||||
|
const ret = this.quickAccess.type(...args);
|
||||||
|
if (ret) {
|
||||||
|
if (!newQATabRenderer) {
|
||||||
|
this.tabRenderer = ret.props.children[1].children.type;
|
||||||
|
newQATabRenderer = (...args: any) => {
|
||||||
|
const oFilter = Array.prototype.filter;
|
||||||
|
Array.prototype.filter = function (...args: any[]) {
|
||||||
|
if (isTabsArray(this)) {
|
||||||
|
self.render(this);
|
||||||
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
return oFilter.call(this, ...args);
|
||||||
|
};
|
||||||
|
// TODO remove array hack entirely and use this instead const tabs = ret.props.children.props.children[0].props.children[1].props.children[0].props.children[0].props.tabs
|
||||||
|
const ret = this.tabRenderer(...args);
|
||||||
|
Array.prototype.filter = oFilter;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.rendererTree = ret.props.children[1].children;
|
||||||
|
ret.props.children[1].children.type = newQATabRenderer;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
this.memoizedQuickAccess = memo(newQA);
|
||||||
|
this.memoizedQuickAccess.isDeckyQuickAccess = true;
|
||||||
|
}
|
||||||
|
if (ret.props.children.props.children[4]) {
|
||||||
|
this.qAPTree = ret.props.children.props.children[4];
|
||||||
|
ret.props.children.props.children[4].type = this.memoizedQuickAccess;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
});
|
||||||
|
this.cNode = scrollRoot;
|
||||||
|
this.cNode.stateNode.forceUpdate();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit() {
|
||||||
|
unpatch(this.cNode.stateNode, 'render');
|
||||||
|
if (this.qAPTree) this.qAPTree.type = this.quickAccess;
|
||||||
|
if (this.rendererTree) this.rendererTree.type = this.tabRenderer;
|
||||||
|
if (this.cNode) this.cNode.stateNode.forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
add(tab: Tab) {
|
add(tab: Tab) {
|
||||||
|
|||||||
Reference in New Issue
Block a user