diff --git a/apps/desktop/e2e/features/groups.spec.ts b/apps/desktop/e2e/features/groups.spec.ts
index bb22417..d19373c 100644
--- a/apps/desktop/e2e/features/groups.spec.ts
+++ b/apps/desktop/e2e/features/groups.spec.ts
@@ -83,7 +83,7 @@ test('a serial group across projects waits for each step, then stops everything'
await expect(bar).toContainText(/front1启动中 \d\/2/)
await expect(titleBar).toHaveCount(0)
await page.getByRole('button', { name: '批量', exact: true }).click()
- await expect(item).toContainText('已完成', { timeout: 30_000 })
+ await expect(item).toContainText('运行中 2/2', { timeout: 30_000 })
// The navigation badge and bar remain while the servers keep running after the execution ended.
await expect(running).toHaveText(/\d+/)
await page.getByRole('button', { name: '运行中', exact: true }).click()
@@ -91,7 +91,7 @@ test('a serial group across projects waits for each step, then stops everything'
await expect(titleBar).toHaveCount(0)
await page.getByRole('button', { name: '批量', exact: true }).click()
await expect(detail).toContainText('2/2 个步骤完成')
- await expect(detail).toContainText('服务进程可能仍在运行')
+ await expect(detail).toContainText('服务进程正在运行中')
await expect(detail.getByRole('button', { name: '停止全部' })).toBeEnabled()
await expect(detail.getByRole('listitem', { name: '运行步骤 1' })).toContainText('本次启动')
await detail
@@ -194,7 +194,7 @@ test('waits for a regex in the output and remembers the result after a restart',
const item = () => page.getByRole('listitem', { name: '批量任务 backend' })
await item().getByRole('button', { name: '执行 backend' }).click()
- await expect(item()).toContainText(/已完成 · \d{2}:\d{2}/)
+ await expect(item()).toContainText('运行中 1/1', { timeout: 30_000 })
await item().getByRole('button', { name: '查看 backend' }).click()
const detail = () => page.getByRole('region', { name: '任务运行 backend' })
await expect(detail()).toContainText('本次启动')
diff --git a/apps/desktop/e2e/process/ports.spec.ts b/apps/desktop/e2e/process/ports.spec.ts
index 1d0d830..35ee9ec 100644
--- a/apps/desktop/e2e/process/ports.spec.ts
+++ b/apps/desktop/e2e/process/ports.spec.ts
@@ -257,7 +257,7 @@ for (const mode of ['serial', 'parallel'] as const) {
await item.getByRole('button', { name: '执行 replace listeners' }).click()
// Windows performs verified CIM snapshots for each sequential port takeover.
- await expect(item).toContainText('已完成', { timeout: 35_000 })
+ await expect(item).toContainText('运行中 2/2', { timeout: 35_000 })
await expect.poll(() => httpBody(first.port)).toBe('group-first')
await expect.poll(() => httpBody(second.port)).toBe('group-second')
await expect.poll(() => [hasExited(first), hasExited(second)]).toEqual([true, true])
diff --git a/apps/desktop/src/renderer/src/features/groups/batch-task-list.tsx b/apps/desktop/src/renderer/src/features/groups/batch-task-list.tsx
index 0a75586..55f70a8 100644
--- a/apps/desktop/src/renderer/src/features/groups/batch-task-list.tsx
+++ b/apps/desktop/src/renderer/src/features/groups/batch-task-list.tsx
@@ -23,6 +23,7 @@ import {
} from '@renderer/components/ui/dropdown-menu'
import { useRuns } from '@renderer/features/runs/use-runs'
import { cn } from '@renderer/lib/utils'
+import { resolveGroupStatus } from './group-status'
import { GROUP_SORT_STORAGE_KEY, getStoredGroupSortOrder } from './group-sort'
import { GroupSortMenu } from './group-sort-menu'
import {
@@ -67,7 +68,8 @@ export function BatchTaskList({
}
}
- const activeIds = new Set(activeGroups(states.data ?? [], runs).map((group) => group.groupId))
+ const activeList = activeGroups(states.data ?? [], runs)
+ const activeIds = new Set(activeList.map((group) => group.groupId))
const sortedGroups = sortGroups(groups.data ?? [], activeIds, {
order: sortOrder,
states: states.data
@@ -114,10 +116,9 @@ export function BatchTaskList({
{sortedGroups.map((group) => {
const state = states.data?.find((s) => s.groupId === group.id)
+ const active = activeList.find((a) => a.groupId === group.id)
+ const presentation = resolveGroupStatus({ group, state, active })
const isSelected = group.id === selectedGroupId
- const running = state?.status === 'running'
- const failed = state?.status === 'failed'
- const done = state?.status === 'done'
const busy =
(start.isPending && start.variables === group.id) ||
(stop.isPending && stop.variables === group.id)
@@ -140,10 +141,11 @@ export function BatchTaskList({
@@ -168,21 +170,15 @@ export function BatchTaskList({
variant="secondary"
className={cn(
'h-4 shrink-0 px-1 font-mono text-[9px] font-normal border-0',
- running && 'bg-primary/15 text-primary font-medium',
- failed && 'bg-destructive/15 text-destructive font-medium',
- done && 'bg-secondary text-muted-foreground',
- !state && 'bg-secondary/60 text-muted-foreground/60'
+ presentation.isActive && 'bg-primary/15 text-primary font-medium',
+ presentation.phase === 'failed' &&
+ 'bg-destructive/15 text-destructive font-medium',
+ (presentation.phase === 'done' || presentation.phase === 'stopped') &&
+ 'bg-secondary text-muted-foreground',
+ presentation.phase === 'idle' && 'bg-secondary/60 text-muted-foreground/60'
)}
>
- {running
- ? '运行中'
- : failed
- ? '失败'
- : done
- ? '已完成'
- : group.mode === 'parallel'
- ? '并行'
- : '串行'}
+ {presentation.badgeText}
@@ -191,14 +187,8 @@ export function BatchTaskList({
{group.steps.length} 步 · {group.mode === 'parallel' ? '并行' : '串行'}
-
- {running
- ? '运行中'
- : failed
- ? (state?.steps?.find((s) => s.state === 'failed')?.message ?? '失败')
- : state?.finishedAt
- ? `已完成 · ${formatFinished(state.finishedAt)}`
- : '未运行'}
+
+ {presentation.summaryText}
@@ -208,12 +198,12 @@ export function BatchTaskList({
variant="ghost"
size="icon-xs"
onClick={() => start.mutate(group.id, { onError: (e) => setError(e.message) })}
- disabled={busy || running}
+ disabled={busy || presentation.phase === 'starting'}
aria-label={`执行 ${group.name}`}
- title="执行任务"
+ title={presentation.isActive ? '重新执行任务' : '执行任务'}
className="size-6 text-muted-foreground hover:text-foreground"
>
- {busy && !running ? (
+ {busy && presentation.phase === 'starting' ? (
) : (
@@ -224,10 +214,15 @@ export function BatchTaskList({
variant="ghost"
size="icon-xs"
onClick={() => stop.mutate(group.id, { onError: (e) => setError(e.message) })}
- disabled={busy}
+ disabled={busy || !presentation.isActive}
aria-label={`停止 ${group.name}`}
title="停止全部"
- className="size-6 text-muted-foreground hover:text-foreground"
+ className={cn(
+ 'size-6 transition-colors',
+ presentation.isActive
+ ? 'text-destructive hover:bg-destructive/15 hover:text-destructive'
+ : 'text-muted-foreground/40 hover:text-muted-foreground'
+ )}
>
@@ -309,11 +304,3 @@ export function BatchTaskList({
)
}
-
-function formatFinished(iso: string): string {
- const date = new Date(iso)
- const time = date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
- return date.toDateString() === new Date().toDateString()
- ? time
- : `${date.getMonth() + 1}月${date.getDate()}日 ${time}`
-}
diff --git a/apps/desktop/src/renderer/src/features/groups/group-detail.tsx b/apps/desktop/src/renderer/src/features/groups/group-detail.tsx
index 61757b4..c973057 100644
--- a/apps/desktop/src/renderer/src/features/groups/group-detail.tsx
+++ b/apps/desktop/src/renderer/src/features/groups/group-detail.tsx
@@ -1,6 +1,6 @@
import { useState } from 'react'
import { Pencil, Play, RotateCcw, Square } from 'lucide-react'
-import { formatDuration, type Group, type GroupRunState, type Run } from '@devhub/shared'
+import { activeGroups, formatDuration, type Group, type Run } from '@devhub/shared'
import { access } from '@renderer/api'
import { Badge } from '@renderer/components/ui/badge'
import { Button } from '@renderer/components/ui/button'
@@ -12,16 +12,10 @@ import { cn } from '@renderer/lib/utils'
import { GroupEditor } from './group-editor'
import { GroupOutputPanel } from './group-output-panel'
import { GroupProgressBar } from './group-progress-bar'
+import { resolveGroupStatus } from './group-status'
import { GroupStepCard } from './group-step-card'
import { useGroupStates, useStartGroup, useStopGroup } from './use-groups'
-const statusLabels: Record = {
- running: '执行中',
- done: '已完成',
- failed: '失败',
- stopped: '已停止'
-}
-
export function GroupDetail({
group,
onOpenRun
@@ -29,11 +23,14 @@ export function GroupDetail({
group: Group
onOpenRun: (run: Run) => void
}): React.JSX.Element {
- const state = useGroupStates().data?.find((candidate) => candidate.groupId === group.id)
+ const allStates = useGroupStates().data ?? []
+ const state = allStates.find((candidate) => candidate.groupId === group.id)
const execution = state?.group ?? group
const projects = useProjects().data ?? []
const runs = useRuns().data ?? []
const health = useRunHealth().data ?? []
+ const active = activeGroups(allStates, runs).find((candidate) => candidate.groupId === group.id)
+ const presentation = resolveGroupStatus({ group, state, active })
const start = useStartGroup()
const stop = useStopGroup()
const [editing, setEditing] = useState(false)
@@ -74,7 +71,6 @@ export function GroupDetail({
)
const isParallel = execution.mode === 'parallel'
- const currentStepNum = Math.min(completed + 1, execution.steps.length)
return (
- {running
- ? `第 ${currentStepNum} / ${execution.steps.length} 步 · 运行中`
- : state
- ? statusLabels[state.status]
- : '尚未执行'}
+ {presentation.detailBadgeText}
@@ -205,15 +198,7 @@ export function GroupDetail({
totalCount={execution.steps.length}
stepStates={stepStates}
durationText={groupDurationMs !== null ? formatDuration(groupDurationMs) : null}
- statusHint={
- running
- ? `正在执行第 ${currentStepNum} 步`
- : state?.status === 'done'
- ? '全部步骤就绪'
- : state?.status === 'failed'
- ? '执行中断'
- : '待执行'
- }
+ statusHint={presentation.progressHint}
/>
{/* Main body scrollable area */}
@@ -237,9 +222,15 @@ export function GroupDetail({
)}
- {state?.status === 'done' && (
+ {presentation.phase === 'running' && (
- 步骤已完成,服务进程可能仍在运行。当前有 {activeRuns.length} 个活动脚本。
+ 步骤已就绪,服务进程正在运行中。当前有 {activeRuns.length} 个活动脚本。
+
+ )}
+
+ {presentation.phase === 'done' && (
+
+ 上次执行步骤已完成,相关服务均已停止。
)}
diff --git a/apps/desktop/src/renderer/src/features/groups/group-editor.tsx b/apps/desktop/src/renderer/src/features/groups/group-editor.tsx
index 9c87a5b..22a9706 100644
--- a/apps/desktop/src/renderer/src/features/groups/group-editor.tsx
+++ b/apps/desktop/src/renderer/src/features/groups/group-editor.tsx
@@ -88,7 +88,7 @@ export function GroupEditor({
把多个项目的脚本组合在一起,一键启动或停止。
-
+
group.groupId))
+ const activeList = activeGroups(states.data ?? [], runs)
+ const activeIds = new Set(activeList.map((group) => group.groupId))
const sortedGroups = sortGroups(groups.data ?? [], activeIds, {
order: sortOrder,
states: states.data
@@ -142,6 +145,7 @@ export function GroupList({
selected={group.id === selectedGroupId}
onSelect={() => onSelectGroup(group.id)}
state={states.data?.find((state) => state.groupId === group.id)}
+ active={activeList.find((a) => a.groupId === group.id)}
projects={projects}
busy={
(start.isPending && start.variables === group.id) ||
@@ -178,6 +182,7 @@ interface GroupItemProps {
onSelect: () => void
group: Group
state: GroupRunState | undefined
+ active: ActiveGroup | undefined
projects: Project[]
busy: boolean
onStart: () => void
@@ -189,18 +194,12 @@ interface GroupItemProps {
onSelectProject: (projectId: string) => void
}
-const statusLabels: Record
= {
- running: '执行中',
- done: '已完成',
- failed: '失败',
- stopped: '已停止'
-}
-
function GroupItem({
selected,
onSelect,
group,
state,
+ active,
projects,
busy,
onStart,
@@ -211,9 +210,11 @@ function GroupItem({
onSelectProject
}: GroupItemProps): React.JSX.Element {
const deleteGroup = useDeleteGroup()
- const running = state?.status === 'running'
+ const presentation = resolveGroupStatus({ group, state, active })
// Show the steps while something is happening or went wrong; finished groups stay compact.
- const showSteps = state && (state.status === 'running' || state.status === 'failed')
+ const showSteps =
+ state &&
+ (state.status === 'running' || state.status === 'failed' || presentation.phase === 'running')
return (
-
- {state
- ? [statusLabels[state.status], state.finishedAt && formatFinished(state.finishedAt)]
- .filter(Boolean)
- .join(' · ')
- : `${group.steps.length} 个脚本`}
+ {state ? presentation.summaryText : `${group.steps.length} 个脚本`}