Rewrite toaster hook to not re-create the window (#217)

This commit is contained in:
AAGaming
2022-10-14 20:09:11 -04:00
committed by GitHub
parent 618abec97a
commit 3ac0abc82b
2 changed files with 14 additions and 25 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ const Toast: FunctionComponent<ToastProps> = ({ toast }) => {
return ( return (
<div <div
style={{ '--toast-duration': `${toast.nToastDurationMS}ms` } as React.CSSProperties} style={{ '--toast-duration': `${toast.nToastDurationMS}ms` } as React.CSSProperties}
className={joinClassNames(toastClasses.ToastPopup, toastClasses.toastEnter)} className={toastClasses.toastEnter}
> >
<div <div
onClick={toast.data.onClick} onClick={toast.data.onClick}
+5 -16
View File
@@ -38,34 +38,23 @@ class Toaster extends Logger {
await sleep(2000); await sleep(2000);
} }
this.node = instance.return.return; this.node = instance.sibling.child;
let toast: any; let toast: any;
let renderedToast: ReactNode = null; let renderedToast: ReactNode = null;
this.node.stateNode.render = (...args: any[]) => { afterPatch(this.node, 'type', (args: any[], ret: any) => {
const ret = this.node.stateNode.__proto__.render.call(this.node.stateNode, ...args); const currentToast = args[0].notification;
if (ret) {
this.instanceRetPatch = afterPatch(ret, 'type', (_: any, ret: any) => {
if (ret?.props?.children[1]?.children?.props) {
const currentToast = ret.props.children[1].children.props.notification;
if (currentToast?.decky) { if (currentToast?.decky) {
if (currentToast == toast) { if (currentToast !== toast) {
ret.props.children[1].children = renderedToast;
} else {
toast = currentToast; toast = currentToast;
renderedToast = <Toast toast={toast} />; renderedToast = <Toast toast={toast} />;
ret.props.children[1].children = renderedToast;
} }
ret.props.children = renderedToast;
} else { } else {
toast = null; toast = null;
renderedToast = null; renderedToast = null;
} }
}
return ret; return ret;
}); });
}
return ret;
};
this.node.stateNode.forceUpdate();
this.settingsModule = findModuleChild((m) => { this.settingsModule = findModuleChild((m) => {
if (typeof m !== 'object') return undefined; if (typeof m !== 'object') return undefined;
for (let prop in m) { for (let prop in m) {