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
@@ -10,10 +10,10 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { motion } from 'motion/react';
|
||||
import { Check, Loader2, MousePointerClick, Plus, Save } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { ScrollableTabList } from '@/components/ui/tabs';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type {
|
||||
AdapterStatus,
|
||||
@@ -41,9 +41,19 @@ type DialogState =
|
||||
// index: null → create with `seed`, otherwise edit the item at that position.
|
||||
|
||||
export function ConfigPage() {
|
||||
const { qqList, connections, selectedUin, setSelectedUin } = useAppState();
|
||||
const {
|
||||
qqList,
|
||||
connections,
|
||||
selectedUin,
|
||||
setSelectedUin,
|
||||
resources,
|
||||
refreshQqList,
|
||||
} = useAppState();
|
||||
const {
|
||||
config,
|
||||
loading,
|
||||
loadError,
|
||||
reload,
|
||||
setConfig,
|
||||
dirty,
|
||||
requestSwitchUin,
|
||||
@@ -57,7 +67,6 @@ export function ConfigPage() {
|
||||
selectedUin,
|
||||
onSelectedUinChange: setSelectedUin,
|
||||
});
|
||||
|
||||
const { pages, setPages } = useLayout();
|
||||
const [activeTab, setActiveTabState] = useState<TabKey>(() => {
|
||||
const t = pages.configTab;
|
||||
@@ -169,99 +178,136 @@ export function ConfigPage() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex gap-4">
|
||||
<AccountSidebar
|
||||
accounts={qqList}
|
||||
selectedUin={selectedUin}
|
||||
onSelect={requestSwitchUin}
|
||||
collapsed={sidebarCollapsed}
|
||||
onToggleCollapsed={() => setSidebarCollapsed((v) => !v)}
|
||||
/>
|
||||
|
||||
<div className="min-w-0 flex-1">
|
||||
{!selectedUin ? (
|
||||
<EmptyState />
|
||||
) : !config ? (
|
||||
<LoadingSkeleton />
|
||||
<SkeletonSwap
|
||||
ready={resources.qqList.ready}
|
||||
lines={7}
|
||||
lineHeight={28}
|
||||
barHeight={11}
|
||||
reserve={196}
|
||||
label="账号列表"
|
||||
className={resources.qqList.ready ? 'skeleton-swap-fluid min-h-[196px]' : ''}
|
||||
>
|
||||
{resources.qqList.ready ? (
|
||||
resources.qqList.error && qqList.length === 0 ? (
|
||||
<ConfigLoadError message={resources.qqList.error} onRetry={refreshQqList} />
|
||||
) : (
|
||||
<div className="flex flex-col gap-4">
|
||||
<HeaderBar
|
||||
selectedUin={selectedUin}
|
||||
dirty={dirty}
|
||||
saveStatus={saveStatus}
|
||||
saveStatusTone={saveStatusTone}
|
||||
onSave={immediateSave}
|
||||
activeTab={activeTab}
|
||||
onCreate={
|
||||
activeTab !== 'general' ? () => openCreate(activeTab as NetworkKind) : undefined
|
||||
}
|
||||
/>
|
||||
<div className="flex flex-col gap-3">
|
||||
{resources.qqList.error && (
|
||||
<div role="alert" className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{resources.qqList.error};当前显示上次成功读取的账号列表。
|
||||
</div>
|
||||
)}
|
||||
<div className="flex gap-4">
|
||||
<AccountSidebar
|
||||
accounts={qqList}
|
||||
selectedUin={selectedUin}
|
||||
onSelect={requestSwitchUin}
|
||||
collapsed={sidebarCollapsed}
|
||||
onToggleCollapsed={() => setSidebarCollapsed((v) => !v)}
|
||||
/>
|
||||
|
||||
<TabStrip
|
||||
activeTab={activeTab}
|
||||
onChange={setActiveTab}
|
||||
counts={countMap(config.networks)}
|
||||
/>
|
||||
<div className="min-w-0 flex-1">
|
||||
{!selectedUin ? (
|
||||
<EmptyState />
|
||||
) : (
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
lines={7}
|
||||
lineHeight={28}
|
||||
barHeight={11}
|
||||
reserve={196}
|
||||
label="账号配置"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-[196px]' : 'w-full'}
|
||||
>
|
||||
{!loading ? (
|
||||
loadError || !config ? (
|
||||
<ConfigLoadError message={loadError ?? '账号配置不可用'} onRetry={reload} />
|
||||
) : (
|
||||
<div className="flex flex-col gap-4">
|
||||
<HeaderBar
|
||||
selectedUin={selectedUin}
|
||||
dirty={dirty}
|
||||
saveStatus={saveStatus}
|
||||
saveStatusTone={saveStatusTone}
|
||||
onSave={immediateSave}
|
||||
activeTab={activeTab}
|
||||
onCreate={
|
||||
activeTab !== 'general' ? () => openCreate(activeTab as NetworkKind) : undefined
|
||||
}
|
||||
/>
|
||||
|
||||
<div
|
||||
id={`config-panel-${activeTab}`}
|
||||
role="tabpanel"
|
||||
aria-labelledby={`config-tab-${activeTab}`}
|
||||
>
|
||||
{activeTab === 'general' ? (
|
||||
<GeneralSettingsTab config={config} onChange={setConfig} />
|
||||
) : (
|
||||
<NetworkTabView
|
||||
kind={activeTab}
|
||||
config={config}
|
||||
statusByName={liveStatusByName}
|
||||
onCreateClick={() => openCreate(activeTab)}
|
||||
onEdit={(idx) => openEdit(activeTab, idx)}
|
||||
onDelete={(idx) => handleDelete(activeTab, idx)}
|
||||
onToggleEnabled={(idx, v) => handleToggleEnabled(activeTab, idx, v)}
|
||||
<TabStrip
|
||||
activeTab={activeTab}
|
||||
onChange={setActiveTab}
|
||||
counts={countMap(config.networks)}
|
||||
/>
|
||||
|
||||
<div
|
||||
id={`config-panel-${activeTab}`}
|
||||
role="tabpanel"
|
||||
aria-labelledby={`config-tab-${activeTab}`}
|
||||
>
|
||||
{activeTab === 'general' ? (
|
||||
<GeneralSettingsTab config={config} onChange={setConfig} />
|
||||
) : (
|
||||
<NetworkTabView
|
||||
kind={activeTab}
|
||||
config={config}
|
||||
statusByName={liveStatusByName}
|
||||
onCreateClick={() => openCreate(activeTab)}
|
||||
onEdit={(idx) => openEdit(activeTab, idx)}
|
||||
onDelete={(idx) => handleDelete(activeTab, idx)}
|
||||
onToggleEnabled={(idx, v) => handleToggleEnabled(activeTab, idx, v)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Single dialog covers create + edit across all 4 kinds. */}
|
||||
{dialog.open && config && (
|
||||
<NodeEditDialog
|
||||
open={dialog.open}
|
||||
onOpenChange={(open) => !open && setDialog({ open: false })}
|
||||
kind={dialog.kind}
|
||||
initial={dialog.seed}
|
||||
isEdit={dialog.index != null}
|
||||
otherNames={otherNames(config.networks, dialog.kind, dialog.index)}
|
||||
onSubmit={(item) => {
|
||||
if (dialog.index == null) handleCreate(dialog.kind, item);
|
||||
else handleEdit(dialog.kind, dialog.index, item);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={pendingSwitchUin != null}
|
||||
onOpenChange={(open) => !open && cancelSwitch()}
|
||||
title="放弃未保存的修改?"
|
||||
description={
|
||||
<>
|
||||
<p>
|
||||
当前会话 <code className="font-mono">{selectedUin}</code> 还有未保存的修改。
|
||||
</p>
|
||||
<p className="mt-2">
|
||||
切换到 <code className="font-mono">{pendingSwitchAccount?.uin ?? pendingSwitchUin}</code>
|
||||
{pendingSwitchAccount?.nickname ? `(${pendingSwitchAccount.nickname})` : ''} 会丢弃这些修改。
|
||||
</p>
|
||||
</>
|
||||
}
|
||||
confirmText="放弃并切换"
|
||||
destructive
|
||||
onConfirm={confirmSwitch}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Single dialog covers create + edit across all 4 kinds. */}
|
||||
{dialog.open && config && (
|
||||
<NodeEditDialog
|
||||
open={dialog.open}
|
||||
onOpenChange={(open) => !open && setDialog({ open: false })}
|
||||
kind={dialog.kind}
|
||||
initial={dialog.seed}
|
||||
isEdit={dialog.index != null}
|
||||
otherNames={otherNames(config.networks, dialog.kind, dialog.index)}
|
||||
onSubmit={(item) => {
|
||||
if (dialog.index == null) handleCreate(dialog.kind, item);
|
||||
else handleEdit(dialog.kind, dialog.index, item);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={pendingSwitchUin != null}
|
||||
onOpenChange={(open) => !open && cancelSwitch()}
|
||||
title="放弃未保存的修改?"
|
||||
description={
|
||||
<>
|
||||
<p>
|
||||
当前会话 <code className="font-mono">{selectedUin}</code> 还有未保存的修改。
|
||||
</p>
|
||||
<p className="mt-2">
|
||||
切换到 <code className="font-mono">{pendingSwitchAccount?.uin ?? pendingSwitchUin}</code>
|
||||
{pendingSwitchAccount?.nickname ? `(${pendingSwitchAccount.nickname})` : ''} 会丢弃这些修改。
|
||||
</p>
|
||||
</>
|
||||
}
|
||||
confirmText="放弃并切换"
|
||||
destructive
|
||||
onConfirm={confirmSwitch}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -494,13 +540,13 @@ function EmptyState() {
|
||||
);
|
||||
}
|
||||
|
||||
function LoadingSkeleton() {
|
||||
function ConfigLoadError({ message, onRetry }: { message: string; onRetry: () => void }) {
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-9 w-48" />
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-20" />
|
||||
<Skeleton className="h-20" />
|
||||
<div className="flex h-64 flex-col items-center justify-center gap-3 rounded-xl border border-dashed text-muted-foreground">
|
||||
<p className="max-w-md text-center text-sm text-destructive">{message}</p>
|
||||
<Button variant="outline" size="sm" onClick={onRetry}>
|
||||
重试
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { ActionTester } from '@/components/debug/action-tester';
|
||||
import { MessageComposer } from '@/components/debug/message-composer';
|
||||
import { LiveActivity } from '@/components/debug/live-activity';
|
||||
import { ApiBrowser } from '@/components/debug/api-browser';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { useApi } from '@/lib/api';
|
||||
import type { DebugActionDoc, QQInfo } from '@/types';
|
||||
|
||||
@@ -20,6 +21,8 @@ export function DebugPage() {
|
||||
const api = useApi();
|
||||
const [accounts, setAccounts] = useState<QQInfo[]>([]);
|
||||
const [docs, setDocs] = useState<DebugActionDoc[]>([]);
|
||||
const [ready, setReady] = useState(false);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
const [tab, setTab] = useState<Tab>('tester');
|
||||
const [preset, setPreset] = useState<{ name: string; nonce: number } | undefined>();
|
||||
|
||||
@@ -29,7 +32,12 @@ export function DebugPage() {
|
||||
const [qq, acts] = await Promise.all([api.qqList(), api.debug.actions()]);
|
||||
setAccounts(qq);
|
||||
setDocs(acts.actions);
|
||||
} catch { /* surfaced lazily on invoke */ }
|
||||
} catch (error) {
|
||||
console.error('load debug tools', error);
|
||||
setLoadError(error instanceof Error ? error.message : '加载开发者工具失败');
|
||||
} finally {
|
||||
setReady(true);
|
||||
}
|
||||
})();
|
||||
}, [api]);
|
||||
|
||||
@@ -66,15 +74,35 @@ export function DebugPage() {
|
||||
/>
|
||||
</motion.header>
|
||||
|
||||
{/* Tester / compose / activity stay MOUNTED and toggle via CSS so the
|
||||
live feed's SSE never drops (it must capture events fired from other
|
||||
tabs) and in-progress params/messages survive a peek at another tab.
|
||||
ApiBrowser has no state worth preserving and is heavy (~520 rows), so
|
||||
it mounts on demand. */}
|
||||
<div className={cn(tab !== 'tester' && 'hidden')}><ActionTester accounts={accounts} docs={docs} presetAction={preset} /></div>
|
||||
<div className={cn(tab !== 'compose' && 'hidden')}><MessageComposer accounts={accounts} /></div>
|
||||
<div className={cn(tab !== 'activity' && 'hidden')}><LiveActivity /></div>
|
||||
{tab === 'api' && <ApiBrowser docs={docs} onTry={tryAction} />}
|
||||
{loadError && (
|
||||
<div role="alert" className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
||||
{loadError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<SkeletonSwap
|
||||
ready={ready}
|
||||
reserve={224}
|
||||
lines={8}
|
||||
lineHeight={28}
|
||||
barHeight={11}
|
||||
label="开发者工具数据"
|
||||
className={ready ? 'skeleton-swap-fluid' : ''}
|
||||
>
|
||||
{ready ? (
|
||||
<>
|
||||
{/* Tester / compose / activity stay MOUNTED and toggle via CSS so the
|
||||
live feed's SSE never drops (it must capture events fired from other
|
||||
tabs) and in-progress params/messages survive a peek at another tab.
|
||||
ApiBrowser has no state worth preserving and is heavy (~520 rows), so
|
||||
it mounts on demand. */}
|
||||
<div className={cn(tab !== 'tester' && 'hidden')}><ActionTester accounts={accounts} docs={docs} presetAction={preset} /></div>
|
||||
<div className={cn(tab !== 'compose' && 'hidden')}><MessageComposer accounts={accounts} /></div>
|
||||
<div className={cn(tab !== 'activity' && 'hidden')}><LiveActivity /></div>
|
||||
{tab === 'api' && <ApiBrowser docs={docs} onTry={tryAction} />}
|
||||
</>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { Input } from '@/components/ui/input';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { LogEntry, LogLevel, LogsPreset, UiHighlightRule } from '@/types';
|
||||
import { useApi } from '@/lib/api';
|
||||
@@ -107,10 +108,14 @@ export function LogsPage() {
|
||||
const prefs = pages.logs;
|
||||
|
||||
const [logs, setLogs] = useState<LogEntry[]>([]);
|
||||
const [logsReady, setLogsReady] = useState(false);
|
||||
const [logsError, setLogsError] = useState<string | null>(null);
|
||||
const [streamStatus, setStreamStatus] = useState('连接中');
|
||||
const [filter, setFilter] = useState('');
|
||||
const [confirmClear, setConfirmClear] = useState(false);
|
||||
const [serverLevel, setServerLevel] = useState<LogLevel | null>(null);
|
||||
const [serverLevelReady, setServerLevelReady] = useState(false);
|
||||
const [serverLevelError, setServerLevelError] = useState<string | null>(null);
|
||||
const [levelBusy, setLevelBusy] = useState(false);
|
||||
const [confirmTrace, setConfirmTrace] = useState(false);
|
||||
const [traceExportBusy, setTraceExportBusy] = useState(false);
|
||||
@@ -133,23 +138,39 @@ export function LogsPage() {
|
||||
const enabled = useMemo(() => new Set(prefs.visibleLevels as LogLevel[]), [prefs.visibleLevels]);
|
||||
|
||||
const loadLogs = useCallback(async () => {
|
||||
setLogsError(null);
|
||||
try {
|
||||
// Backfill is capped at the server's ring-buffer size (1000); `maxLines`
|
||||
// can exceed that, but only the live SSE stream grows the view past 1000.
|
||||
setLogs(await api.logs.list(Math.min(1000, maxLinesRef.current)));
|
||||
} catch (e) {
|
||||
console.error('logs', e);
|
||||
setLogsError(e instanceof Error ? e.message : '加载日志失败');
|
||||
} finally {
|
||||
setLogsReady(true);
|
||||
}
|
||||
}, [api]);
|
||||
|
||||
useEffect(() => { void loadLogs(); }, [loadLogs]);
|
||||
|
||||
useEffect(() => {
|
||||
api.logs.getLevel().then(({ level }) => setServerLevel(level)).catch((err) => {
|
||||
console.error('getLevel', err);
|
||||
});
|
||||
const loadServerLevel = useCallback(async () => {
|
||||
setServerLevelReady(false);
|
||||
setServerLevelError(null);
|
||||
try {
|
||||
const { level } = await api.logs.getLevel();
|
||||
setServerLevel(level);
|
||||
} catch (error) {
|
||||
console.error('get server log level failed', error);
|
||||
setServerLevelError(error instanceof Error ? error.message : '加载服务端日志级别失败');
|
||||
} finally {
|
||||
setServerLevelReady(true);
|
||||
}
|
||||
}, [api]);
|
||||
|
||||
useEffect(() => {
|
||||
void loadServerLevel();
|
||||
}, [loadServerLevel]);
|
||||
|
||||
const applyServerLevel = useCallback(async (lv: LogLevel) => {
|
||||
if (lv === serverLevel || levelBusy) return;
|
||||
setLevelBusy(true);
|
||||
@@ -587,29 +608,50 @@ export function LogsPage() {
|
||||
<span className="text-xs font-medium text-foreground">服务端日志级别</span>
|
||||
<span className="text-xs text-muted-foreground">· 普通日志仅影响控制台 / 实时流;首次登录凭据始终可见;文件等级由环境变量决定,默认为 debug</span>
|
||||
</div>
|
||||
<div className="inline-flex flex-wrap gap-1 rounded-lg bg-muted/60 p-1">
|
||||
{LEVELS.map((lv) => {
|
||||
const active = serverLevel === lv;
|
||||
return (
|
||||
<button
|
||||
key={lv}
|
||||
type="button"
|
||||
onClick={() => void changeServerLevel(lv)}
|
||||
disabled={levelBusy || serverLevel === null}
|
||||
aria-pressed={active}
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-[background-color,color,box-shadow,opacity] duration-150 ease-out cursor-pointer disabled:cursor-not-allowed disabled:opacity-50',
|
||||
active
|
||||
? cn('bg-card shadow-sm ring-1 ring-border/60', levelClass[lv])
|
||||
: 'text-muted-foreground/70 hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
<span className={cn('size-1.5 rounded-full', active ? 'bg-current' : 'bg-muted-foreground/30')} />
|
||||
{lv.toUpperCase()}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<SkeletonSwap
|
||||
ready={serverLevelReady}
|
||||
reserve={34}
|
||||
lines={1}
|
||||
lineHeight={34}
|
||||
barHeight={8}
|
||||
label="服务端日志级别"
|
||||
className={serverLevelReady ? 'skeleton-swap-fluid min-h-[34px]' : 'w-72 max-w-full'}
|
||||
>
|
||||
{serverLevelReady ? (
|
||||
serverLevelError ? (
|
||||
<div role="alert" className="flex flex-wrap items-center gap-2 text-xs text-destructive">
|
||||
<span>{serverLevelError}</span>
|
||||
<Button variant="outline" size="sm" onClick={() => void loadServerLevel()}>
|
||||
重试
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="inline-flex flex-wrap gap-1 rounded-lg bg-muted/60 p-1">
|
||||
{LEVELS.map((lv) => {
|
||||
const active = serverLevel === lv;
|
||||
return (
|
||||
<button
|
||||
key={lv}
|
||||
type="button"
|
||||
onClick={() => void changeServerLevel(lv)}
|
||||
disabled={levelBusy || serverLevel === null}
|
||||
aria-pressed={active}
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-[background-color,color,box-shadow,opacity] duration-150 ease-out cursor-pointer disabled:cursor-not-allowed disabled:opacity-50',
|
||||
active
|
||||
? cn('bg-card shadow-sm ring-1 ring-border/60', levelClass[lv])
|
||||
: 'text-muted-foreground/70 hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
<span className={cn('size-1.5 rounded-full', active ? 'bg-current' : 'bg-muted-foreground/30')} />
|
||||
{lv.toUpperCase()}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
|
||||
{/* Highlight rules */}
|
||||
@@ -674,7 +716,7 @@ export function LogsPage() {
|
||||
<div className="flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-muted/20">
|
||||
{/* Column header lives OUTSIDE the scroll viewport so the virtualizer's
|
||||
scroll element contains only the rows (no sticky-offset math). */}
|
||||
{filtered.length > 0 && (
|
||||
{logsReady && filtered.length > 0 && (
|
||||
<div className="hidden items-center gap-3 border-b border-border/60 bg-card/60 px-3 py-2 font-mono text-micro font-medium uppercase tracking-wider text-muted-foreground/70 sm:flex">
|
||||
<span className="w-[104px] shrink-0">时间</span>
|
||||
<span className="w-[76px] shrink-0">级别</span>
|
||||
@@ -682,75 +724,100 @@ export function LogsPage() {
|
||||
<span className="flex-1">消息</span>
|
||||
</div>
|
||||
)}
|
||||
{logsReady && logsError && logs.length > 0 && (
|
||||
<div role="alert" className="border-b border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{logsError};当前显示已读取和实时接收的日志。
|
||||
</div>
|
||||
)}
|
||||
<ScrollArea viewportRef={scrollRef} className="min-h-0 flex-1" viewportClassName={cn('[&>div]:!block', maskCls)}>
|
||||
<div className="font-mono text-xs">
|
||||
{filtered.length === 0 ? (
|
||||
<div className="flex min-h-60 flex-col items-center justify-center gap-3 px-4 py-10 text-center font-sans text-muted-foreground">
|
||||
{logs.length === 0 ? (
|
||||
<>
|
||||
<Inbox className="size-9 opacity-30" />
|
||||
<span className="text-sm">暂无日志</span>
|
||||
</>
|
||||
<SkeletonSwap
|
||||
ready={logsReady}
|
||||
reserve={240}
|
||||
lines={8}
|
||||
lineHeight={30}
|
||||
barHeight={10}
|
||||
label="运行日志"
|
||||
className={logsReady ? 'skeleton-swap-fluid min-h-60' : ''}
|
||||
>
|
||||
{logsReady ? (
|
||||
<div className="font-mono text-xs">
|
||||
{logsError && logs.length === 0 ? (
|
||||
<div role="alert" className="flex min-h-60 flex-col items-center justify-center gap-3 px-4 py-10 text-center font-sans text-destructive">
|
||||
<TriangleAlert className="size-9 opacity-70" />
|
||||
<span className="text-sm">{logsError}</span>
|
||||
<Button variant="outline" size="sm" onClick={() => void loadLogs()} className="rounded-lg">
|
||||
<RefreshCw className="size-3.5" /> 重试
|
||||
</Button>
|
||||
</div>
|
||||
) : filtered.length === 0 ? (
|
||||
<div className="flex min-h-60 flex-col items-center justify-center gap-3 px-4 py-10 text-center font-sans text-muted-foreground">
|
||||
{logs.length === 0 ? (
|
||||
<>
|
||||
<Inbox className="size-9 opacity-30" />
|
||||
<span className="text-sm">暂无日志</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<SearchX className="size-9 opacity-30" />
|
||||
<span className="text-sm">没有符合筛选条件的日志</span>
|
||||
<Button variant="outline" size="sm" onClick={clearFilters} className="rounded-lg">清除筛选</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<SearchX className="size-9 opacity-30" />
|
||||
<span className="text-sm">没有符合筛选条件的日志</span>
|
||||
<Button variant="outline" size="sm" onClick={clearFilters} className="rounded-lg">清除筛选</Button>
|
||||
</>
|
||||
<div className="relative w-full" style={{ height: rowVirtualizer.getTotalSize() }}>
|
||||
{rowVirtualizer.getVirtualItems().map((vRow) => {
|
||||
const log = filtered[vRow.index];
|
||||
if (!log) return null; // guard a transient count/measurement skew
|
||||
const hl = matchHighlight(log.message, prefs.highlightRules);
|
||||
// Entrance is decided entirely by animatingRef (populated in
|
||||
// the flush from real arrivals, pruned at 260ms), so it fires
|
||||
// on the first paint, never replays on scroll-into-view, and
|
||||
// is immune to filter/idle churn. Outer = positioning +
|
||||
// measurement (its translateY); inner = visual row + the
|
||||
// transform-based entrance, kept separate so they never collide.
|
||||
const entering = animatingRef.current.has(log.id);
|
||||
return (
|
||||
<div
|
||||
key={log.id}
|
||||
data-index={vRow.index}
|
||||
ref={rowVirtualizer.measureElement}
|
||||
className="absolute left-0 top-0 w-full"
|
||||
style={{ transform: `translateY(${vRow.start}px)` }}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'flex flex-col gap-0.5 border-b border-border/30 px-3 py-1.5 transition-colors hover:bg-accent/40 sm:flex-row sm:items-start sm:gap-3 sm:py-1',
|
||||
entering && 'log-row-in',
|
||||
)}
|
||||
style={hl ? { boxShadow: `inset 3px 0 0 ${hl}`, backgroundColor: `color-mix(in oklab, ${hl} 8%, transparent)` } : undefined}
|
||||
>
|
||||
<div className="flex items-center gap-3 sm:contents">
|
||||
<span className="w-[104px] shrink-0 tabular-nums text-muted-foreground">{formatClock(log.time)}</span>
|
||||
<span className={cn('flex w-[76px] shrink-0 items-center gap-1.5 font-semibold', levelClass[log.level])}>
|
||||
<span className="size-1.5 shrink-0 rounded-full bg-current" />
|
||||
{log.level.toUpperCase()}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-muted-foreground sm:w-28 sm:flex-none sm:shrink-0">[{log.scope}]</span>
|
||||
</div>
|
||||
<span
|
||||
className={cn('min-w-0 flex-1 leading-5', prefs.wrap ? 'whitespace-pre-wrap break-all' : 'truncate')}
|
||||
title={prefs.wrap ? undefined : log.message}
|
||||
>
|
||||
{log.req !== undefined && (
|
||||
<span className="mr-1.5 rounded bg-primary/10 px-1 text-micro text-primary tabular-nums" title="请求关联号">#{log.req}</span>
|
||||
)}
|
||||
{log.message}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="relative w-full" style={{ height: rowVirtualizer.getTotalSize() }}>
|
||||
{rowVirtualizer.getVirtualItems().map((vRow) => {
|
||||
const log = filtered[vRow.index];
|
||||
if (!log) return null; // guard a transient count/measurement skew
|
||||
const hl = matchHighlight(log.message, prefs.highlightRules);
|
||||
// Entrance is decided entirely by animatingRef (populated in
|
||||
// the flush from real arrivals, pruned at 260ms), so it fires
|
||||
// on the first paint, never replays on scroll-into-view, and
|
||||
// is immune to filter/idle churn. Outer = positioning +
|
||||
// measurement (its translateY); inner = visual row + the
|
||||
// transform-based entrance, kept separate so they never collide.
|
||||
const entering = animatingRef.current.has(log.id);
|
||||
return (
|
||||
<div
|
||||
key={log.id}
|
||||
data-index={vRow.index}
|
||||
ref={rowVirtualizer.measureElement}
|
||||
className="absolute left-0 top-0 w-full"
|
||||
style={{ transform: `translateY(${vRow.start}px)` }}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'flex flex-col gap-0.5 border-b border-border/30 px-3 py-1.5 transition-colors hover:bg-accent/40 sm:flex-row sm:items-start sm:gap-3 sm:py-1',
|
||||
entering && 'log-row-in',
|
||||
)}
|
||||
style={hl ? { boxShadow: `inset 3px 0 0 ${hl}`, backgroundColor: `color-mix(in oklab, ${hl} 8%, transparent)` } : undefined}
|
||||
>
|
||||
<div className="flex items-center gap-3 sm:contents">
|
||||
<span className="w-[104px] shrink-0 tabular-nums text-muted-foreground">{formatClock(log.time)}</span>
|
||||
<span className={cn('flex w-[76px] shrink-0 items-center gap-1.5 font-semibold', levelClass[log.level])}>
|
||||
<span className="size-1.5 shrink-0 rounded-full bg-current" />
|
||||
{log.level.toUpperCase()}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-muted-foreground sm:w-28 sm:flex-none sm:shrink-0">[{log.scope}]</span>
|
||||
</div>
|
||||
<span
|
||||
className={cn('min-w-0 flex-1 leading-5', prefs.wrap ? 'whitespace-pre-wrap break-all' : 'truncate')}
|
||||
title={prefs.wrap ? undefined : log.message}
|
||||
>
|
||||
{log.req !== undefined && (
|
||||
<span className="mr-1.5 rounded bg-primary/10 px-1 text-micro text-primary tabular-nums" title="请求关联号">#{log.req}</span>
|
||||
)}
|
||||
{log.message}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
</CardContent>
|
||||
|
||||
@@ -12,7 +12,7 @@ import { Progress } from '@/components/ui/progress';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn, formatBytes, formatUptime } from '@/lib/utils';
|
||||
import type { AppPath } from '@/router';
|
||||
import type {
|
||||
@@ -64,7 +64,7 @@ function renderWidget(block: UiLayoutItem): ReactNode {
|
||||
}
|
||||
|
||||
export function OverviewPage() {
|
||||
const { qqList, processList } = useAppState();
|
||||
const { qqList, processList, resources } = useAppState();
|
||||
const {
|
||||
overviewBlocks, setOverviewBlocks, overviewMobile, setOverviewMobile,
|
||||
resetLayout, editing, setEditing,
|
||||
@@ -153,7 +153,7 @@ export function OverviewPage() {
|
||||
)}
|
||||
|
||||
{/* First-run nudge — always shown (not a grid widget) so it can't be hidden. */}
|
||||
{qqList.length === 0 && (
|
||||
{resources.qqList.ready && !resources.qqList.error && qqList.length === 0 && (
|
||||
<motion.div initial={off ? false : { opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }}>
|
||||
<Link
|
||||
to="/processes"
|
||||
@@ -475,7 +475,7 @@ function shortDistro(distro: string): string {
|
||||
}
|
||||
|
||||
function StatTile({
|
||||
icon, label, value, subtext, details, accent = false, to,
|
||||
icon, label, value, subtext, details, accent = false, to, ready = true,
|
||||
}: {
|
||||
icon: ReactNode;
|
||||
label: string;
|
||||
@@ -484,6 +484,7 @@ function StatTile({
|
||||
details?: string;
|
||||
accent?: boolean;
|
||||
to?: AppPath;
|
||||
ready?: boolean;
|
||||
}) {
|
||||
const copy = (
|
||||
<>
|
||||
@@ -502,10 +503,32 @@ function StatTile({
|
||||
>
|
||||
{icon}
|
||||
</div>
|
||||
{details ? (
|
||||
<StatTileDetails label={label} details={details}>{copy}</StatTileDetails>
|
||||
{details && ready ? (
|
||||
<StatTileDetails label={label} details={details}>
|
||||
<SkeletonSwap
|
||||
ready={ready}
|
||||
reserve={52}
|
||||
lines={3}
|
||||
lineHeight={17}
|
||||
barHeight={8}
|
||||
label={label}
|
||||
className="skeleton-swap-fluid"
|
||||
>
|
||||
{copy}
|
||||
</SkeletonSwap>
|
||||
</StatTileDetails>
|
||||
) : (
|
||||
<div className="min-w-0 flex-1">{copy}</div>
|
||||
<SkeletonSwap
|
||||
ready={ready}
|
||||
reserve={52}
|
||||
lines={3}
|
||||
lineHeight={17}
|
||||
barHeight={8}
|
||||
label={label}
|
||||
className={ready ? 'skeleton-swap-fluid min-w-0 flex-1' : 'min-w-0 flex-1'}
|
||||
>
|
||||
{ready ? copy : null}
|
||||
</SkeletonSwap>
|
||||
)}
|
||||
{to && <ArrowRight className="optical-forward size-4 shrink-0 text-muted-foreground/60" />}
|
||||
</CardContent>
|
||||
@@ -521,7 +544,7 @@ function StatTile({
|
||||
}
|
||||
|
||||
function StatTileWidget({ id }: { id: string }) {
|
||||
const { qqList, processList, systemInfo } = useAppState();
|
||||
const { qqList, processList, systemInfo, resources } = useAppState();
|
||||
const { status } = useSession();
|
||||
const online = status === '已连接';
|
||||
|
||||
@@ -541,8 +564,11 @@ function StatTileWidget({ id }: { id: string }) {
|
||||
<StatTile
|
||||
icon={<Users className="size-5" />}
|
||||
label="在线账号"
|
||||
value={qqList.length}
|
||||
subtext={`已接入 ${qqList.length} 个会话`}
|
||||
ready={resources.qqList.ready}
|
||||
value={resources.qqList.error && qqList.length === 0 ? '—' : qqList.length}
|
||||
subtext={resources.qqList.error
|
||||
? qqList.length > 0 ? '更新失败,显示上次数据' : '加载失败'
|
||||
: `已接入 ${qqList.length} 个会话`}
|
||||
/>
|
||||
);
|
||||
case 'stat:processes': {
|
||||
@@ -552,19 +578,25 @@ function StatTileWidget({ id }: { id: string }) {
|
||||
<StatTile
|
||||
icon={<PlugZap className="size-5" />}
|
||||
label="进程注入"
|
||||
value={`${onlineProcs} 在线`}
|
||||
subtext={`${processList.length} 进程 · ${loadableProcs} 可注入`}
|
||||
ready={resources.processList.ready}
|
||||
value={resources.processList.error && processList.length === 0 ? '—' : `${onlineProcs} 在线`}
|
||||
subtext={resources.processList.error
|
||||
? processList.length > 0 ? '更新失败,显示上次数据' : '加载失败'
|
||||
: `${processList.length} 进程 · ${loadableProcs} 可注入`}
|
||||
to="/processes"
|
||||
/>
|
||||
);
|
||||
}
|
||||
case 'stat:host': {
|
||||
const value = systemInfo?.hostname ?? '—';
|
||||
const subtext = systemInfo ? `${shortDistro(systemInfo.distro)} · ${systemInfo.archLabel}` : '加载中';
|
||||
const subtext = systemInfo
|
||||
? `${shortDistro(systemInfo.distro)} · ${systemInfo.archLabel}`
|
||||
: resources.systemInfo.error ? '加载失败' : '加载中';
|
||||
return (
|
||||
<StatTile
|
||||
icon={<Server className="size-5" />}
|
||||
label="主机名"
|
||||
ready={resources.systemInfo.ready}
|
||||
value={value}
|
||||
subtext={subtext}
|
||||
details={systemInfo
|
||||
@@ -580,6 +612,7 @@ function StatTileWidget({ id }: { id: string }) {
|
||||
<StatTile
|
||||
icon={<MonitorCog className="size-5" />}
|
||||
label="系统运行"
|
||||
ready={resources.systemInfo.ready}
|
||||
value={systemUptime}
|
||||
subtext={processUptime ? `进程 ${processUptime}` : undefined}
|
||||
details={processUptime
|
||||
@@ -598,7 +631,7 @@ function StatTileWidget({ id }: { id: string }) {
|
||||
const HOST_GRID_COLS: Record<number, string> = { 1: 'lg:grid-cols-1', 2: 'lg:grid-cols-2', 3: 'lg:grid-cols-3' };
|
||||
|
||||
function HostBlock({ config }: { config: HostConfig }) {
|
||||
const { systemInfo, refreshSystem } = useAppState();
|
||||
const { systemInfo, refreshSystem, resources } = useAppState();
|
||||
const panelCount = [config.cpu, config.memory, config.runtime].filter(Boolean).length;
|
||||
return (
|
||||
<Card className="flex h-full flex-col">
|
||||
@@ -607,8 +640,10 @@ function HostBlock({ config }: { config: HostConfig }) {
|
||||
<CardTitle>主机资源</CardTitle>
|
||||
<CardDescription>
|
||||
{systemInfo
|
||||
? `${systemInfo.cpu.model.trim()} · ${systemInfo.cpu.cores} 核 · Node ${systemInfo.nodeVersion}`
|
||||
: '正在采集主机信息…'}
|
||||
? `${systemInfo.cpu.model.trim()} · ${systemInfo.cpu.cores} 核 · Node ${systemInfo.nodeVersion}${
|
||||
resources.systemInfo.error ? ' · 更新失败,显示上次数据' : ''
|
||||
}`
|
||||
: resources.systemInfo.error ?? '正在采集主机信息…'}
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onClick={refreshSystem}>
|
||||
@@ -631,34 +666,50 @@ function HostBlock({ config }: { config: HostConfig }) {
|
||||
{systemInfo ? `${systemInfo.cpu.average.toFixed(1)}%` : '—'}
|
||||
</span>
|
||||
</div>
|
||||
<Progress value={systemInfo?.cpu.average ?? 0} />
|
||||
<p className="mt-2 text-meta text-muted-foreground tabular-nums">
|
||||
负载: {systemInfo ? systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ') : '—'}
|
||||
</p>
|
||||
{systemInfo && systemInfo.cpu.perCore.length > 0 && (
|
||||
<div
|
||||
className="mt-3 grid"
|
||||
style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(34px, 1fr))', gap: 3 }}
|
||||
>
|
||||
{systemInfo.cpu.perCore.map((p, i) => (
|
||||
<div
|
||||
key={i}
|
||||
title={`Core ${i}: ${p.toFixed(1)}%`}
|
||||
className="grid aspect-square place-items-center rounded-md transition-[background] duration-500 ease-[cubic-bezier(0.16,1,0.3,1)]"
|
||||
style={{
|
||||
background: `color-mix(in oklab, var(--primary) ${Math.min(100, Math.max(0, p)).toFixed(1)}%, color-mix(in oklab, var(--muted) 80%, transparent))`,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="text-micro leading-none tabular-nums"
|
||||
style={{ color: 'color-mix(in oklab, var(--foreground) 55%, transparent)' }}
|
||||
<SkeletonSwap
|
||||
ready={resources.systemInfo.ready}
|
||||
reserve={112}
|
||||
lines={4}
|
||||
lineHeight={28}
|
||||
barHeight={9}
|
||||
label="CPU 使用率"
|
||||
className="skeleton-swap-fluid min-h-[112px]"
|
||||
>
|
||||
{systemInfo ? (
|
||||
<>
|
||||
<Progress value={systemInfo.cpu.average} />
|
||||
<p className="mt-2 text-meta text-muted-foreground tabular-nums">
|
||||
负载: {systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ')}
|
||||
</p>
|
||||
{systemInfo.cpu.perCore.length > 0 && (
|
||||
<div
|
||||
className="mt-3 grid"
|
||||
style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(34px, 1fr))', gap: 3 }}
|
||||
>
|
||||
{i}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{systemInfo.cpu.perCore.map((p, i) => (
|
||||
<div
|
||||
key={i}
|
||||
title={`Core ${i}: ${p.toFixed(1)}%`}
|
||||
className="grid aspect-square place-items-center rounded-md transition-[background] duration-500 ease-[cubic-bezier(0.16,1,0.3,1)]"
|
||||
style={{
|
||||
background: `color-mix(in oklab, var(--primary) ${Math.min(100, Math.max(0, p)).toFixed(1)}%, color-mix(in oklab, var(--muted) 80%, transparent))`,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="text-micro leading-none tabular-nums"
|
||||
style={{ color: 'color-mix(in oklab, var(--foreground) 55%, transparent)' }}
|
||||
>
|
||||
{i}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : resources.systemInfo.error ? (
|
||||
<p role="alert" className="text-xs text-destructive">{resources.systemInfo.error}</p>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
)}
|
||||
{/* Memory */}
|
||||
@@ -673,39 +724,51 @@ function HostBlock({ config }: { config: HostConfig }) {
|
||||
{systemInfo ? `${systemInfo.memory.usagePercent.toFixed(1)}%` : '—'}
|
||||
</span>
|
||||
</div>
|
||||
{systemInfo ? (() => {
|
||||
const m = systemInfo.memory;
|
||||
const rss = Math.min(systemInfo.runtime.rss, m.used);
|
||||
const other = Math.max(0, m.used - rss);
|
||||
const segs = [
|
||||
{ key: 'proc', label: '本进程', bytes: rss, grow: (rss / m.total) * 100, color: 'var(--primary)' },
|
||||
{ key: 'other', label: '其他已用', bytes: other, grow: (other / m.total) * 100, color: 'color-mix(in oklab, var(--primary) 45%, transparent)' },
|
||||
{ key: 'free', label: '空闲', bytes: m.free, grow: (m.free / m.total) * 100, color: 'color-mix(in oklab, var(--muted) 85%, transparent)' },
|
||||
];
|
||||
return (
|
||||
<>
|
||||
<div className="mt-1.5 flex h-3 gap-0.5">
|
||||
{segs.map((seg) => (
|
||||
<span
|
||||
key={seg.key}
|
||||
className="rounded-[3px]"
|
||||
style={{ flexGrow: seg.grow, minWidth: 2, background: seg.color }}
|
||||
title={`${seg.label} ${formatBytes(seg.bytes)}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-3 flex flex-wrap gap-x-3.5 gap-y-1 text-meta text-muted-foreground">
|
||||
{segs.map((seg) => (
|
||||
<span key={seg.key} className="inline-flex items-center gap-1.5">
|
||||
<i className="size-2 rounded-[2px]" style={{ background: seg.color }} />
|
||||
{seg.label}
|
||||
<b className="font-semibold text-foreground tabular-nums">{formatBytes(seg.bytes)}</b>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
})() : <Progress value={0} />}
|
||||
<SkeletonSwap
|
||||
ready={resources.systemInfo.ready}
|
||||
reserve={72}
|
||||
lines={3}
|
||||
lineHeight={24}
|
||||
barHeight={9}
|
||||
label="内存使用"
|
||||
className="skeleton-swap-fluid min-h-[72px]"
|
||||
>
|
||||
{systemInfo ? (() => {
|
||||
const m = systemInfo.memory;
|
||||
const rss = Math.min(systemInfo.runtime.rss, m.used);
|
||||
const other = Math.max(0, m.used - rss);
|
||||
const segs = [
|
||||
{ key: 'proc', label: '本进程', bytes: rss, grow: (rss / m.total) * 100, color: 'var(--primary)' },
|
||||
{ key: 'other', label: '其他已用', bytes: other, grow: (other / m.total) * 100, color: 'color-mix(in oklab, var(--primary) 45%, transparent)' },
|
||||
{ key: 'free', label: '空闲', bytes: m.free, grow: (m.free / m.total) * 100, color: 'color-mix(in oklab, var(--muted) 85%, transparent)' },
|
||||
];
|
||||
return (
|
||||
<>
|
||||
<div className="mt-1.5 flex h-3 gap-0.5">
|
||||
{segs.map((seg) => (
|
||||
<span
|
||||
key={seg.key}
|
||||
className="rounded-[3px]"
|
||||
style={{ flexGrow: seg.grow, minWidth: 2, background: seg.color }}
|
||||
title={`${seg.label} ${formatBytes(seg.bytes)}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-3 flex flex-wrap gap-x-3.5 gap-y-1 text-meta text-muted-foreground">
|
||||
{segs.map((seg) => (
|
||||
<span key={seg.key} className="inline-flex items-center gap-1.5">
|
||||
<i className="size-2 rounded-[2px]" style={{ background: seg.color }} />
|
||||
{seg.label}
|
||||
<b className="font-semibold text-foreground tabular-nums">{formatBytes(seg.bytes)}</b>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
})() : resources.systemInfo.error ? (
|
||||
<p role="alert" className="text-xs text-destructive">{resources.systemInfo.error}</p>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
)}
|
||||
{/* Runtime */}
|
||||
@@ -720,29 +783,36 @@ function HostBlock({ config }: { config: HostConfig }) {
|
||||
{systemInfo ? `PID ${systemInfo.runtime.pid}` : '—'}
|
||||
</span>
|
||||
</div>
|
||||
{!systemInfo ? (
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-3/4" />
|
||||
<Skeleton className="h-4 w-1/2" />
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-1.5 text-xs">
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">RSS</span>
|
||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.rss)}</span>
|
||||
<SkeletonSwap
|
||||
ready={resources.systemInfo.ready}
|
||||
reserve={88}
|
||||
lines={3}
|
||||
lineHeight={29}
|
||||
barHeight={9}
|
||||
label="运行进程"
|
||||
className={resources.systemInfo.ready ? 'skeleton-swap-fluid min-h-[88px]' : ''}
|
||||
>
|
||||
{systemInfo ? (
|
||||
<div className="space-y-1.5 text-xs">
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">RSS</span>
|
||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.rss)}</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">堆内存</span>
|
||||
<span className="font-medium tabular-nums">
|
||||
{formatBytes(systemInfo.runtime.heapUsed)} / {formatBytes(systemInfo.runtime.heapTotal)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">外部内存</span>
|
||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.external)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">堆内存</span>
|
||||
<span className="font-medium tabular-nums">
|
||||
{formatBytes(systemInfo.runtime.heapUsed)} / {formatBytes(systemInfo.runtime.heapTotal)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||
<span className="text-muted-foreground">外部内存</span>
|
||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.external)}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
) : resources.systemInfo.error ? (
|
||||
<p role="alert" className="text-xs text-destructive">{resources.systemInfo.error}</p>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
@@ -753,7 +823,7 @@ function HostBlock({ config }: { config: HostConfig }) {
|
||||
// ─────────────── online sessions ───────────────
|
||||
|
||||
function SessionsBlock({ config }: { config: SessionsConfig }) {
|
||||
const { qqList } = useAppState();
|
||||
const { qqList, resources } = useAppState();
|
||||
const off = useTheme().appearance.disableMotion;
|
||||
const list = useMemo(() => {
|
||||
const f = config.filter.trim().toLowerCase();
|
||||
@@ -775,37 +845,60 @@ function SessionsBlock({ config }: { config: SessionsConfig }) {
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="min-h-0 flex-1">
|
||||
{list.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Users className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">{qqList.length === 0 ? '暂无在线会话' : '无匹配的会话'}</p>
|
||||
</div>
|
||||
) : (
|
||||
<ScrollArea className="h-full" viewportClassName="[&>div]:!block">
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
||||
{list.map((q, idx) => (
|
||||
<motion.div
|
||||
key={q.uin}
|
||||
initial={off ? false : { opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={off ? { duration: 0 } : { delay: 0.03 + idx * 0.04, duration: 0.22 }}
|
||||
whileHover={off ? undefined : { y: -2 }}
|
||||
className="flex items-center gap-3 rounded-xl border bg-card/40 p-3"
|
||||
>
|
||||
<Avatar size={40}>
|
||||
<AvatarImage src={qqAvatarUrl(q.uin)} alt={q.nickname || q.uin} />
|
||||
<AvatarFallback>{(q.nickname || q.uin).slice(0, 2)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm font-semibold">{q.nickname}</div>
|
||||
<div className="truncate font-mono text-meta text-muted-foreground tabular-nums">{q.uin}</div>
|
||||
<SkeletonSwap
|
||||
ready={resources.qqList.ready}
|
||||
reserve={120}
|
||||
lines={5}
|
||||
lineHeight={24}
|
||||
barHeight={9}
|
||||
label="在线会话"
|
||||
className={resources.qqList.ready ? 'skeleton-swap-fluid min-h-[120px]' : ''}
|
||||
>
|
||||
{resources.qqList.ready ? (
|
||||
resources.qqList.error && qqList.length === 0 ? (
|
||||
<p role="alert" className="rounded-xl border border-destructive/30 bg-destructive/10 px-3 py-8 text-center text-sm text-destructive">
|
||||
{resources.qqList.error}
|
||||
</p>
|
||||
) : list.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Users className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">{qqList.length === 0 ? '暂无在线会话' : '无匹配的会话'}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{resources.qqList.error && (
|
||||
<p role="alert" className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{resources.qqList.error};当前显示上次成功读取的在线会话。
|
||||
</p>
|
||||
)}
|
||||
<ScrollArea className="h-full" viewportClassName="[&>div]:!block">
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
||||
{list.map((q, idx) => (
|
||||
<motion.div
|
||||
key={q.uin}
|
||||
initial={off ? false : { opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={off ? { duration: 0 } : { delay: 0.03 + idx * 0.04, duration: 0.22 }}
|
||||
whileHover={off ? undefined : { y: -2 }}
|
||||
className="flex items-center gap-3 rounded-xl border bg-card/40 p-3"
|
||||
>
|
||||
<Avatar size={40}>
|
||||
<AvatarImage src={qqAvatarUrl(q.uin)} alt={q.nickname || q.uin} />
|
||||
<AvatarFallback>{(q.nickname || q.uin).slice(0, 2)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm font-semibold">{q.nickname}</div>
|
||||
<div className="truncate font-mono text-meta text-muted-foreground tabular-nums">{q.uin}</div>
|
||||
</div>
|
||||
<span className="size-2 shrink-0 animate-pulse rounded-full bg-success shadow-[0_0_8px_color-mix(in_oklab,var(--success)_60%,transparent)]" />
|
||||
</motion.div>
|
||||
))}
|
||||
</div>
|
||||
<span className="size-2 shrink-0 animate-pulse rounded-full bg-success shadow-[0_0_8px_color-mix(in_oklab,var(--success)_60%,transparent)]" />
|
||||
</motion.div>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
)}
|
||||
</ScrollArea>
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
@@ -837,7 +930,7 @@ const CONN_STATUS_RANK: Record<AdapterStatusLevel, number> = {
|
||||
};
|
||||
|
||||
function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
||||
const { connections } = useAppState();
|
||||
const { connections, resources } = useAppState();
|
||||
const list = useMemo(() => {
|
||||
const f = config.filter.trim().toLowerCase();
|
||||
// Optionally drop healthy adapters, then accounts left with none.
|
||||
@@ -869,51 +962,72 @@ function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="min-h-0 flex-1 overflow-auto">
|
||||
{list.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Cable className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">{filtered ? '无匹配的连接' : '暂无已接入的账号实例'}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-4">
|
||||
{list.map((acc) => (
|
||||
<div key={acc.uin} className="flex flex-col gap-2">
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-sm font-semibold">{acc.nickname || acc.uin}</span>
|
||||
<span className="font-mono text-meta text-muted-foreground tabular-nums">{acc.uin}</span>
|
||||
</div>
|
||||
{acc.databaseMigration && acc.databaseMigration.phase !== 'complete' && (
|
||||
<DatabaseMigrationProgress migration={acc.databaseMigration} />
|
||||
)}
|
||||
{acc.adapters.length > 0 ? (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
{acc.adapters.map((adp) => (
|
||||
<div key={adp.name} className="flex items-center gap-2 rounded-xl border bg-card/40 px-3 py-2">
|
||||
<span className={cn('shrink-0 rounded px-1.5 py-0.5 text-micro font-medium', CONN_STATUS_STYLE[adp.status])}>
|
||||
{CONN_STATUS_LABEL[adp.status]}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="truncate text-sm font-medium">{adp.name}</span>
|
||||
<span className="shrink-0 text-micro text-muted-foreground">{ADAPTER_KIND_LABEL[adp.kind]}</span>
|
||||
</div>
|
||||
<div className="truncate text-meta text-muted-foreground">{adp.detail}</div>
|
||||
{adp.lastError && adp.lastErrorAt && (
|
||||
<div className="truncate text-xs text-destructive/80">
|
||||
{new Date(adp.lastErrorAt).toLocaleString()} · {adp.lastError}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : acc.databaseMigration?.usable !== false ? (
|
||||
<p className="rounded-md border border-dashed px-3 py-2 text-xs text-muted-foreground">未配置任何协议端点</p>
|
||||
) : null}
|
||||
<SkeletonSwap
|
||||
ready={resources.connections.ready}
|
||||
reserve={120}
|
||||
lines={5}
|
||||
lineHeight={24}
|
||||
barHeight={9}
|
||||
label="OneBot 连接"
|
||||
className={resources.connections.ready ? 'skeleton-swap-fluid min-h-[120px]' : ''}
|
||||
>
|
||||
{resources.connections.ready ? (
|
||||
resources.connections.error && connections.length === 0 ? (
|
||||
<p role="alert" className="rounded-xl border border-destructive/30 bg-destructive/10 px-3 py-8 text-center text-sm text-destructive">
|
||||
{resources.connections.error}
|
||||
</p>
|
||||
) : list.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Cable className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">{filtered ? '无匹配的连接' : '暂无已接入的账号实例'}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
) : (
|
||||
<div className="flex flex-col gap-4">
|
||||
{resources.connections.error && (
|
||||
<p role="alert" className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{resources.connections.error};当前显示上次成功读取的连接状态。
|
||||
</p>
|
||||
)}
|
||||
{list.map((acc) => (
|
||||
<div key={acc.uin} className="flex flex-col gap-2">
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-sm font-semibold">{acc.nickname || acc.uin}</span>
|
||||
<span className="font-mono text-meta text-muted-foreground tabular-nums">{acc.uin}</span>
|
||||
</div>
|
||||
{acc.databaseMigration && acc.databaseMigration.phase !== 'complete' && (
|
||||
<DatabaseMigrationProgress migration={acc.databaseMigration} />
|
||||
)}
|
||||
{acc.adapters.length > 0 ? (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
{acc.adapters.map((adp) => (
|
||||
<div key={adp.name} className="flex items-center gap-2 rounded-xl border bg-card/40 px-3 py-2">
|
||||
<span className={cn('shrink-0 rounded px-1.5 py-0.5 text-micro font-medium', CONN_STATUS_STYLE[adp.status])}>
|
||||
{CONN_STATUS_LABEL[adp.status]}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="truncate text-sm font-medium">{adp.name}</span>
|
||||
<span className="shrink-0 text-micro text-muted-foreground">{ADAPTER_KIND_LABEL[adp.kind]}</span>
|
||||
</div>
|
||||
<div className="truncate text-meta text-muted-foreground">{adp.detail}</div>
|
||||
{adp.lastError && adp.lastErrorAt && (
|
||||
<div className="truncate text-xs text-destructive/80">
|
||||
{new Date(adp.lastErrorAt).toLocaleString()} · {adp.lastError}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : acc.databaseMigration?.usable !== false ? (
|
||||
<p className="rounded-md border border-dashed px-3 py-2 text-xs text-muted-foreground">未配置任何协议端点</p>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
@@ -1013,7 +1127,7 @@ function LinkWidget({ config }: { config: LinkConfig }) {
|
||||
}
|
||||
|
||||
function AccountWidget({ config }: { config: AccountConfig }) {
|
||||
const { qqList } = useAppState();
|
||||
const { qqList, resources } = useAppState();
|
||||
const acct = qqList.find((q) => q.uin === config.uin);
|
||||
if (!config.uin) {
|
||||
return (
|
||||
@@ -1027,20 +1141,34 @@ function AccountWidget({ config }: { config: AccountConfig }) {
|
||||
}
|
||||
return (
|
||||
<Card className="h-full overflow-hidden">
|
||||
<CardContent className="flex h-full items-center gap-3 p-4">
|
||||
<Avatar size={40}>
|
||||
<AvatarImage src={qqAvatarUrl(config.uin)} alt={acct?.nickname || config.uin} />
|
||||
<AvatarFallback>{(acct?.nickname || config.uin).slice(0, 2)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-semibold">{acct?.nickname || '未接入账号'}</p>
|
||||
<p className="truncate font-mono text-meta text-muted-foreground tabular-nums">{config.uin}</p>
|
||||
</div>
|
||||
<span
|
||||
title={acct ? '在线' : '未接入'}
|
||||
className={cn('size-2 shrink-0 rounded-full', acct ? 'bg-success' : 'bg-muted-foreground/40')}
|
||||
/>
|
||||
</CardContent>
|
||||
<SkeletonSwap
|
||||
ready={resources.qqList.ready}
|
||||
reserve={72}
|
||||
lines={3}
|
||||
lineHeight={24}
|
||||
barHeight={9}
|
||||
label="账号状态"
|
||||
className="skeleton-swap-fill"
|
||||
>
|
||||
{resources.qqList.ready ? (
|
||||
<CardContent className="flex h-full items-center gap-3 p-4">
|
||||
<Avatar size={40}>
|
||||
<AvatarImage src={qqAvatarUrl(config.uin)} alt={acct?.nickname || config.uin} />
|
||||
<AvatarFallback>{(acct?.nickname || config.uin).slice(0, 2)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-semibold">
|
||||
{resources.qqList.error ? '账号状态加载失败' : acct?.nickname || '未接入账号'}
|
||||
</p>
|
||||
<p className="truncate font-mono text-meta text-muted-foreground tabular-nums">{config.uin}</p>
|
||||
</div>
|
||||
<span
|
||||
title={acct ? '在线' : resources.qqList.error ? '状态未知' : '未接入'}
|
||||
className={cn('size-2 shrink-0 rounded-full', acct ? 'bg-success' : 'bg-muted-foreground/40')}
|
||||
/>
|
||||
</CardContent>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1062,24 +1190,32 @@ const ALERT_LEVEL_CLASS: Record<LogLevel, string> = {
|
||||
function RecentAlertsCard({ config }: { config: AlertsConfig }) {
|
||||
const api = useApi();
|
||||
const { formatClock } = useTheme();
|
||||
const [alerts, setAlerts] = useState<LogEntry[]>([]);
|
||||
const [alerts, setAlerts] = useState<LogEntry[] | null>(null);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
const { count } = config;
|
||||
const levelsKey = config.levels.join(',');
|
||||
|
||||
useEffect(() => {
|
||||
const levels = new Set(levelsKey.split(',') as LogLevel[]);
|
||||
let active = true;
|
||||
setAlerts(null);
|
||||
setLoadError(null);
|
||||
api.logs
|
||||
.list(Math.max(200, count * 4))
|
||||
.then((list) => {
|
||||
if (!active) return;
|
||||
setAlerts(list.filter((l) => levels.has(l.level)).slice(-count));
|
||||
})
|
||||
.catch(() => { /* ignore */ });
|
||||
.catch((error) => {
|
||||
if (!active) return;
|
||||
console.error('load recent alerts failed', error);
|
||||
setLoadError(error instanceof Error ? error.message : '加载最近告警失败');
|
||||
setAlerts((previous) => previous ?? []);
|
||||
});
|
||||
const stop = api.logs.stream({
|
||||
onLine: (entry) => {
|
||||
if (!levels.has(entry.level)) return;
|
||||
setAlerts((prev) => [...prev.filter((a) => a.id !== entry.id), entry].slice(-count));
|
||||
setAlerts((prev) => [...(prev ?? []).filter((a) => a.id !== entry.id), entry].slice(-count));
|
||||
},
|
||||
});
|
||||
return () => { active = false; stop(); };
|
||||
@@ -1099,24 +1235,45 @@ function RecentAlertsCard({ config }: { config: AlertsConfig }) {
|
||||
</Link>
|
||||
</CardHeader>
|
||||
<CardContent className="min-h-0 flex-1 overflow-auto">
|
||||
{alerts.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">暂无告警</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-1 font-mono text-meta">
|
||||
{alerts.map((a) => (
|
||||
<div key={a.id} className="flex gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
||||
<span className="shrink-0 text-muted-foreground tabular-nums">{formatClock(a.time)}</span>
|
||||
<span className={cn('shrink-0 font-semibold', ALERT_LEVEL_CLASS[a.level])}>
|
||||
{a.level.toUpperCase()}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate" title={a.message}>[{a.scope}] {a.message}</span>
|
||||
<SkeletonSwap
|
||||
ready={alerts !== null}
|
||||
reserve={120}
|
||||
lines={5}
|
||||
lineHeight={24}
|
||||
barHeight={9}
|
||||
label="最近告警"
|
||||
className={alerts !== null ? 'skeleton-swap-fluid min-h-[120px]' : ''}
|
||||
>
|
||||
{alerts !== null ? (
|
||||
loadError && alerts.length === 0 ? (
|
||||
<p role="alert" className="rounded-xl border border-destructive/30 bg-destructive/10 px-3 py-8 text-center text-sm text-destructive">
|
||||
{loadError}
|
||||
</p>
|
||||
) : alerts.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">暂无告警</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
) : (
|
||||
<div className="flex flex-col gap-1 font-mono text-meta">
|
||||
{loadError && (
|
||||
<p role="alert" className="mb-1 rounded-lg border border-destructive/30 bg-destructive/10 px-2 py-1.5 font-sans text-xs text-destructive">
|
||||
{loadError};当前显示已收到的实时告警。
|
||||
</p>
|
||||
)}
|
||||
{alerts.map((a) => (
|
||||
<div key={a.id} className="flex gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
||||
<span className="shrink-0 text-muted-foreground tabular-nums">{formatClock(a.time)}</span>
|
||||
<span className={cn('shrink-0 font-semibold', ALERT_LEVEL_CLASS[a.level])}>
|
||||
{a.level.toUpperCase()}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate" title={a.message}>[{a.scope}] {a.message}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import { NAV_ITEMS } from '@/components/layout/sidebar';
|
||||
import { TOPBAR_CATALOGUE } from '@/components/layout/top-bar';
|
||||
import { ChangePasswordDialog } from '@/components/change-password-dialog';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { useApi } from '@/lib/api';
|
||||
import { useAppState } from '@/contexts/AppStateContext';
|
||||
import { cn } from '@/lib/utils';
|
||||
@@ -739,6 +740,7 @@ function FontField({
|
||||
const listId = useId();
|
||||
const [fonts, setFonts] = useState<string[] | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [fontLoadError, setFontLoadError] = useState<string | null>(null);
|
||||
const canQuery = typeof (window as FontQueryWindow).queryLocalFonts === 'function';
|
||||
const isCustom = value === FONT_CUSTOM_ID;
|
||||
|
||||
@@ -747,16 +749,17 @@ function FontField({
|
||||
{ value: FONT_CUSTOM_ID, label: '自定义' },
|
||||
];
|
||||
|
||||
// Lazily enumerate local fonts the first time the field is focused. A denied
|
||||
// permission (or any failure) just leaves the plain text box — no error UI.
|
||||
// Lazily enumerate local fonts the first time the field is focused.
|
||||
const loadFonts = async () => {
|
||||
if (fonts !== null || loading || !canQuery) return;
|
||||
setLoading(true);
|
||||
setFontLoadError(null);
|
||||
try {
|
||||
const arr = await (window as FontQueryWindow).queryLocalFonts!();
|
||||
setFonts(Array.from(new Set(arr.map((f) => f.family))).sort((x, y) => x.localeCompare(y)));
|
||||
} catch {
|
||||
setFonts([]);
|
||||
} catch (error) {
|
||||
console.error('Failed to enumerate local fonts', error);
|
||||
setFontLoadError('无法读取本机字体,请检查浏览器权限后重试。');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -784,11 +787,32 @@ function FontField({
|
||||
{fonts.map((f) => <option key={f} value={f} />)}
|
||||
</datalist>
|
||||
)}
|
||||
<p className="text-xs leading-snug text-muted-foreground">
|
||||
{canQuery
|
||||
? '可输入字体名称,或聚焦后从已安装字体中选择;找不到时回退到系统字体。'
|
||||
: '输入已安装的字体名称(可写多个,用逗号分隔);找不到时回退到系统字体。'}
|
||||
</p>
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
reserve={28}
|
||||
lines={1}
|
||||
label="本机字体"
|
||||
className={!loading ? 'skeleton-swap-fluid' : ''}
|
||||
>
|
||||
{fontLoadError ? (
|
||||
<div className="flex items-center gap-2 text-xs leading-snug text-destructive">
|
||||
<span>{fontLoadError}</span>
|
||||
<button
|
||||
type="button"
|
||||
className="shrink-0 font-medium underline underline-offset-2"
|
||||
onClick={() => void loadFonts()}
|
||||
>
|
||||
重试
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs leading-snug text-muted-foreground">
|
||||
{canQuery
|
||||
? '可输入字体名称,或聚焦后从已安装字体中选择;找不到时回退到系统字体。'
|
||||
: '输入已安装的字体名称(可写多个,用逗号分隔);找不到时回退到系统字体。'}
|
||||
</p>
|
||||
)}
|
||||
</SkeletonSwap>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -1250,7 +1274,7 @@ function assetHint(latest: string, platform?: string, arch?: string): string | n
|
||||
// Advisory software update, shown as a grouped list. Read-only: links to the
|
||||
// GitHub release; SnowLuma never downloads or applies anything itself.
|
||||
function UpdateGroup() {
|
||||
const { updateInfo, refreshUpdate, systemInfo } = useAppState();
|
||||
const { updateInfo, refreshUpdate, systemInfo, resources } = useAppState();
|
||||
const { runAction } = useActionFeedback();
|
||||
const [checking, setChecking] = useState(false);
|
||||
|
||||
@@ -1286,7 +1310,8 @@ function UpdateGroup() {
|
||||
const disabledCheck = updateInfo?.error === 'disabled';
|
||||
|
||||
let status: ReactNode;
|
||||
if (!updateInfo) status = <span className="text-muted-foreground">正在检查…</span>;
|
||||
if (!updateInfo && resources.updateInfo.error) status = <span className="text-muted-foreground">无法检查</span>;
|
||||
else if (!updateInfo) status = null;
|
||||
else if (disabledCheck) status = <span className="text-muted-foreground">检查已关闭</span>;
|
||||
else if (updateInfo.error) status = <span className="text-muted-foreground">无法检查</span>;
|
||||
else if (updateInfo.hasUpdate && updateInfo.latest) status = <span className="font-medium text-primary">发现新版本</span>;
|
||||
@@ -1337,7 +1362,17 @@ function UpdateGroup() {
|
||||
</SettingRow>
|
||||
<SettingRow label="检查更新">
|
||||
<div className="flex items-center gap-2.5 text-[12px]">
|
||||
{status}
|
||||
<SkeletonSwap
|
||||
ready={resources.updateInfo.ready}
|
||||
reserve={24}
|
||||
lines={1}
|
||||
lineHeight={24}
|
||||
barHeight={8}
|
||||
label="更新状态"
|
||||
className={resources.updateInfo.ready ? 'skeleton-swap-fluid min-h-6 min-w-24' : 'w-24'}
|
||||
>
|
||||
{resources.updateInfo.ready ? status : null}
|
||||
</SkeletonSwap>
|
||||
{!disabledCheck && (
|
||||
<Button variant="outline" size="sm" onClick={onCheck} disabled={checking}>
|
||||
{checking ? <Loader2 className="size-4 animate-spin" /> : <RefreshCw className="size-4" />}
|
||||
|
||||
Reference in new issue
Block a user