Browse Source

feat(desktop): in-app update toasts

Adam 10 months ago
parent
commit
1c25f1fae0
1 changed files with 13 additions and 5 deletions
  1. 13 5
      packages/app/src/pages/layout.tsx

+ 13 - 5
packages/app/src/pages/layout.tsx

@@ -134,11 +134,15 @@ export default function Layout(props: ParentProps) {
     })
     })
   }
   }
 
 
-  onMount(async () => {
-    if (platform.checkUpdate && platform.update && platform.restart) {
-      const { updateAvailable, version } = await platform.checkUpdate()
-      if (updateAvailable) {
-        showToast({
+  onMount(() => {
+    if (!platform.checkUpdate || !platform.update || !platform.restart) return
+
+    let toastId: number | undefined
+
+    async function pollUpdate() {
+      const { updateAvailable, version } = await platform.checkUpdate!()
+      if (updateAvailable && toastId === undefined) {
+        toastId = showToast({
           persistent: true,
           persistent: true,
           icon: "download",
           icon: "download",
           title: "Update available",
           title: "Update available",
@@ -159,6 +163,10 @@ export default function Layout(props: ParentProps) {
         })
         })
       }
       }
     }
     }
+
+    pollUpdate()
+    const interval = setInterval(pollUpdate, 10 * 60 * 1000)
+    onCleanup(() => clearInterval(interval))
   })
   })
 
 
   onMount(() => {
   onMount(() => {