From 3aa07dc9ce798ff8d1148424ee9e8a8bf2ba78c6 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Mon, 16 Sep 2024 19:29:38 -0400 Subject: [PATCH] fix(utils): fix potential race condition in findSP --- .github/workflows/release.yaml | 2 +- src/utils/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 038bc2a..d228f0e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -4,7 +4,7 @@ on: pull_request: push: branches: - - v4-dev + - main jobs: release: diff --git a/src/utils/index.ts b/src/utils/index.ts index 4f23c5a..6e28665 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -25,7 +25,7 @@ export function findSP(): Window { if (document.title == 'SP') return window; // new (SP as popup) const navTrees = getGamepadNavigationTrees(); - return navTrees?.find((x: any) => x.m_ID == 'root_1_').Root.Element.ownerDocument.defaultView; + return navTrees?.find((x: any) => x.m_ID == 'root_1_')?.Root?.Element?.ownerDocument?.defaultView; } /** @@ -40,6 +40,6 @@ export function getFocusNavController(): any { */ export function getGamepadNavigationTrees(): any { const focusNav = getFocusNavController(); - const context = focusNav.m_ActiveContext || focusNav.m_LastActiveContext; + const context = focusNav?.m_ActiveContext || focusNav?.m_LastActiveContext; return context?.m_rgGamepadNavigationTrees; }