Skip to content

Commit

Permalink
refactor(LibraryContextMenu): arguably better way to get menu component
Browse files Browse the repository at this point in the history
Also fixes 3.5
  • Loading branch information
doZennn committed Sep 16, 2023
1 parent c4d836c commit a583a70
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/patches/contextMenuPatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
afterPatch,
fakeRenderComponent,
findInReactTree,
findInTree,
findModuleChild,
MenuItem,
Navigation,
} from 'decky-frontend-lib';
Expand Down Expand Up @@ -79,20 +79,23 @@ export const getMenu = async () => {
await new Promise((resolve) => setTimeout(resolve, 500));
}

let LibraryContextMenu = findInReactTree(
fakeRenderComponent(
findInTree(
fakeRenderComponent(
// @ts-ignore: decky global is not typed
window.DeckyPluginLoader.routerHook.routes.find((x) => x?.props?.path == '/zoo').props.children.type
), (x) => x?.route === '/zoo/modals',
{
walkable: ['props', 'children', 'child', 'pages'],
let LibraryContextMenu = fakeRenderComponent(
findModuleChild((m) => {
if (typeof m !== 'object') return;
for (const prop in m) {
if (
m[prop]?.toString() &&
m[prop].toString().includes('().LibraryContextMenu')
) {
return Object.values(m).find((sibling) => (
sibling?.toString().includes('createElement') &&
sibling?.toString().includes('navigator:')
));
}
).content.type
),
(x) => x?.title?.includes('AppActionsMenu')
).children.type;
}
return;
})
).type;

if (!LibraryContextMenu?.prototype?.AddToHidden) {
LibraryContextMenu = fakeRenderComponent(LibraryContextMenu).type;
Expand Down

0 comments on commit a583a70

Please sign in to comment.