From 867ce63f7bc67cb418d96d226a7e3eaf2b05bc87 Mon Sep 17 00:00:00 2001
From: Party Wumpus <48649272+PartyWumpus@users.noreply.github.com>
Date: Thu, 15 Feb 2024 22:28:36 +0000
Subject: Add event handler

---
 .../components/settings/pages/general/Updater.tsx  | 24 +++++++++++++---------
 1 file changed, 14 insertions(+), 10 deletions(-)

(limited to 'frontend/src/components/settings/pages/general/Updater.tsx')

diff --git a/frontend/src/components/settings/pages/general/Updater.tsx b/frontend/src/components/settings/pages/general/Updater.tsx
index 26537b58..645252fe 100644
--- a/frontend/src/components/settings/pages/general/Updater.tsx
+++ b/frontend/src/components/settings/pages/general/Updater.tsx
@@ -77,16 +77,20 @@ export default function UpdaterSettings() {
   const { t } = useTranslation();
 
   useEffect(() => {
-    window.DeckyUpdater = {
-      updateProgress: (i) => {
-        setUpdateProgress(i);
-        setIsLoaderUpdating(true);
-      },
-      finish: async () => {
-        setUpdateProgress(0);
-        setReloading(true);
-        await doRestart();
-      },
+    const a = DeckyBackend.addEventListener('frontend/update_download_percentage', (percentage) => {
+      setUpdateProgress(percentage);
+      setIsLoaderUpdating(true);
+    });
+
+    const b = DeckyBackend.addEventListener('frontend/finish_download', async () => {
+      setUpdateProgress(0);
+      setReloading(true);
+      await doRestart();
+    });
+
+    return () => {
+      DeckyBackend.removeEventListener('frontend/update_download_percentage', a);
+      DeckyBackend.removeEventListener('frontend/finish_download', b);
     };
   }, []);
 
-- 
cgit v1.2.3

