Skip to content

Commit

Permalink
fix(modal): update showModal types (SteamDeckHomebrew#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogTheFrog authored Sep 24, 2022
1 parent ad64383 commit 6996e54
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/deck-components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
import { FC, ReactNode } from 'react';

import { findModuleChild } from '../webpack';

// TODO: there is another argument, figure out what it does
export const showModal: (children: ReactNode, parent?: EventTarget) => void = findModuleChild((m) => {
// All of the popout options + strTitle are related. Proper usage is not yet known...
export interface ShowModalProps {
browserContext?: unknown; // This is another Deck Object that is yet to be found
bForcePopOut?: boolean;
bHideActionIcons?: boolean;
bHideMainWindowForPopouts?: boolean;
bNeverPopOut?: boolean;
fnOnClose?: () => void; // Seems to be the same as "closeModal" callback, but only when the modal is a popout. Will no longer work after "Update" invocation!
popupHeight?: number;
popupWidth?: number;
promiseRenderComplete?: Promise<void>; // Invoked once the render is complete. Currently, it seems to be used as image loading success/error callback...
strTitle?: string;
}

export interface ShowModalResult {
// This method will not invoke any of the variations of "closeModal" callbacks!
Close: () => void;

// This method will replace the modal element completely and will not update the callback chains,
// meaning that "closeModal" and etc. will not automatically close the modal anymore (also "fnOnClose"
// will not be even called upon close anymore)! You have to manually call the "Close" method when, for example,
// the "closeModal" is invoked in the newly updated modal:
// <ModalRoot closeModal={() => { console.log("ABOUT TO CLOSE"); showModalRes.Close(); }} />
Update: (modal: ReactNode) => void;
}

export const showModal: (modal: ReactNode, parent?: EventTarget, props?: ShowModalProps) => Promise<ShowModalResult> = findModuleChild((m) => {
if (typeof m !== 'object') return undefined;
for (let prop in m) {
if (typeof m[prop] === 'function' && m[prop].toString().includes('bHideMainWindowForPopouts:!0')) {
Expand Down Expand Up @@ -46,4 +70,4 @@ export const ModalRoot = findModuleChild((m) => {
return m[prop];
}
}
}) as FC<ModalRootProps>;
}) as FC<ModalRootProps>;

0 comments on commit 6996e54

Please sign in to comment.