From 591c58330c75770bf829aaa9ea96dd6125b73ab7 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Mon, 5 Sep 2022 14:28:52 -0400 Subject: fix(toaster): fix toasts rendering multiple times --- frontend/src/toaster.tsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/frontend/src/toaster.tsx b/frontend/src/toaster.tsx index b0c8671a..3a922bfc 100644 --- a/frontend/src/toaster.tsx +++ b/frontend/src/toaster.tsx @@ -1,4 +1,5 @@ import { Patch, ToastData, afterPatch, findInReactTree, findModuleChild, sleep } from 'decky-frontend-lib'; +import { ReactNode } from 'react'; import Toast from './components/Toast'; import Logger from './logger'; @@ -43,13 +44,26 @@ class Toaster extends Logger { } this.node = instance.return.return; + let toast: any; + let renderedToast: ReactNode = null; this.node.stateNode.render = (...args: any[]) => { const ret = this.node.stateNode.__proto__.render.call(this.node.stateNode, ...args); if (ret) { this.instanceRetPatch = afterPatch(ret, 'type', (_: any, ret: any) => { - if (ret?.props?.children[1]?.children?.props?.notification?.decky) { - const toast = ret.props.children[1].children.props.notification; - ret.props.children[1].children.type = () => ; + if (ret?.props?.children[1]?.children?.props) { + const currentToast = ret.props.children[1].children.props.notification; + if (currentToast?.decky) { + if (currentToast == toast) { + ret.props.children[1].children = renderedToast; + } else { + toast = currentToast; + renderedToast = ; + ret.props.children[1].children = renderedToast; + } + } else { + toast = null; + renderedToast = null; + } } return ret; }); -- cgit v1.2.3