feat(webui): standardize content loading states
Use consistent delayed placeholders across data-backed console surfaces. Avoid flashing loading UI for fast local responses while keeping slower transitions stable. Keep failures visible and prevent gated content from opening on incomplete checks.
This commit is contained in:
22 files changed
+2493
-1527
No files matched your search
@@ -6,6 +6,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { ProcessProbeDialog } from '@/components/process-probe-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { HookProcessInfo } from '@/types';
|
||||
import { useAppState } from '@/contexts/AppStateContext';
|
||||
@@ -48,7 +49,7 @@ function processBadgeVariant(status: HookProcessInfo['status']) {
|
||||
* regardless of which page is mounted.
|
||||
*/
|
||||
export function ProcessesPage() {
|
||||
const { processList, processOps, refreshProcesses } = useAppState();
|
||||
const { processList, processOps, refreshProcesses, resources } = useAppState();
|
||||
const { statusOf, banner: processActionStatus, load, unload, refresh } = processOps;
|
||||
const { pages, setPages } = useLayout();
|
||||
const off = useTheme().appearance.disableMotion;
|
||||
@@ -95,7 +96,12 @@ export function ProcessesPage() {
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
<Button variant="outline" size="sm" onClick={refreshProcesses}>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={refreshProcesses}
|
||||
disabled={!resources.processList.ready}
|
||||
>
|
||||
<RefreshCw className="size-3.5" /> 刷新
|
||||
</Button>
|
||||
</div>
|
||||
@@ -111,129 +117,154 @@ export function ProcessesPage() {
|
||||
{processActionStatus}
|
||||
</motion.div>
|
||||
)}
|
||||
{processList.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<Cpu className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">未检测到可加载 QQ 主进程</p>
|
||||
<p className="text-xs text-muted-foreground/80">请确认 QQ 已启动后点击右上角刷新</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-3 xl:grid-cols-2 2xl:grid-cols-3">
|
||||
{sorted.map((proc, idx) => {
|
||||
const op = statusOf(proc.pid);
|
||||
const loading = op === 'load' || proc.status === 'loading';
|
||||
const unloading = op === 'unload';
|
||||
const refreshing = op === 'refresh';
|
||||
const busy = op != null || proc.status === 'loading';
|
||||
const isOnline = proc.status === 'online';
|
||||
const canUnload = proc.injected;
|
||||
// Refresh is meaningful whenever a hook may exist (so the user
|
||||
// can re-check the pipe and trigger a reconnect on demand).
|
||||
const showRefresh = proc.injected || proc.status === 'connecting' || proc.status === 'disconnected';
|
||||
return (
|
||||
<motion.div
|
||||
key={proc.pid}
|
||||
initial={off ? false : { opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={off ? { duration: 0 } : { delay: 0.03 + idx * 0.025, duration: 0.22 }}
|
||||
className="flex flex-col gap-3 rounded-xl border bg-card/50 p-3.5 transition-colors hover:bg-accent/20 sm:flex-row sm:items-center"
|
||||
>
|
||||
{/* icon + info stay horizontal; on phones the actions drop to
|
||||
a second row so name / PID / path get the full width
|
||||
instead of collapsing to "Q..". */}
|
||||
<div className="flex min-w-0 flex-1 items-center gap-3">
|
||||
<div
|
||||
className={cn(
|
||||
'flex size-10 shrink-0 items-center justify-center rounded-xl',
|
||||
isOnline
|
||||
? 'bg-success/15 text-success'
|
||||
: proc.status === 'error'
|
||||
? 'bg-destructive/15 text-destructive'
|
||||
: 'bg-primary/10 text-primary'
|
||||
)}
|
||||
>
|
||||
{isOnline ? (
|
||||
<CheckCircle2 className="size-5" />
|
||||
) : proc.status === 'error' ? (
|
||||
<AlertCircle className="size-5" />
|
||||
) : (
|
||||
<Cpu className="size-5" />
|
||||
)}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 truncate text-sm font-semibold">{proc.name || 'QQ.exe'}</span>
|
||||
<Badge variant={processBadgeVariant(proc.status)} className="shrink-0 whitespace-nowrap">
|
||||
{processStatusLabel[proc.status]}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="mt-0.5 truncate font-mono text-meta text-muted-foreground tabular-nums">
|
||||
PID {proc.pid}
|
||||
{proc.uin && proc.uin !== '0' ? ` · UIN ${proc.uin}` : ''}
|
||||
</div>
|
||||
{proc.path && (
|
||||
<div className="truncate text-meta text-muted-foreground/80" title={proc.path}>
|
||||
{proc.path}
|
||||
</div>
|
||||
)}
|
||||
{proc.error && (
|
||||
<div className="mt-0.5 truncate text-xs text-destructive" title={proc.error}>
|
||||
{proc.error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex shrink-0 flex-wrap items-center gap-1.5">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={busy}
|
||||
onClick={() => setProbeDialog({ pid: proc.pid, name: proc.name || `PID ${proc.pid}` })}
|
||||
>
|
||||
<Eye className="size-3.5" /> 探测登录
|
||||
</Button>
|
||||
{showRefresh && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
disabled={busy}
|
||||
aria-label={`刷新进程 ${proc.pid} 管道状态`}
|
||||
title="刷新管道状态 / 重连"
|
||||
onClick={() => refresh(proc.pid)}
|
||||
className="size-8 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{refreshing ? (
|
||||
<Loader2 className="size-3.5 animate-spin" />
|
||||
) : (
|
||||
<RefreshCw className="size-3.5" />
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant={canUnload ? 'outline' : 'default'}
|
||||
disabled={busy}
|
||||
onClick={() =>
|
||||
setConfirm({
|
||||
kind: canUnload ? 'unload' : 'load',
|
||||
pid: proc.pid,
|
||||
name: proc.name || `PID ${proc.pid}`,
|
||||
})
|
||||
}
|
||||
className={cn(
|
||||
canUnload && 'text-destructive hover:bg-destructive/10 hover:text-destructive'
|
||||
)}
|
||||
>
|
||||
{(loading || unloading) && <Loader2 className="size-3.5 animate-spin" />}
|
||||
{!loading && !unloading && canUnload && <Unplug className="size-3.5" />}
|
||||
{canUnload ? (unloading ? '卸载中' : '卸载') : loading ? '加载中' : '加载'}
|
||||
</Button>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
})}
|
||||
{resources.processList.error && processList.length > 0 && (
|
||||
<div role="alert" className="mb-3 rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{resources.processList.error};当前显示上次成功读取的进程状态。
|
||||
</div>
|
||||
)}
|
||||
<SkeletonSwap
|
||||
ready={resources.processList.ready}
|
||||
reserve={192}
|
||||
lines={6}
|
||||
lineHeight={32}
|
||||
barHeight={10}
|
||||
label="进程列表"
|
||||
className={resources.processList.ready ? 'skeleton-swap-fluid min-h-[192px]' : ''}
|
||||
>
|
||||
{resources.processList.ready ? (
|
||||
resources.processList.error && processList.length === 0 ? (
|
||||
<div role="alert" className="flex flex-col items-center justify-center gap-3 rounded-xl border border-destructive/30 bg-destructive/10 py-16 text-destructive">
|
||||
<AlertCircle className="size-8 opacity-70" strokeWidth={1.5} />
|
||||
<p className="text-sm">{resources.processList.error}</p>
|
||||
<Button variant="outline" size="sm" onClick={refreshProcesses}>
|
||||
<RefreshCw className="size-3.5" /> 重试
|
||||
</Button>
|
||||
</div>
|
||||
) : processList.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<Cpu className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">未检测到可加载 QQ 主进程</p>
|
||||
<p className="text-xs text-muted-foreground/80">请确认 QQ 已启动后点击右上角刷新</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-3 xl:grid-cols-2 2xl:grid-cols-3">
|
||||
{sorted.map((proc, idx) => {
|
||||
const op = statusOf(proc.pid);
|
||||
const loading = op === 'load' || proc.status === 'loading';
|
||||
const unloading = op === 'unload';
|
||||
const refreshing = op === 'refresh';
|
||||
const busy = op != null || proc.status === 'loading';
|
||||
const isOnline = proc.status === 'online';
|
||||
const canUnload = proc.injected;
|
||||
// Refresh is meaningful whenever a hook may exist (so the user
|
||||
// can re-check the pipe and trigger a reconnect on demand).
|
||||
const showRefresh = proc.injected || proc.status === 'connecting' || proc.status === 'disconnected';
|
||||
return (
|
||||
<motion.div
|
||||
key={proc.pid}
|
||||
initial={off ? false : { opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={off ? { duration: 0 } : { delay: 0.03 + idx * 0.025, duration: 0.22 }}
|
||||
className="flex flex-col gap-3 rounded-xl border bg-card/50 p-3.5 transition-colors hover:bg-accent/20 sm:flex-row sm:items-center"
|
||||
>
|
||||
{/* icon + info stay horizontal; on phones the actions drop to
|
||||
a second row so name / PID / path get the full width
|
||||
instead of collapsing to "Q..". */}
|
||||
<div className="flex min-w-0 flex-1 items-center gap-3">
|
||||
<div
|
||||
className={cn(
|
||||
'flex size-10 shrink-0 items-center justify-center rounded-xl',
|
||||
isOnline
|
||||
? 'bg-success/15 text-success'
|
||||
: proc.status === 'error'
|
||||
? 'bg-destructive/15 text-destructive'
|
||||
: 'bg-primary/10 text-primary'
|
||||
)}
|
||||
>
|
||||
{isOnline ? (
|
||||
<CheckCircle2 className="size-5" />
|
||||
) : proc.status === 'error' ? (
|
||||
<AlertCircle className="size-5" />
|
||||
) : (
|
||||
<Cpu className="size-5" />
|
||||
)}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 truncate text-sm font-semibold">{proc.name || 'QQ.exe'}</span>
|
||||
<Badge variant={processBadgeVariant(proc.status)} className="shrink-0 whitespace-nowrap">
|
||||
{processStatusLabel[proc.status]}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="mt-0.5 truncate font-mono text-meta text-muted-foreground tabular-nums">
|
||||
PID {proc.pid}
|
||||
{proc.uin && proc.uin !== '0' ? ` · UIN ${proc.uin}` : ''}
|
||||
</div>
|
||||
{proc.path && (
|
||||
<div className="truncate text-meta text-muted-foreground/80" title={proc.path}>
|
||||
{proc.path}
|
||||
</div>
|
||||
)}
|
||||
{proc.error && (
|
||||
<div className="mt-0.5 truncate text-xs text-destructive" title={proc.error}>
|
||||
{proc.error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex shrink-0 flex-wrap items-center gap-1.5">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={busy}
|
||||
onClick={() => setProbeDialog({ pid: proc.pid, name: proc.name || `PID ${proc.pid}` })}
|
||||
>
|
||||
<Eye className="size-3.5" /> 探测登录
|
||||
</Button>
|
||||
{showRefresh && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
disabled={busy}
|
||||
aria-label={`刷新进程 ${proc.pid} 管道状态`}
|
||||
title="刷新管道状态 / 重连"
|
||||
onClick={() => refresh(proc.pid)}
|
||||
className="size-8 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{refreshing ? (
|
||||
<Loader2 className="size-3.5 animate-spin" />
|
||||
) : (
|
||||
<RefreshCw className="size-3.5" />
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant={canUnload ? 'outline' : 'default'}
|
||||
disabled={busy}
|
||||
onClick={() =>
|
||||
setConfirm({
|
||||
kind: canUnload ? 'unload' : 'load',
|
||||
pid: proc.pid,
|
||||
name: proc.name || `PID ${proc.pid}`,
|
||||
})
|
||||
}
|
||||
className={cn(
|
||||
canUnload && 'text-destructive hover:bg-destructive/10 hover:text-destructive'
|
||||
)}
|
||||
>
|
||||
{(loading || unloading) && <Loader2 className="size-3.5 animate-spin" />}
|
||||
{!loading && !unloading && canUnload && <Unplug className="size-3.5" />}
|
||||
{canUnload ? (unloading ? '卸载中' : '卸载') : loading ? '加载中' : '加载'}
|
||||
</Button>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
Reference in new issue
Block a user