From c24a04cdb23f78078c71c7654d3c6e74c336330e Mon Sep 17 00:00:00 2001 From: jim800121chen Date: Sun, 12 Apr 2026 20:21:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(local-tool):=20Review=20minor=20m1/m2/m4=20?= =?UTF-8?q?=E4=BF=AE=E5=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit m1(i18n 混用不一致): - flash-dialog.tsx 所有英文字串改繁中(載入模型 / 選擇模型 / 硬體不相容 / 開始載入 / 關閉 / 完成) - flash-progress.tsx 同理(模型載入失敗 / 重試 / 正在準備載入 / 模型載入完成) m2(Dialog 關閉防護不完整): - 改用 isInProgress 判斷(isFlashing || progress 未到 100%)+ 沒 error 而非只看 isFlashing,涵蓋「API 回應了但 WS 進度還在跑」的情況 m4(WS 3 秒 timeout 應 reject): - connectAndWait timeout 改 reject + Error message - flash-dialog handleFlash 加 try/catch 捕捉 WS 連線失敗 → 呼叫 setError 讓 UI 顯示錯誤而非靜默卡住 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/components/devices/flash-dialog.tsx | 35 ++++++++++++------- .../src/components/devices/flash-progress.tsx | 8 ++--- .../frontend/src/hooks/use-flash-progress.ts | 17 +++++---- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/local-tool/frontend/src/components/devices/flash-dialog.tsx b/local-tool/frontend/src/components/devices/flash-dialog.tsx index 0a57a12..39e6834 100644 --- a/local-tool/frontend/src/components/devices/flash-dialog.tsx +++ b/local-tool/frontend/src/components/devices/flash-dialog.tsx @@ -39,6 +39,7 @@ export function FlashDialog({ deviceId }: FlashDialogProps) { const device = devices.find((d) => d.id === deviceId); const selectedModel = models.find((m) => m.id === selectedModelId); + // S2: 資料載入前預設 compatible=true,避免在 model/device 還沒載入時就顯示不相容警告 const compatible = useMemo(() => { if (!selectedModel || !device) return true; return isModelCompatible(selectedModel.supportedHardware, device.type); @@ -56,30 +57,38 @@ export function FlashDialog({ deviceId }: FlashDialogProps) { const handleFlash = async () => { if (!selectedModelId) return; - // 1. Create WebSocket and wait for it to open - await connectAndWait(); - // 2. Then start flash (POST) — now WS is listening + try { + await connectAndWait(); + } catch (e) { + const msg = e instanceof Error ? e.message : String(e); + reset(); + useFlashStore.getState().setError(msg); + return; + } await startFlash(deviceId, selectedModelId); }; + // m2 fix: 進度尚未完成時(不管 isFlashing 狀態如何)都阻止關閉 + const isInProgress = (isFlashing || (progress !== null && progress.percent < 100)) && !error; + return ( { - if (!v && isFlashing && !error) return; + if (!v && isInProgress) return; setOpen(v); }}> - + - Flash Model to Device + 載入模型到裝置
{!isFlashing && !progress && !error ? ( <>