From f2fbd399fe875e5aaaaea678d1fb1a824a74932e Mon Sep 17 00:00:00 2001
From: AAGaming <aa@mail.catvibers.me>
Date: Fri, 15 Jul 2022 12:16:57 -0400
Subject: allow users to manually check for updates

---
 .../components/settings/pages/general/Updater.tsx  | 46 ++++++++++++++--------
 1 file changed, 29 insertions(+), 17 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 2772bb2c..e7277631 100644
--- a/frontend/src/components/settings/pages/general/Updater.tsx
+++ b/frontend/src/components/settings/pages/general/Updater.tsx
@@ -24,6 +24,7 @@ export default function UpdaterSettings() {
   const [versionInfo, setVersionInfo] = useState<VerInfo | null>(null);
   const [updateProgress, setUpdateProgress] = useState<number>(-1);
   const [reloading, setReloading] = useState<boolean>(false);
+  const [checkingForUpdates, setCheckingForUpdates] = useState<boolean>(false);
   useEffect(() => {
     (async () => {
       const res = (await callUpdaterMethod('get_version')) as { result: VerInfo };
@@ -51,25 +52,36 @@ export default function UpdaterSettings() {
     >
       {updateProgress == -1 ? (
         <DialogButton
-          disabled={
-            !versionInfo?.updatable || !versionInfo?.remote || versionInfo.remote.tag_name == versionInfo.current
+          disabled={!versionInfo?.updatable || !versionInfo?.remote || checkingForUpdates}
+          onClick={
+            versionInfo?.remote?.tag_name == versionInfo?.current
+              ? async () => {
+                  setCheckingForUpdates(true);
+                  const res = (await callUpdaterMethod('check_for_updates')) as { result: VerInfo };
+                  setVersionInfo(res.result);
+                  setCheckingForUpdates(false);
+                }
+              : async () => {
+                  window.DeckyUpdater = {
+                    updateProgress: (i) => {
+                      setUpdateProgress(i);
+                    },
+                    finish: async () => {
+                      setUpdateProgress(0);
+                      setReloading(true);
+                      await finishUpdate();
+                    },
+                  };
+                  setUpdateProgress(0);
+                  callUpdaterMethod('do_update');
+                }
           }
-          onClick={async () => {
-            window.DeckyUpdater = {
-              updateProgress: (i) => {
-                setUpdateProgress(i);
-              },
-              finish: async () => {
-                setUpdateProgress(0);
-                setReloading(true);
-                await finishUpdate();
-              },
-            };
-            setUpdateProgress(0);
-            callUpdaterMethod('do_update');
-          }}
         >
-          Update
+          {checkingForUpdates
+            ? 'Checking'
+            : versionInfo?.remote?.tag_name == versionInfo?.current
+            ? 'Check For Updates'
+            : 'Install Update'}
         </DialogButton>
       ) : (
         <ProgressBarWithInfo
-- 
cgit v1.2.3

