@steambrew/client
Version:
A support library for creating plugins with Millennium.
56 lines (55 loc) • 2.18 kB
JavaScript
import { createElement, useEffect, useState } from 'react';
import { fakeRenderComponent, findInReactTree, sleep } from '../utils';
import { findModuleByExport } from '../webpack';
import { SteamSpinner } from './SteamSpinner';
let tabsComponent;
const getTabs = async () => {
if (tabsComponent)
return tabsComponent;
// @ts-ignore
while (!window?.DeckyPluginLoader?.routerHook?.routes) {
console.debug('[DFL:Tabs]: Waiting for Decky router...');
await sleep(500);
}
return (tabsComponent = fakeRenderComponent(() => {
return findInReactTree(findInReactTree(
// @ts-ignore
window.DeckyPluginLoader.routerHook.routes
.find((x) => x.props.path == '/library/app/:appid/achievements')
.props.children.type(), (x) => x?.props?.scrollTabsTop).type({ appid: 1 }), (x) => x?.props?.tabs).type;
}, {
useRef: () => ({ current: { reaction: { track: () => { } } } }),
useContext: () => ({ match: { params: { appid: 1 } } }),
useMemo: () => ({ data: {} }),
}));
};
let oldTabs;
try {
const oldTabsModule = findModuleByExport((e) => e.Unbleed);
if (oldTabsModule)
oldTabs = Object.values(oldTabsModule).find((x) => x?.type?.toString()?.includes('((function(){'));
}
catch (e) {
console.error('Error finding oldTabs:', e);
}
/**
* Tabs component as used in the library and media tabs. See {@link TabsProps}.
* Unlike other components in `decky-frontend-lib`, this requires Decky Loader to be running.
*/
export const Tabs = (oldTabs ||
((props) => {
const found = tabsComponent;
const [tc, setTC] = useState(found);
useEffect(() => {
if (found)
return;
(async () => {
console.debug('[DFL:Tabs]: Finding component...');
const t = await getTabs();
console.debug('[DFL:Tabs]: Found!');
setTC(t);
})();
}, []);
console.log('tc', tc);
return tc ? createElement(tc, props) : window.SP_REACT.createElement(SteamSpinner, null);
}));