From bcf25038a865a842adb483803e1d8b5aa1feae19 Mon Sep 17 00:00:00 2001 From: sw3205933776 <3205933776@qq.com> Date: Fri, 1 Aug 2025 17:04:25 +0800 Subject: [PATCH 1/4] fix: download progress bar not showing during app update --- src/components/ui/progress.tsx | 2 +- src/components/update/index.tsx | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/components/ui/progress.tsx b/src/components/ui/progress.tsx index d4b424341..cda3ab63f 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..95145226c 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); + }, + [] + ) + + // 监听下载进度变化,更新 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: { From 50207d94f9a7f78c9b40b24da83b1b4f162c79a5 Mon Sep 17 00:00:00 2001 From: sw3205933776 <3205933776@qq.com> Date: Fri, 1 Aug 2025 17:15:40 +0800 Subject: [PATCH 2/4] fix: update comment for clarity on download progress handling --- src/components/update/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/update/index.tsx b/src/components/update/index.tsx index 95145226c..e89cff6fb 100644 --- a/src/components/update/index.tsx +++ b/src/components/update/index.tsx @@ -53,8 +53,8 @@ const Update = () => { }, [] ) - - // 监听下载进度变化,更新 toast + + // listen to download progress and update toast useEffect(() => { if (isDownloading) { toast.custom((t) => ( From 8b994db4d2230c4464556ddccfda0646762031ac Mon Sep 17 00:00:00 2001 From: sw3205933776 <3205933776@qq.com> Date: Fri, 1 Aug 2025 17:28:53 +0800 Subject: [PATCH 3/4] style: update progress bar color --- src/components/ui/progress.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/ui/progress.tsx b/src/components/ui/progress.tsx index cda3ab63f..7b17f4c2d 100644 --- a/src/components/ui/progress.tsx +++ b/src/components/ui/progress.tsx @@ -16,7 +16,8 @@ const Progress = React.forwardRef< {...props} > From 3900c44d047c70efbcf1c16a32683efc4c74f9e2 Mon Sep 17 00:00:00 2001 From: sw3205933776 <3205933776@qq.com> Date: Fri, 1 Aug 2025 17:29:10 +0800 Subject: [PATCH 4/4] chore: remove commented-out code --- src/components/ui/progress.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/ui/progress.tsx b/src/components/ui/progress.tsx index 7b17f4c2d..701c0d2ed 100644 --- a/src/components/ui/progress.tsx +++ b/src/components/ui/progress.tsx @@ -17,7 +17,6 @@ const Progress = React.forwardRef< >