diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f4fcfb..fbf64ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ +## [3.19.2](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v3.19.1...v3.19.2) (2023-03-07) + + +### Bug Fixes + +* **Item:** add highlightOnFocus prop ([c53f87b](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/c53f87b4a9273b377853bfff1d27474ebd6e564a)) + +## [3.19.1](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v3.19.0...v3.19.1) (2023-02-23) + + +### Bug Fixes + +* refactoring to fix for feb 22 2023 beta ([0b6dc24](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/0b6dc24c0da2d7644e185425e975787657f8bba1)) + +# [3.19.0](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v3.18.11...v3.19.0) (2023-02-22) + + +### Features + +* added reorderable list and updated fieldProps ([#57](https://github.com/SteamDeckHomebrew/decky-frontend-lib/issues/57)) ([5a074b5](https://github.com/SteamDeckHomebrew/decky-frontend-lib/commit/5a074b5bb68c675c484a7b693f67a67488be9bcf)) + ## [3.18.11](https://github.com/SteamDeckHomebrew/decky-frontend-lib/compare/v3.18.10...v3.18.11) (2023-02-18) diff --git a/package.json b/package.json index 613868c..632ad55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "decky-frontend-lib", - "version": "3.18.11", + "version": "3.19.2", "description": "A library for building decky plugins", "main": "dist/index.js", "types": "dist/index.d.ts", 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/Item.tsx b/src/deck-components/Item.tsx index a101d80..2861edc 100644 --- a/src/deck-components/Item.tsx +++ b/src/deck-components/Item.tsx @@ -8,4 +8,5 @@ export interface ItemProps { bottomSeparator?: 'standard' | 'thick' | 'none'; indentLevel?: number; tooltip?: string; + highlightOnFocus?: boolean; } 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/SidebarNavigation.tsx b/src/deck-components/SidebarNavigation.tsx index 8afe94b..10ad495 100644 --- a/src/deck-components/SidebarNavigation.tsx +++ b/src/deck-components/SidebarNavigation.tsx @@ -16,7 +16,7 @@ export interface SidebarNavigationPage { export interface SidebarNavigationProps { title?: string; - pages: SidebarNavigationPage[]; + pages: (SidebarNavigationPage | 'separator')[]; showTitle?: boolean; disableRouteReporting?: boolean; page?: string; 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; }