From 405ac69fa7b029f043470d17f523884e66a945c9 Mon Sep 17 00:00:00 2001 From: langiam Date: Wed, 26 Nov 2025 15:14:26 -0500 Subject: [PATCH 1/2] new build to fix unresponsive UI and hard crashing with PIP --- src/pip.tsx | 90 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 25 deletions(-) diff --git a/src/pip.tsx b/src/pip.tsx index 1209a52..e1af293 100644 --- a/src/pip.tsx +++ b/src/pip.tsx @@ -24,16 +24,37 @@ const Browser = ({ url, visible, x, y, width, height }: BrowserProps) => { useUIComposition(UIComposition.Notification); const [{ browser, view }] = useState<{ browser: any, view: any }>(() => { - const root: WindowRouter & any = Router.WindowStore?.GamepadUIMainWindowInstance; + const root: (WindowRouter & any) | undefined = + Router.WindowStore?.GamepadUIMainWindowInstance; + + if (!root || typeof root.CreateBrowserView !== "function") { + const noOp = () => {}; + const fakeView = { + LoadURL: noOp, + Destroy: noOp, + GetBrowser: () => ({ + SetVisible: noOp, + SetBounds: noOp, + }), + } as any; + + console.error("[decky-pip] GamepadUIMainWindowInstance/CreateBrowserView not available"); + + return { + view: fakeView, + browser: fakeView.GetBrowser(), + }; + } + const view = root.CreateBrowserView("pip"); const browser = view.GetBrowser(); - window['pip' as any] = view; + (window as any).pip = view; return { view, - browser - } + browser, + }; }); useEffect(() => { @@ -65,38 +86,54 @@ const getBounds = (document: any) => { } const getDeckComponentBounds = () => { - const trees = getGamepadNavigationTrees(); - - const nav = trees.find((tree: any) => tree?.id === 'MainNavMenuContainer')?.m_Root?.m_element?.ownerDocument.defaultView ?? null - const navHidden = nav?.document.hidden; - const navBounds = navHidden - ? null - : getBounds(nav?.document); - - const qam = trees.find((tree: any) => tree?.id === 'QuickAccess-NA')?.m_Root?.m_element?.ownerDocument.defaultView ?? null - const qamHidden = qam?.document.hidden; - const qamBounds = qamHidden - ? null - : getBounds(qam?.document); + const trees = (typeof getGamepadNavigationTrees === "function" + ? getGamepadNavigationTrees() + : []) as any[]; + + const findWindow = (match: (id: string) => boolean) => { + const tree = trees.find( + (t: any) => typeof t?.id === "string" && match(t.id) + ); + return tree?.m_Root?.m_element?.ownerDocument?.defaultView ?? null; + }; - const virtualKeyboard = trees.find((tree: any) => tree?.id === 'virtual keyboard')?.m_Root?.m_element?.ownerDocument.defaultView ?? null - const virtualKeyboardHidden = !virtualKeyboard; - // this is a guess, gotta figure out how to inspect to keyboard DOM + // Try to be flexible: support old exact IDs and any future variants + const navWindow = findWindow( + id => id === "MainNavMenuContainer" || id.includes("MainNav") + ); + const qamWindow = findWindow( + id => id === "QuickAccess-NA" || id.includes("QuickAccess") + ); + const virtualKeyboardWindow = findWindow( + id => id.toLowerCase().includes("keyboard") + ); + + // NAV + const navHidden = navWindow?.document.hidden; + const navBounds = navHidden ? null : getBounds(navWindow?.document); + + // QAM + const qamHidden = qamWindow?.document.hidden; + const qamBounds = qamHidden ? null : getBounds(qamWindow?.document); + + // VIRTUAL KEYBOARD (still a guess, based on its screen area) + const virtualKeyboardHidden = !virtualKeyboardWindow; const virtualKeyboardBounds = virtualKeyboardHidden ? null : { x: 0, y: SCREEN_HEIGHT - 240, width: SCREEN_WIDTH, - height: 240 + height: 240, }; return { nav: navBounds, qam: qamBounds, virtualKeyboard: virtualKeyboardBounds, - } -} + }; +}; + const useDeckComponentBounds = () => { const [state, setState] = useState(getDeckComponentBounds()); @@ -109,7 +146,7 @@ const useDeckComponentBounds = () => { ? current : next; }); - }, 250); + }, 500); return () => clearInterval(interval); }, []); @@ -121,6 +158,9 @@ export const Pip = () => { const { nav, qam, virtualKeyboard } = useDeckComponentBounds(); const [{ viewMode, position, size, url, visible, ...settings }] = useGlobalState(); + const overlayOpen = !!nav || !!qam || !!virtualKeyboard; + const effectiveVisible = visible && !overlayOpen; + const pictureWidth = PICTURE_WIDTH * size; const pictureHeight = PICTURE_HEIGHT * size; @@ -217,7 +257,7 @@ export const Pip = () => { return ; } From d1a10d19ec7029cac2d4852d649118f7c6a4d5b1 Mon Sep 17 00:00:00 2001 From: langiam Date: Wed, 26 Nov 2025 17:29:44 -0500 Subject: [PATCH 2/2] created dist --- src/pip.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pip.tsx b/src/pip.tsx index e1af293..f1c42d2 100644 --- a/src/pip.tsx +++ b/src/pip.tsx @@ -97,7 +97,7 @@ const getDeckComponentBounds = () => { return tree?.m_Root?.m_element?.ownerDocument?.defaultView ?? null; }; - // Try to be flexible: support old exact IDs and any future variants + const navWindow = findWindow( id => id === "MainNavMenuContainer" || id.includes("MainNav") ); @@ -108,11 +108,9 @@ const getDeckComponentBounds = () => { id => id.toLowerCase().includes("keyboard") ); - // NAV const navHidden = navWindow?.document.hidden; const navBounds = navHidden ? null : getBounds(navWindow?.document); - // QAM const qamHidden = qamWindow?.document.hidden; const qamBounds = qamHidden ? null : getBounds(qamWindow?.document); @@ -134,7 +132,6 @@ const getDeckComponentBounds = () => { }; }; - const useDeckComponentBounds = () => { const [state, setState] = useState(getDeckComponentBounds());