From 65b6883dcc42944607eb0efa1f28e41f57335313 Mon Sep 17 00:00:00 2001
From: AAGaming <aagaming@riseup.net>
Date: Wed, 7 Aug 2024 16:14:18 -0400
Subject: handle crashloops and disable decky for the user

---
 frontend/src/toaster.tsx | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

(limited to 'frontend/src/toaster.tsx')

diff --git a/frontend/src/toaster.tsx b/frontend/src/toaster.tsx
index e45b14a4..4f67c589 100644
--- a/frontend/src/toaster.tsx
+++ b/frontend/src/toaster.tsx
@@ -1,5 +1,13 @@
 import type { ToastData, ToastNotification } from '@decky/api';
-import { Patch, callOriginal, findModuleExport, injectFCTrampoline, replacePatch } from '@decky/ui';
+import {
+  ErrorBoundary,
+  Patch,
+  callOriginal,
+  findModuleExport,
+  injectFCTrampoline,
+  replacePatch,
+  sleep,
+} from '@decky/ui';
 
 import Toast from './components/Toast';
 import Logger from './logger';
@@ -21,6 +29,8 @@ declare global {
 
 class Toaster extends Logger {
   private toastPatch?: Patch;
+  private markReady!: () => void;
+  private ready = new Promise<void>((r) => (this.markReady = r));
 
   constructor() {
     super('Toaster');
@@ -34,13 +44,16 @@ class Toaster extends Logger {
     this.toastPatch = replacePatch(patchedRenderer, 'component', (args: any[]) => {
       if (args?.[0]?.group?.decky || args?.[0]?.group?.notifications?.[0]?.decky) {
         return args[0].group.notifications.map((notification: any) => (
-          <Toast toast={notification.data} newIndicator={notification.bNewIndicator} location={args?.[0]?.location} />
+          <ErrorBoundary>
+            <Toast toast={notification.data} newIndicator={notification.bNewIndicator} location={args?.[0]?.location} />
+          </ErrorBoundary>
         ));
       }
       return callOriginal;
     });
 
     this.log('Initialized');
+    sleep(4000).then(this.markReady);
   }
 
   toast(toast: ToastData): ToastNotification {
@@ -107,7 +120,7 @@ class Toaster extends Logger {
         }
       }, toast.expiration);
     }
-    window.NotificationStore.ProcessNotification(info, toastData, ToastType.New);
+    this.ready.then(() => window.NotificationStore.ProcessNotification(info, toastData, ToastType.New));
     return toastResult;
   }
 
-- 
cgit v1.2.3

