fix(ui): mark older active runtime as not latest (#151)

This commit is contained in:
Nwflower committed 2026-12-04 07:16:57 -07:00
1 parent 4053ffb60c
commit 9d06e8db05
9 files changed
+122 -11

No files matched your search

+7
View File
@@ -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)."
}
+48
View File
@@ -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)
})
+9 -1
View File
@@ -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<Props> = ({ 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<StorageBreakdown | null>(null)
const { host, config, runtimes } = state
@@ -215,6 +217,7 @@ export const HostView: React.FC<Props> = ({ state, locale, onRefresh, onNewVM, o
onChannel={onChannel}
onInstall={onInstallRuntime}
onCancel={onCancelTask}
onLatestCommit={setLatestRuntimeCommit}
/>
<div className="row">
<div className="row-main">
@@ -228,7 +231,12 @@ export const HostView: React.FC<Props> = ({ state, locale, onRefresh, onNewVM, o
{(runtimes ?? []).filter((rt) => !rt.active).map((rt) => (
<div className="row" key={rt.commit}>
<div className="row-main">
<div className="row-title"><span className="mono">{rt.commit}</span></div>
<div className="row-title">
<span className="mono">{rt.commit}</span>
{latestRuntimeCommit && sameRuntimeId(rt.commit, latestRuntimeCommit) && (
<span className="badge rg-p-badge badge-ok">{tr('runtimeLatestBadge')}</span>
)}
</div>
<div className="row-sub">{rt.manifest.qemu_version.replace(/^QEMU emulator version\s*/i, 'QEMU ')}</div>
</div>
<div className="row-right">
+17 -10
View File
@@ -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<Props> = ({ locale, channel, installed, task, onChannel, onInstall, onCancel }) => {
export const RuntimeOnline: React.FC<Props> = ({ locale, channel, installed, task, onChannel, onInstall, onCancel, onLatestCommit }) => {
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
const [remote, setRemote] = useState<RemoteRuntime[] | null>(null)
const [error, setError] = useState('')
@@ -43,16 +45,13 @@ export const RuntimeOnline: React.FC<Props> = ({ 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<Props> = ({ locale, channel, installed, tas
<span>{task.percent >= 0 ? `${Math.floor(task.percent)}%` : ''} {taskDetail(task)}</span>
</div>
)
} else if (switchRecommended && active && latest) {
sub = (
<div className="row-sub">
{shortQemu(active.manifest.qemu_version)} · {tr('runtimeRecommendLatest', { v: latest.commit })}
</div>
)
} else if (active && !updatable) {
sub = <div className="row-sub">{shortQemu(active.manifest.qemu_version)}</div>
} else if (error) {
@@ -107,7 +112,9 @@ export const RuntimeOnline: React.FC<Props> = ({ locale, channel, installed, tas
<Button variant="primary" icon={<Download size={14} />} onClick={() => onInstall(latest!.commit)}>
{tr(active ? 'runtimeUpdate' : 'runtimeInstall')}
</Button>
) : !running && active && remote ? (
) : !running && switchRecommended ? (
<span className="badge rg-p-badge badge-warn">{tr('runtimeNotLatest')}</span>
) : !running && active && activeIsLatest ? (
<span className="badge rg-p-badge badge-ok">{tr('runtimeUpToDate')}</span>
) : null}
</div>
+6
View File
@@ -21,11 +21,14 @@ export const wizardZh: Record<string, string> = {
"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<string, string> = {
"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",
+3
View File
@@ -888,11 +888,14 @@ export type I18nKey =
| "runtimeDeleted"
| "runtimeInstall"
| "runtimeLatest"
| "runtimeLatestBadge"
| "runtimeLookupFailed"
| "runtimeLookupRateLimit"
| "runtimeNewer"
| "runtimeNoneOnChannel"
| "runtimeNotLatest"
| "runtimeOnline"
| "runtimeRecommendLatest"
| "runtimeRetry"
| "runtimeUpToDate"
| "runtimeUpdate"
+26
View File
@@ -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 }
}
+3
View File
@@ -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}",
+3
View File
@@ -23,8 +23,11 @@
"setupImport": "导入本地包…",
"runtimeOnline": "在线安装",
"runtimeLatest": "最新:{v}",
"runtimeLatestBadge": "最新",
"runtimeNoneOnChannel": "这个通道还没有发布运行时",
"runtimeUpToDate": "已是最新",
"runtimeNotLatest": "不是最新",
"runtimeRecommendLatest": "建议切换至最新运行时 {v}",
"runtimeCurrent": "当前运行时",
"runtimeUpdate": "更新",
"runtimeNewer": "有新版本:{v}",