From 58b69f0d6c43356c4f0ed183802d5bf7fb80e978 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Sun, 15 Jan 2023 20:22:54 -0500 Subject: [PATCH] fix(Navigation): fix timing issue in decky-loader --- src/deck-components/Router.tsx | 100 +++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/src/deck-components/Router.tsx b/src/deck-components/Router.tsx index 919f8fb..75afe08 100644 --- a/src/deck-components/Router.tsx +++ b/src/deck-components/Router.tsx @@ -1,3 +1,4 @@ +import { sleep } from '../utils'; import { Module, findModuleChild } from '../webpack'; export enum SideMenu { @@ -107,16 +108,6 @@ export const Router = findModuleChild((m: Module) => { } }) as Router; -// With how much Valve is changing these, you really shouldn't use them directly, instead see Navigation -export const InternalNavigators = findModuleChild((m: any) => { - if (typeof m !== 'object') return undefined; - for (let prop in m) { - if (m[prop]?.GetNavigator) { - return m[prop]; - } - } -})?.GetNavigator() - export interface Navigation { Navigate(path: string): void; NavigateBack(): void; @@ -138,35 +129,62 @@ export interface Navigation { export let Navigation = {} as Navigation; try { - Navigation = { - Navigate: Router.Navigate.bind(Router), - NavigateBack: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateBack.bind( - Router.WindowStore.GamepadUIMainWindowInstance, - ), - NavigateToAppProperties: InternalNavigators?.AppProperties || Router.NavigateToAppProperties.bind(Router), - NavigateToExternalWeb: Router.NavigateToExternalWeb.bind(Router), - NavigateToInvites: InternalNavigators?.Invites || Router.NavigateToInvites.bind(Router), - NavigateToChat: Router.NavigateToChat.bind(Router), - NavigateToLibraryTab: InternalNavigators?.LibraryTab || Router.NavigateToLibraryTab.bind(Router), - NavigateToLayoutPreview: Router.NavigateToLayoutPreview.bind(Router), - NavigateToSteamWeb: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateToSteamWeb.bind( - Router.WindowStore.GamepadUIMainWindowInstance, - ), - NavigateToWebRoute: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateToWebRoute.bind( - Router.WindowStore.GamepadUIMainWindowInstance, - ), - OpenSideMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenSideMenu.bind( - Router.WindowStore.GamepadUIMainWindowInstance.MenuStore, - ), - OpenQuickAccessMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenQuickAccessMenu.bind( - Router.WindowStore.GamepadUIMainWindowInstance.MenuStore, - ), - OpenMainMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenMainMenu.bind( - Router.WindowStore.GamepadUIMainWindowInstance.MenuStore, - ), - CloseSideMenus: Router.CloseSideMenus.bind(Router), - OpenPowerMenu: Router.OpenPowerMenu.bind(Router), - } as Navigation; + (async () => { + // With how much Valve is changing these, you really shouldn't use them directly, instead see Navigation + let InternalNavigators: any; + function initInternalNavigators() { + try { + InternalNavigators = findModuleChild((m: any) => { + if (typeof m !== 'object') return undefined; + for (let prop in m) { + if (m[prop]?.GetNavigator) { + return m[prop]; + } + } + })?.GetNavigator(); + } catch (e) { + console.error('[DFL:Router]: Failed to init internal navigators, trying again'); + } + } + initInternalNavigators(); + while (!InternalNavigators?.AppProperties) { + console.log('[DFL:Router]: Trying to init internal navigators again'); + await sleep(100); + initInternalNavigators(); + } + console.log("got navigators", InternalNavigators) + const newNavigation = { + Navigate: Router.Navigate.bind(Router), + NavigateBack: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateBack.bind( + Router.WindowStore.GamepadUIMainWindowInstance, + ), + NavigateToAppProperties: InternalNavigators?.AppProperties || Router.NavigateToAppProperties.bind(Router), + NavigateToExternalWeb: Router.NavigateToExternalWeb.bind(Router), + NavigateToInvites: InternalNavigators?.Invites || Router.NavigateToInvites.bind(Router), + NavigateToChat: Router.NavigateToChat.bind(Router), + NavigateToLibraryTab: InternalNavigators?.LibraryTab || Router.NavigateToLibraryTab.bind(Router), + NavigateToLayoutPreview: Router.NavigateToLayoutPreview.bind(Router), + NavigateToSteamWeb: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateToSteamWeb.bind( + Router.WindowStore.GamepadUIMainWindowInstance, + ), + NavigateToWebRoute: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateToWebRoute.bind( + Router.WindowStore.GamepadUIMainWindowInstance, + ), + OpenSideMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenSideMenu.bind( + Router.WindowStore.GamepadUIMainWindowInstance.MenuStore, + ), + OpenQuickAccessMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenQuickAccessMenu.bind( + Router.WindowStore.GamepadUIMainWindowInstance.MenuStore, + ), + OpenMainMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenMainMenu.bind( + Router.WindowStore.GamepadUIMainWindowInstance.MenuStore, + ), + CloseSideMenus: Router.CloseSideMenus.bind(Router), + OpenPowerMenu: Router.OpenPowerMenu.bind(Router), + } as Navigation; + + Object.assign(Navigation, newNavigation); + })(); } catch (e) { - console.error("[DFL:Router]: Error initializing Navigation interface", e) -} \ No newline at end of file + console.error('[DFL:Router]: Error initializing Navigation interface', e); +}