Skip to content

Commit

Permalink
fix(useQuickAccessVisible): make it work again
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogTheFrog committed Mar 19, 2023
1 parent 7e5c7b5 commit 7dacb23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
14 changes: 3 additions & 11 deletions src/custom-hooks/useQuickAccessVisible.tsx
Original file line number Diff line number Diff line change
@@ -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;
}

/**
Expand Down
15 changes: 11 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

0 comments on commit 7dacb23

Please sign in to comment.