From 9d06e8db05992cf2dc3ce810f81175b02b7f370a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E5=B7=9D=E7=99=BD=E6=B5=AA?= <1679659@qq.com> Date: Fri, 4 Dec 2026 07:16:57 -0700 Subject: [PATCH] fix(ui): mark older active runtime as not latest (#151) --- changes/runtime-latest-indicator.json | 7 ++++ frontend/scripts/test-runtime-status.mjs | 48 +++++++++++++++++++++++ frontend/src/components/HostView.tsx | 10 ++++- frontend/src/components/RuntimeOnline.tsx | 27 ++++++++----- frontend/src/i18n/domains/wizard.gen.ts | 6 +++ frontend/src/i18n/keys.gen.ts | 3 ++ frontend/src/lib/runtimeStatus.ts | 26 ++++++++++++ locales/en-US/wizard.json | 3 ++ locales/zh-CN/wizard.json | 3 ++ 9 files changed, 122 insertions(+), 11 deletions(-) create mode 100644 changes/runtime-latest-indicator.json create mode 100644 frontend/scripts/test-runtime-status.mjs create mode 100644 frontend/src/lib/runtimeStatus.ts diff --git a/changes/runtime-latest-indicator.json b/changes/runtime-latest-indicator.json new file mode 100644 index 0000000..5b33261 --- /dev/null +++ b/changes/runtime-latest-indicator.json @@ -0,0 +1,7 @@ +{ + "group": "fixes", + "order": 0, + "authors": ["Nwflower"], + "zh": "手动切换到旧版运行时后,在内核页将当前运行时标注为不是最新并提示切换,同时将最新标签标注在实际最新版本旁 (#151)。", + "en": "Mark the active runtime as not latest with a switch hint when an older runtime is selected on the Engine page, and place the Latest badge on the actual newest installed runtime (#151)." +} diff --git a/frontend/scripts/test-runtime-status.mjs b/frontend/scripts/test-runtime-status.mjs new file mode 100644 index 0000000..22eaa11 --- /dev/null +++ b/frontend/scripts/test-runtime-status.mjs @@ -0,0 +1,48 @@ +import assert from 'node:assert/strict' +import test from 'node:test' +import { loadTestModule } from './load-test-module.mjs' + +const { describeRuntimeStatus, sameRuntimeId } = await loadTestModule(`export * from './lib/runtimeStatus'`) + +const rt = (commit, active = false) => ({ + commit, + active, + path: `/runtimes/${commit}`, + manifest: { qemu_version: 'QEMU 11.1.90' }, +}) + +const remote = (commit) => ({ + commit, + channel: 'stable', + archive_size: 100, +}) + +test('sameRuntimeId matches full and short commits with matching revision suffix', () => { + assert.equal(sameRuntimeId('6a1f03f', '6a1f03f862b4'), true) + assert.equal(sameRuntimeId('3731afd-p3', '3731afd-p4'), false) + assert.equal(sameRuntimeId('3731afd-p3', '3731afd9-p3'), true) +}) + +test('active runtime matching remote latest is up to date', () => { + const s = describeRuntimeStatus([rt('6a1f03f', true), rt('2df30ff', false)], remote('6a1f03f')) + assert.equal(s.activeIsLatest, true) + assert.equal(s.latestInstalled, true) + assert.equal(s.updatable, false) + assert.equal(s.switchRecommended, false) +}) + +test('switching to an older runtime while latest is installed flags not-latest instead of up-to-date', () => { + const s = describeRuntimeStatus([rt('2df30ff', true), rt('6a1f03f', false)], remote('6a1f03f')) + assert.equal(s.activeIsLatest, false) + assert.equal(s.latestInstalled, true) + assert.equal(s.updatable, false) + assert.equal(s.switchRecommended, true) +}) + +test('missing remote latest marks runtime as updatable', () => { + const s = describeRuntimeStatus([rt('2df30ff', true)], remote('6a1f03f')) + assert.equal(s.activeIsLatest, false) + assert.equal(s.latestInstalled, false) + assert.equal(s.updatable, true) + assert.equal(s.switchRecommended, false) +}) diff --git a/frontend/src/components/HostView.tsx b/frontend/src/components/HostView.tsx index 2725b2e..634621f 100644 --- a/frontend/src/components/HostView.tsx +++ b/frontend/src/components/HostView.tsx @@ -9,6 +9,7 @@ import { AppState, Locale, StorageBreakdown, Task } from '../types' import { Button, IconButton } from '../ui/controls' import { Switch } from '../ui/settings' import { api } from '../wails' +import { sameRuntimeId } from '../lib/runtimeStatus' import { RuntimeOnline } from './RuntimeOnline' interface Props { @@ -30,6 +31,7 @@ export const HostView: React.FC = ({ state, locale, onRefresh, onNewVM, o const [enabling, setEnabling] = useState(false) const [savingASLR, setSavingASLR] = useState(false) const [confirmDelete, setConfirmDelete] = useState('') + const [latestRuntimeCommit, setLatestRuntimeCommit] = useState('') const [removing, setRemoving] = useState('') const [storage, setStorage] = useState(null) const { host, config, runtimes } = state @@ -215,6 +217,7 @@ export const HostView: React.FC = ({ state, locale, onRefresh, onNewVM, o onChannel={onChannel} onInstall={onInstallRuntime} onCancel={onCancelTask} + onLatestCommit={setLatestRuntimeCommit} />
@@ -228,7 +231,12 @@ export const HostView: React.FC = ({ state, locale, onRefresh, onNewVM, o {(runtimes ?? []).filter((rt) => !rt.active).map((rt) => (
-
{rt.commit}
+
+ {rt.commit} + {latestRuntimeCommit && sameRuntimeId(rt.commit, latestRuntimeCommit) && ( + {tr('runtimeLatestBadge')} + )} +
{rt.manifest.qemu_version.replace(/^QEMU emulator version\s*/i, 'QEMU ')}
diff --git a/frontend/src/components/RuntimeOnline.tsx b/frontend/src/components/RuntimeOnline.tsx index d6c63a4..fe9339c 100644 --- a/frontend/src/components/RuntimeOnline.tsx +++ b/frontend/src/components/RuntimeOnline.tsx @@ -2,6 +2,7 @@ import { Download, LoaderCircle, Pause, RefreshCw } from 'lucide-react' import React, { useEffect, useState } from 'react' import '../i18n/domains/wizard.gen' import { I18nKey, t } from '../i18n' +import { describeRuntimeStatus } from '../lib/runtimeStatus' import { taskDetail } from '../lib/tasks' import { InstalledRuntime, Locale, RemoteRuntime, Task } from '../types' import { Button, IconButton } from '../ui/controls' @@ -16,6 +17,7 @@ interface Props { onChannel: (alpha: boolean) => void onInstall: (commit: string) => void onCancel: (taskId: string) => void + onLatestCommit?: (commit: string) => void } const gb = (b: number) => (b >= 1e9 ? `${(b / 1e9).toFixed(1)} GB` : `${Math.ceil(b / 1e6)} MB`) @@ -27,7 +29,7 @@ const shortQemu = (v: string) => v.replace(/^QEMU emulator version\s*/i, 'QEMU ' * The runtime rows: the active runtime and whether it is current (or, with * none installed, the newest release to install), then the alpha switch. */ -export const RuntimeOnline: React.FC = ({ locale, channel, installed, task, onChannel, onInstall, onCancel }) => { +export const RuntimeOnline: React.FC = ({ locale, channel, installed, task, onChannel, onInstall, onCancel, onLatestCommit }) => { const tr = (k: I18nKey, v?: Record) => t(locale, k, v) const [remote, setRemote] = useState(null) const [error, setError] = useState('') @@ -43,16 +45,13 @@ export const RuntimeOnline: React.FC = ({ locale, channel, installed, tas return () => { live = false } }, [channel, task?.status === 'done', reload]) - const active = installed.find((i) => i.active) ?? installed[0] const latest = remote?.[0] - const sameRuntimeId = (a: string, b: string) => { - const [baseA, revA = ''] = a.split('-', 2) - const [baseB, revB = ''] = b.split('-', 2) - return revA === revB && (baseA.startsWith(baseB) || baseB.startsWith(baseA)) - } - const isInstalled = (c: string) => installed.some((i) => sameRuntimeId(i.commit, c)) + const { active, latestCommit, activeIsLatest, updatable, switchRecommended } = describeRuntimeStatus(installed, latest) const running = task?.status === 'running' - const updatable = !!latest && !isInstalled(latest.commit) + + useEffect(() => { + onLatestCommit?.(latestCommit) + }, [latestCommit, onLatestCommit]) let sub: React.ReactNode if (running && task) { @@ -67,6 +66,12 @@ export const RuntimeOnline: React.FC = ({ locale, channel, installed, tas {task.percent >= 0 ? `${Math.floor(task.percent)}%` : ''} {taskDetail(task)}
) + } else if (switchRecommended && active && latest) { + sub = ( +
+ {shortQemu(active.manifest.qemu_version)} · {tr('runtimeRecommendLatest', { v: latest.commit })} +
+ ) } else if (active && !updatable) { sub =
{shortQemu(active.manifest.qemu_version)}
} else if (error) { @@ -107,7 +112,9 @@ export const RuntimeOnline: React.FC = ({ locale, channel, installed, tas - ) : !running && active && remote ? ( + ) : !running && switchRecommended ? ( + {tr('runtimeNotLatest')} + ) : !running && active && activeIsLatest ? ( {tr('runtimeUpToDate')} ) : null}
diff --git a/frontend/src/i18n/domains/wizard.gen.ts b/frontend/src/i18n/domains/wizard.gen.ts index 93b1c61..442ad76 100644 --- a/frontend/src/i18n/domains/wizard.gen.ts +++ b/frontend/src/i18n/domains/wizard.gen.ts @@ -21,11 +21,14 @@ export const wizardZh: Record = { "runtimeCurrent": "当前运行时", "runtimeInstall": "安装", "runtimeLatest": "最新:{v}", + "runtimeLatestBadge": "最新", "runtimeLookupFailed": "无法读取运行时列表", "runtimeLookupRateLimit": "GitHub 接口限流(HTTP 403),请稍后重试或手动导入", "runtimeNewer": "有新版本:{v}", "runtimeNoneOnChannel": "这个通道还没有发布运行时", + "runtimeNotLatest": "不是最新", "runtimeOnline": "在线安装", + "runtimeRecommendLatest": "建议切换至最新运行时 {v}", "runtimeRetry": "重试", "runtimeUpToDate": "已是最新", "runtimeUpdate": "更新", @@ -109,11 +112,14 @@ export const wizardEn: Record = { "runtimeCurrent": "Current runtime", "runtimeInstall": "Install", "runtimeLatest": "Latest: {v}", + "runtimeLatestBadge": "Latest", "runtimeLookupFailed": "Couldn’t read the runtime list", "runtimeLookupRateLimit": "GitHub API rate limit reached (HTTP 403); retry later or import a local bundle", "runtimeNewer": "New version: {v}", "runtimeNoneOnChannel": "No runtime published on this channel yet", + "runtimeNotLatest": "Not latest", "runtimeOnline": "Online install", + "runtimeRecommendLatest": "Switch to latest runtime {v}", "runtimeRetry": "Retry", "runtimeUpToDate": "Up to date", "runtimeUpdate": "Update", diff --git a/frontend/src/i18n/keys.gen.ts b/frontend/src/i18n/keys.gen.ts index 6a69726..3894230 100644 --- a/frontend/src/i18n/keys.gen.ts +++ b/frontend/src/i18n/keys.gen.ts @@ -888,11 +888,14 @@ export type I18nKey = | "runtimeDeleted" | "runtimeInstall" | "runtimeLatest" + | "runtimeLatestBadge" | "runtimeLookupFailed" | "runtimeLookupRateLimit" | "runtimeNewer" | "runtimeNoneOnChannel" + | "runtimeNotLatest" | "runtimeOnline" + | "runtimeRecommendLatest" | "runtimeRetry" | "runtimeUpToDate" | "runtimeUpdate" diff --git a/frontend/src/lib/runtimeStatus.ts b/frontend/src/lib/runtimeStatus.ts new file mode 100644 index 0000000..8535a3a --- /dev/null +++ b/frontend/src/lib/runtimeStatus.ts @@ -0,0 +1,26 @@ +import { InstalledRuntime, RemoteRuntime } from '../types' + +export function sameRuntimeId(a: string, b: string): boolean { + const [baseA, revA = ''] = a.split('-', 2) + const [baseB, revB = ''] = b.split('-', 2) + return revA === revB && (baseA.startsWith(baseB) || baseB.startsWith(baseA)) +} + +interface RuntimeStatus { + active?: InstalledRuntime + latestCommit: string + activeIsLatest: boolean + latestInstalled: boolean + updatable: boolean + switchRecommended: boolean +} + +export function describeRuntimeStatus(installed: InstalledRuntime[], latest?: RemoteRuntime): RuntimeStatus { + const active = installed.find((i) => i.active) ?? installed[0] + const latestCommit = latest?.commit ?? '' + const activeIsLatest = !!active && !!latestCommit && sameRuntimeId(active.commit, latestCommit) + const latestInstalled = !!latestCommit && installed.some((i) => sameRuntimeId(i.commit, latestCommit)) + const updatable = !!latestCommit && !latestInstalled + const switchRecommended = !!active && !!latestCommit && !activeIsLatest && latestInstalled + return { active, latestCommit, activeIsLatest, latestInstalled, updatable, switchRecommended } +} diff --git a/locales/en-US/wizard.json b/locales/en-US/wizard.json index 4491ef1..108f372 100644 --- a/locales/en-US/wizard.json +++ b/locales/en-US/wizard.json @@ -23,8 +23,11 @@ "setupImport": "Import a local package…", "runtimeOnline": "Online install", "runtimeLatest": "Latest: {v}", + "runtimeLatestBadge": "Latest", "runtimeNoneOnChannel": "No runtime published on this channel yet", "runtimeUpToDate": "Up to date", + "runtimeNotLatest": "Not latest", + "runtimeRecommendLatest": "Switch to latest runtime {v}", "runtimeCurrent": "Current runtime", "runtimeUpdate": "Update", "runtimeNewer": "New version: {v}", diff --git a/locales/zh-CN/wizard.json b/locales/zh-CN/wizard.json index 56708ca..9ca8978 100644 --- a/locales/zh-CN/wizard.json +++ b/locales/zh-CN/wizard.json @@ -23,8 +23,11 @@ "setupImport": "导入本地包…", "runtimeOnline": "在线安装", "runtimeLatest": "最新:{v}", + "runtimeLatestBadge": "最新", "runtimeNoneOnChannel": "这个通道还没有发布运行时", "runtimeUpToDate": "已是最新", + "runtimeNotLatest": "不是最新", + "runtimeRecommendLatest": "建议切换至最新运行时 {v}", "runtimeCurrent": "当前运行时", "runtimeUpdate": "更新", "runtimeNewer": "有新版本:{v}",