From 7dacb23e8be7b1f076cdd0869a4e3a3902b07ec5 Mon Sep 17 00:00:00 2001 From: FrogTheFrog Date: Sun, 19 Mar 2023 22:22:39 +0200 Subject: [PATCH] fix(useQuickAccessVisible): make it work again --- src/custom-hooks/useQuickAccessVisible.tsx | 14 +++----------- src/utils/index.ts | 15 +++++++++++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/custom-hooks/useQuickAccessVisible.tsx b/src/custom-hooks/useQuickAccessVisible.tsx index e6569dc..5a875d3 100644 --- a/src/custom-hooks/useQuickAccessVisible.tsx +++ b/src/custom-hooks/useQuickAccessVisible.tsx @@ -1,17 +1,9 @@ import { useEffect, useState } from 'react'; - -import { getFocusNavController } from '../utils'; +import { getGamepadNavigationTrees } from '../utils'; function getQuickAccessWindow(): Window | null { - try { - 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; - } + const navTrees = getGamepadNavigationTrees(); + return navTrees.find((tree: any) => tree?.id === 'QuickAccess-NA')?.m_Root?.m_element?.ownerDocument.defaultView ?? null; } /** diff --git a/src/utils/index.ts b/src/utils/index.ts index fbf0e11..e87b167 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -21,10 +21,8 @@ export function findSP(): Window { // old (SP as host) if (document.title == 'SP') return window; // new (SP as popup) - 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; + const navTrees = getGamepadNavigationTrees(); + return navTrees.find((x: any) => x.m_ID == 'root_1_').Root.Element.ownerDocument.defaultView; } /** @@ -33,3 +31,12 @@ export function findSP(): Window { export function getFocusNavController(): any { return window.GamepadNavTree?.m_context?.m_controller || window.FocusNavController; } + +/** + * Gets the gamepad navigation trees as Valve seems to be moving them. + */ +export function getGamepadNavigationTrees(): any { + const focusNav = getFocusNavController(); + const context = focusNav.m_ActiveContext || focusNav.m_LastActiveContext; + return context.m_rgGamepadNavigationTrees; +}