提交记录修改ui/scripts/app-update-ui-smoke.mjs+13 −0看文件
修改ui/src/app-updates.jsx+13 −6看文件
| @@ -80,3 +80,16 @@ try { | ||
| 80 | 80 | await fs.writeFile(`${output}/checks.json`, JSON.stringify(result, null, 2)); |
| 81 | 81 | console.log(JSON.stringify(result)); |
| 82 | 82 | } finally { await browser.close(); } |
| 83 | 新增: | |
| 84 | 新增:const recovered = await createWorkbench({ nativeRequest: async body => { | |
| 85 | 新增: if (body.action !== "appUpdate") return null; | |
| 86 | 新增: return body.operation === "status" | |
| 87 | 新增: ? { phase: "failed", message: "新版本工作台未能就绪,已恢复原应用", retryable: true } | |
| 88 | 新增: : { phase: "current", currentVersion: "0.1.3-alpha.1" }; | |
| 89 | 新增:} }); | |
| 90 | 新增:try { | |
| 91 | 新增: await recovered.page.getByRole("alert").filter({ hasText: "已恢复原应用" }).waitFor(); | |
| 92 | 新增: assert.equal(await recovered.page.locator(".app-update-button").count(), 0, "rollback failure stays visible without advertising an unavailable update"); | |
| 93 | 新增: assert.deepEqual(recovered.errors, []); | |
| 94 | 新增: console.log("PASS: persisted update failure remains visible while the startup check completes"); | |
| 95 | 新增:} finally { await recovered.browser.close(); } | |
| @@ -8,6 +8,7 @@ const retryInterval = 5 * 60 * 1000; | ||
| 8 | 8 | |
| 9 | 9 | export function useAppUpdates() { |
| 10 | 10 | const [state, setState] = useState({ phase: "idle", message: "" }); |
| 11 | 新增: const [startupFailure, setStartupFailure] = useState(""); | |
| 11 | 12 | const current = useRef(state); |
| 12 | 13 | current.current = state; |
| 13 | 14 | const requestPending = useRef(false); |
| @@ -46,6 +47,7 @@ export function useAppUpdates() { | ||
| 46 | 47 | try { |
| 47 | 48 | const next = await native("appUpdate", { operation: "status" }); |
| 48 | 49 | if (!live) return; |
| 50 | 新增: if (next?.phase === "failed") setStartupFailure(next.message || "上次应用更新未完成"); | |
| 49 | 51 | if (next?.phase) { current.current = next; setState(next); } |
| 50 | 52 | if (!next || ["idle", "current", "failed"].includes(next.phase)) void run("check"); |
| 51 | 53 | } catch (error) { |
| @@ -62,11 +64,16 @@ export function useAppUpdates() { | ||
| 62 | 64 | document.removeEventListener("visibilitychange", check); |
| 63 | 65 | }; |
| 64 | 66 | }, [available, run]); |
| 65 | 删除: return { state, run, available }; | |
| 67 | 新增: useEffect(() => { | |
| 68 | 新增: if (!startupFailure) return; | |
| 69 | 新增: const timer = setTimeout(() => setStartupFailure(""), 8000); | |
| 70 | 新增: return () => clearTimeout(timer); | |
| 71 | 新增: }, [startupFailure]); | |
| 72 | 新增: return { state, run, available, startupFailure }; | |
| 66 | 73 | } |
| 67 | 74 | |
| 68 | 75 | export function AppUpdateButton({ updates }) { |
| 69 | 删除: const { state, run, available } = updates; | |
| 76 | 新增: const { state, run, available, startupFailure } = updates; | |
| 70 | 77 | const busy = activePhases.has(state.phase); |
| 71 | 78 | const failed = state.phase === "failed"; |
| 72 | 79 | const visible = state.latestVersion && ["available", "ready", "failed", ...activePhases].includes(state.phase); |
| @@ -84,7 +91,7 @@ export function AppUpdateButton({ updates }) { | ||
| 84 | 91 | const timer = setTimeout(() => setFailure(""), 8000); |
| 85 | 92 | return () => clearTimeout(timer); |
| 86 | 93 | }, [failure]); |
| 87 | 删除: if (!available || !visible) return null; | |
| 94 | 新增: if (!available || (!visible && !startupFailure)) return null; | |
| 88 | 95 | const downloading = state.phase === "downloading"; |
| 89 | 96 | const percent = state.totalBytes > 0 |
| 90 | 97 | ? Math.max(0, Math.min(100, Math.floor((state.receivedBytes || 0) / state.totalBytes * 100))) |
| @@ -99,7 +106,7 @@ export function AppUpdateButton({ updates }) { | ||
| 99 | 106 | const circumference = 2 * Math.PI * 15; |
| 100 | 107 | return ( |
| 101 | 108 | <> |
| 102 | 删除: <button | |
| 109 | 新增: {visible && <button | |
| 103 | 110 | className={`app-update-button${busy ? " busy" : ""}${failed ? " failed" : ""}`} |
| 104 | 111 | aria-label={label} |
| 105 | 112 | title={hint} |
| @@ -118,8 +125,8 @@ export function AppUpdateButton({ updates }) { | ||
| 118 | 125 | {downloading && percent !== null && <span className="app-update-percent">{percent}%</span>} |
| 119 | 126 | </> |
| 120 | 127 | ) : failed ? <RefreshCw size={20} /> : <ArrowDownToLine size={22} />} |
| 121 | 删除: </button> | |
| 122 | 删除: {failure && <div className="app-update-error" role="alert">{failure}。可点击更新按钮重试。</div>} | |
| 128 | 新增: </button>} | |
| 129 | 新增: {(failure || startupFailure) && <div className="app-update-error" role="alert">{failure || startupFailure}{visible ? "。可点击更新按钮重试。" : ""}</div>} | |
| 123 | 130 | </> |
| 124 | 131 | ); |
| 125 | 132 | } |

