From 5f0470c351dc4ecb24ea3e928ff0b0199c399fa4 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Sun, 23 Oct 2022 20:22:00 -0400 Subject: [PATCH] feat(modal): support for latest steamos preview --- src/deck-components/Modal.tsx | 7 ++++++- src/utils/index.ts | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/deck-components/Modal.tsx b/src/deck-components/Modal.tsx index 12064c0..e82c409 100755 --- a/src/deck-components/Modal.tsx +++ b/src/deck-components/Modal.tsx @@ -1,4 +1,5 @@ import { FC, ReactNode } from 'react'; +import { findSP } from '../utils'; import { findModuleChild } from '../webpack'; // All of the popout options + strTitle are related. Proper usage is not yet known... @@ -27,7 +28,7 @@ export interface ShowModalResult { Update: (modal: ReactNode) => void; } -export const showModal: (modal: ReactNode, parent?: EventTarget, props?: ShowModalProps) => Promise = findModuleChild((m) => { +const showModalRaw: (modal: ReactNode, parent?: EventTarget, props?: ShowModalProps) => Promise = findModuleChild((m) => { if (typeof m !== 'object') return undefined; for (let prop in m) { if (typeof m[prop] === 'function' && m[prop].toString().includes('bHideMainWindowForPopouts:!0')) { @@ -36,6 +37,10 @@ export const showModal: (modal: ReactNode, parent?: EventTarget, props?: ShowMod } }); +export const showModal = (modal: ReactNode, parent?: EventTarget, props?: ShowModalProps): Promise => { + return showModalRaw(modal, parent || findSP(), props) +} + export interface ModalRootProps { children?: ReactNode; onCancel?(): void; diff --git a/src/utils/index.ts b/src/utils/index.ts index 3d891c4..7727975 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -7,4 +7,16 @@ export function joinClassNames(...classes: string[]): string { export function sleep(ms: number) { return new Promise(res => setTimeout(res, ms)); -} \ No newline at end of file +} + +/** + * Finds the SP window, since it is a render target as of {10-19-2022}'s beta + */ +export function findSP(): Window { + // old (SP as host) + if (document.title == 'SP') return window; + // new (SP as popup) + return FocusNavController.m_ActiveContext.m_rgGamepadNavigationTrees.find((x: any) => x.m_ID == 'root_1_').Root + .Element.ownerDocument.defaultView; + } + \ No newline at end of file