diff --git a/src/custom-hooks/useQuickAccessVisible.tsx b/src/custom-hooks/useQuickAccessVisible.tsx index 296e26b..e6569dc 100644 --- a/src/custom-hooks/useQuickAccessVisible.tsx +++ b/src/custom-hooks/useQuickAccessVisible.tsx @@ -1,14 +1,13 @@ import { useEffect, useState } from 'react'; -declare global { - var FocusNavController: any; -} +import { getFocusNavController } from '../utils'; function getQuickAccessWindow(): Window | null { try { - const context = FocusNavController?.m_ActiveContext || FocusNavController?.m_LastActiveContext; - const navTrees = context?.m_rgGamepadNavigationTrees || FocusNavController?.m_rgGamepadNavigationTrees; - return navTrees?.find((tree: any) => tree?.id === "QuickAccess-NA")?.m_Root?.m_element?.ownerDocument.defaultView ?? null; + const navTrees = getFocusNavController()?.m_rgGamepadNavigationTrees; + return ( + navTrees?.find((tree: any) => tree?.id === 'QuickAccess-NA')?.m_Root?.m_element?.ownerDocument.defaultView ?? null + ); } catch (error) { console.error(error); return null; diff --git a/src/deck-components/ButtonItem.tsx b/src/deck-components/ButtonItem.tsx index e27b309..4c898b2 100644 --- a/src/deck-components/ButtonItem.tsx +++ b/src/deck-components/ButtonItem.tsx @@ -7,9 +7,10 @@ export interface ButtonItemProps extends ItemProps { onClick?(e: MouseEvent): void; disabled?: boolean; } - -export const ButtonItem = Object.values(CommonUIModule).find( - (mod: any) => - mod?.render?.toString()?.includes('"highlightOnFocus","childrenContainerWidth"') || - mod?.render?.toString()?.includes('childrenContainerWidth:"min"'), -) as FC; +export const ButtonItem = + CommonUIModule.ButtonField || + (Object.values(CommonUIModule).find( + (mod: any) => + mod?.render?.toString()?.includes('"highlightOnFocus","childrenContainerWidth"') || + mod?.render?.toString()?.includes('childrenContainerWidth:"min"'), + ) as FC); diff --git a/src/deck-components/Panel.tsx b/src/deck-components/Panel.tsx index 86c9d6d..629d5d0 100644 --- a/src/deck-components/Panel.tsx +++ b/src/deck-components/Panel.tsx @@ -5,7 +5,7 @@ import { findModuleChild } from '../webpack'; export interface PanelSectionProps { title?: string; spinner?: boolean; - children?: ReactNode + children?: ReactNode; } const [panelSection, mod] = findModuleChild((mod: any) => { @@ -20,9 +20,9 @@ const [panelSection, mod] = findModuleChild((mod: any) => { export const PanelSection = panelSection as FC; export interface PanelSectionRowProps { - children?: ReactNode + children?: ReactNode; } - -export const PanelSectionRow = Object.values(mod).filter( - (exp: any) => !exp?.toString()?.includes('.PanelSection'), -)[0] as FC; +// New as of Feb 22 2023 Beta || Old +export const PanelSectionRow = + mod.PanelSectionRow || + (Object.values(mod).filter((exp: any) => !exp?.toString()?.includes('.PanelSection'))[0] as FC); diff --git a/src/deck-components/Router.tsx b/src/deck-components/Router.tsx index 9ca5c80..a86345d 100644 --- a/src/deck-components/Router.tsx +++ b/src/deck-components/Router.tsx @@ -77,7 +77,6 @@ export interface WindowRouter { NavigateToChat(): void; NavigateToSteamWeb(url: string): void; NavigateBack(): void; - NavigateToWebRoute(unknown?: any, unknown2?: any): void; } export interface WindowStore { @@ -118,7 +117,6 @@ export interface Navigation { NavigateToLibraryTab(): void; NavigateToLayoutPreview(e: unknown): void; NavigateToSteamWeb(url: string): void; - NavigateToWebRoute(unknown?: any, unknown2?: any): void; OpenSideMenu(sideMenu: SideMenu): void; OpenQuickAccessMenu(quickAccessTab?: QuickAccessTab): void; OpenMainMenu(): void; @@ -154,33 +152,30 @@ try { } } const newNavigation = { - Navigate: Router.Navigate.bind(Router), - NavigateBack: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateBack.bind( + Navigate: Router.Navigate?.bind(Router), + NavigateBack: Router.WindowStore?.GamepadUIMainWindowInstance?.NavigateBack?.bind( Router.WindowStore.GamepadUIMainWindowInstance, ), - NavigateToAppProperties: InternalNavigators?.AppProperties || Router.NavigateToAppProperties.bind(Router), - NavigateToExternalWeb: InternalNavigators?.ExternalWeb || 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( + NavigateToAppProperties: InternalNavigators?.AppProperties || Router.NavigateToAppProperties?.bind(Router), + NavigateToExternalWeb: InternalNavigators?.ExternalWeb || 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( + OpenSideMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenSideMenu?.bind( Router.WindowStore.GamepadUIMainWindowInstance.MenuStore, ), - OpenQuickAccessMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenQuickAccessMenu.bind( + OpenQuickAccessMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenQuickAccessMenu?.bind( Router.WindowStore.GamepadUIMainWindowInstance.MenuStore, ), - OpenMainMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenMainMenu.bind( + OpenMainMenu: Router.WindowStore?.GamepadUIMainWindowInstance?.MenuStore.OpenMainMenu?.bind( Router.WindowStore.GamepadUIMainWindowInstance.MenuStore, ), - CloseSideMenus: Router.CloseSideMenus.bind(Router), - OpenPowerMenu: Router.OpenPowerMenu.bind(Router), + CloseSideMenus: Router.CloseSideMenus?.bind(Router), + OpenPowerMenu: Router.OpenPowerMenu?.bind(Router), } as Navigation; Object.assign(Navigation, newNavigation); diff --git a/src/deck-components/index.ts b/src/deck-components/index.ts index 9508ee9..11e45e5 100755 --- a/src/deck-components/index.ts +++ b/src/deck-components/index.ts @@ -26,55 +26,56 @@ export * from './Toggle'; export * from './ToggleField'; export * from './SteamClient'; -import { SteamClient, SteamAppOverview, LogoPosition } from './SteamClient'; +import { AppDetails, LogoPosition, SteamAppOverview, SteamClient } from './SteamClient'; declare global { - var SteamClient: SteamClient; + var SteamClient: SteamClient; - interface Window { - LocalizationManager: { - m_mapTokens: Map; - m_mapFallbackTokens: Map; - m_rgLocalesToUse: string[]; + interface Window { + LocalizationManager: { + m_mapTokens: Map; + m_mapFallbackTokens: Map; + m_rgLocalesToUse: string[]; + }; + App: { + m_CurrentUser: { + bIsLimited: boolean; + bIsOfflineMode: boolean; + bSupportAlertActive: boolean; + bCanInviteFriends: boolean; + NotificationCounts: { + comments: number; + inventory_items: number; + invites: number; + gifts: number; + offline_messages: number; + trade_offers: number; + async_game_updates: number; + moderator_messages: number; + help_request_replies: number; }; - App: { - m_CurrentUser: { - bIsLimited: boolean; - bIsOfflineMode: boolean; - bSupportAlertActive: boolean; - bCanInviteFriends: boolean; - NotificationCounts: { - comments: number; - inventory_items: number; - invites: number; - gifts: number; - offline_messages: number; - trade_offers: number; - async_game_updates: number; - moderator_messages: number; - help_request_replies: number; - }; - strAccountBalance: string; - strAccountName: string; - strSteamID: string; - }; - }; - appStore: { - GetAppOverviewByAppID: (appId: number) => SteamAppOverview | null; - GetCustomVerticalCapsuleURLs: (app: SteamAppOverview) => string[]; - GetCustomLandcapeImageURLs: (app: SteamAppOverview) => string[]; - GetCustomHeroImageURLs: (app: SteamAppOverview) => string[]; - GetCustomLogoImageURLs: (app: SteamAppOverview) => string[]; - GetLandscapeImageURLForApp: (app: SteamAppOverview) => string; - GetVerticalCapsuleURLForApp: (app: SteamAppOverview) => string; - GetCachedLandscapeImageURLForApp: (app: SteamAppOverview) => string; - GetCachedVerticalImageURLForApp: (app: SteamAppOverview) => string; - GetPregeneratedVerticalCapsuleForApp: (app: SteamAppOverview) => string; - GetIconURLForApp: (app: SteamAppOverview) => string; - }; - appDetailsStore: { - GetCustomLogoPosition: (app: SteamAppOverview) => LogoPosition | null; - SaveCustomLogoPosition: (app: SteamAppOverview, logoPositions: LogoPosition) => any; - } - } + strAccountBalance: string; + strAccountName: string; + strSteamID: string; + }; + }; + appStore: { + GetAppOverviewByAppID: (appId: number) => SteamAppOverview | null; + GetCustomVerticalCapsuleURLs: (app: SteamAppOverview) => string[]; + GetCustomLandcapeImageURLs: (app: SteamAppOverview) => string[]; + GetCustomHeroImageURLs: (app: SteamAppOverview) => string[]; + GetCustomLogoImageURLs: (app: SteamAppOverview) => string[]; + GetLandscapeImageURLForApp: (app: SteamAppOverview) => string; + GetVerticalCapsuleURLForApp: (app: SteamAppOverview) => string; + GetCachedLandscapeImageURLForApp: (app: SteamAppOverview) => string; + GetCachedVerticalImageURLForApp: (app: SteamAppOverview) => string; + GetPregeneratedVerticalCapsuleForApp: (app: SteamAppOverview) => string; + GetIconURLForApp: (app: SteamAppOverview) => string; + }; + appDetailsStore: { + GetAppDetails: (appId: number) => AppDetails | null; + GetCustomLogoPosition: (app: SteamAppOverview) => LogoPosition | null; + SaveCustomLogoPosition: (app: SteamAppOverview, logoPositions: LogoPosition) => any; + }; + } } diff --git a/src/utils/index.ts b/src/utils/index.ts index d139e36..fbf0e11 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,11 @@ export * from './patcher'; export * from './react'; +declare global { + var FocusNavController: any; + var GamepadNavTree: any; +} + export function joinClassNames(...classes: string[]): string { return classes.join(' '); } @@ -16,7 +21,15 @@ export function findSP(): Window { // old (SP as host) if (document.title == 'SP') return window; // new (SP as popup) - const context = FocusNavController.m_ActiveContext || FocusNavController.m_LastActiveContext; - return context.m_rgGamepadNavigationTrees.find((x: any) => x.m_ID == 'root_1_').Root - .Element.ownerDocument.defaultView; + const focusNav = getFocusNavController(); + const context = focusNav.m_ActiveContext || focusNav.m_LastActiveContext; + return context.m_rgGamepadNavigationTrees.find((x: any) => x.m_ID == 'root_1_').Root.Element.ownerDocument + .defaultView; +} + +/** + * Gets the correct FocusNavController, as the Feb 22 2023 beta has two for some reason. + */ +export function getFocusNavController(): any { + return window.GamepadNavTree?.m_context?.m_controller || window.FocusNavController; }