diff --git a/src/components/ui/progress.tsx b/src/components/ui/progress.tsx index d4b424341..701c0d2ed 100644 --- a/src/components/ui/progress.tsx +++ b/src/components/ui/progress.tsx @@ -16,7 +16,7 @@ const Progress = React.forwardRef< {...props} > diff --git a/src/components/update/index.tsx b/src/components/update/index.tsx index 7c613d5a3..e89cff6fb 100644 --- a/src/components/update/index.tsx +++ b/src/components/update/index.tsx @@ -1,9 +1,11 @@ import type { ProgressInfo } from "electron-updater"; -import { useCallback, useEffect } from "react"; +import { useCallback, useEffect, useState } from "react"; import { toast } from "sonner"; import {Progress} from "@/components/ui/progress"; const Update = () => { + const [downloadProgress, setDownloadProgress] = useState(0); + const [isDownloading, setIsDownloading] = useState(false); const checkUpdate = async () => { const result = await window.ipcRenderer.invoke("check-update"); @@ -23,6 +25,8 @@ const Update = () => { action: { label: "download", onClick: () => { + setIsDownloading(true); + setDownloadProgress(0); window.ipcRenderer.invoke("start-download"); }, }, @@ -44,22 +48,34 @@ const Update = () => { const onDownloadProgress = useCallback( (_event: Electron.IpcRendererEvent, progress: ProgressInfo) => { + console.log('Download progress received:', progress); + setDownloadProgress(progress.percent ?? 0); + }, + [] + ) + + // listen to download progress and update toast + useEffect(() => { + if (isDownloading) { toast.custom((t) => ( -
-
downloading...
- +
+
Downloading update...
+ +
+ {Math.round(downloadProgress)}% complete +
), { id: "download-progress", duration: Infinity, }); - }, - [] - ) + } + }, [downloadProgress, isDownloading]); const onUpdateDownloaded = useCallback( (_event: Electron.IpcRendererEvent) => { toast.dismiss("download-progress"); + setIsDownloading(false); toast.success("download completed", { description: "click to install update", action: {