feat(webui): split overview into a processes page + mobile/ultrawide pass

The homepage was doing double duty — monitoring + injection control. Split it:

- New /processes page ("进程注入", sidebar #2) owns the QQ-process control
  surface (load / unload / refresh / probe-login + its dialogs). Overview is
  now a read-only dashboard: stats, host metrics, online accounts, plus a
  read-only injection-summary tile (online / loadable, links to /processes)
  and a first-run CTA that points at /processes while nothing is online.
  Route + AppPath + nav item wired; state/polling stay layout-owned.

Responsive + a11y pass:
- Mobile sidebar Sheet gets an sr-only title + description, fixing the Radix
  "DialogContent requires a DialogTitle" accessibility error.
- Log rows stack on phones (meta line + full-width message) instead of a
  ~40px column that broke every few chars; time parses defensively so a
  non-ISO value never renders "Invalid Date".
- Process cards stack on phones (info row + actions row) so name / PID / path
  stop collapsing to "Q.."; the status badge no longer wraps.
- Config tab strip scrolls horizontally on phones instead of wrapping to
  three rows; account strip defaults collapsed ≤lg; header buttons wrap.
- Dialogs keep a 1rem gutter on tiny screens via w-[calc(100vw-2rem)].
- Content widens to 1600px on ≥2xl; account/process grids gain a column at
  2xl so >1700px screens aren't mostly empty gutter.
This commit is contained in:
DrSmoothl
2026-05-30 16:56:34 +08:00
parent 3cfac51811
commit 71be3ae2e1
9 changed files with 369 additions and 245 deletions
@@ -1,7 +1,7 @@
import { useEffect, useState, type ReactNode } from 'react';
import { motion, AnimatePresence } from 'motion/react';
import { useRouterState } from '@tanstack/react-router';
import { Sheet, SheetContent } from '@/components/ui/sheet';
import { Sheet, SheetContent, SheetDescription, SheetTitle } from '@/components/ui/sheet';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Sidebar } from '@/components/layout/sidebar';
import { TopBar } from '@/components/layout/top-bar';
@@ -44,6 +44,11 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
{isMobile && (
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
<SheetContent side="left" className="w-64 max-w-[80vw] p-0">
{/* Radix Dialog (the Sheet primitive) requires an accessible name +
description; the nav itself is the visible content, so these are
screen-reader-only. */}
<SheetTitle className="sr-only">导航菜单</SheetTitle>
<SheetDescription className="sr-only">切换 SnowLuma 控制台的页面。</SheetDescription>
<Sidebar onItemClick={() => setMobileOpen(false)} />
</SheetContent>
</Sheet>
@@ -62,7 +67,7 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
<main className={cn('flex min-h-0 flex-1 flex-col')}>
<ScrollArea className="flex-1 min-h-0" viewportClassName="[&>div]:!block">
<div className="mx-auto w-full max-w-7xl px-4 py-5 sm:px-6 sm:py-6 lg:px-8">
<div className="mx-auto w-full max-w-7xl px-4 py-5 sm:px-6 sm:py-6 lg:px-8 2xl:max-w-[1600px]">
<AnimatePresence mode="wait">
<motion.div
key={pathname}
@@ -1,4 +1,4 @@
import { LayoutDashboard, Settings, SlidersHorizontal, Terminal } from 'lucide-react';
import { LayoutDashboard, PlugZap, Settings, SlidersHorizontal, Terminal } from 'lucide-react';
import { motion } from 'motion/react';
import { Link, useRouterState } from '@tanstack/react-router';
import { ScrollArea } from '@/components/ui/scroll-area';
@@ -16,6 +16,7 @@ export interface NavItem {
export const NAV_ITEMS: NavItem[] = [
{ to: '/', label: '总览', icon: LayoutDashboard, description: '主机与服务状态' },
{ to: '/processes', label: '进程注入', icon: PlugZap, description: '加载 / 卸载 / 登录' },
{ to: '/config', label: '节点配置', icon: Settings, description: 'OneBot 协议端点' },
{ to: '/logs', label: '日志', icon: Terminal, description: '实时事件流' },
{ to: '/settings', label: '系统设置', icon: SlidersHorizontal, description: '主题与账号' },
@@ -56,7 +56,11 @@ export function ConfigPage() {
});
const [activeTab, setActiveTab] = useState<TabKey>('general');
const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
// Default the account strip to its 56px avatar-only form on narrow screens
// (≤lg) so the editor pane isn't squeezed; the user can still expand it.
const [sidebarCollapsed, setSidebarCollapsed] = useState(
() => typeof window !== 'undefined' && window.matchMedia('(max-width: 1024px)').matches,
);
const [confirmSave, setConfirmSave] = useState(false);
// The edit dialog is modal and blocks every other click in the page,
// so `selectedUin` cannot change while it's open — no defensive close
@@ -244,7 +248,7 @@ function HeaderBar({ selectedUin, dirty, saveStatus, onSave, activeTab, onCreate
UIN {selectedUin}
</code>
</div>
<div className="flex items-center gap-2">
<div className="flex flex-wrap items-center gap-2">
{saveStatus && (
<span
className={cn(
@@ -288,7 +292,7 @@ interface TabStripProps {
function TabStrip({ activeTab, onChange, counts }: TabStripProps) {
return (
<div className="flex flex-wrap gap-1 border-b">
<div className="flex gap-1 overflow-x-auto border-b [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
{ALL_TABS.map((key) => {
const label = key === 'general' ? '通用设置' : NETWORK_TABS[key].title;
const count = key === 'general' ? null : counts[key];
@@ -299,7 +303,7 @@ function TabStrip({ activeTab, onChange, counts }: TabStripProps) {
type="button"
onClick={() => onChange(key)}
className={cn(
'group relative inline-flex items-center gap-1.5 px-3 py-2 text-sm transition-colors cursor-pointer',
'group relative inline-flex shrink-0 items-center gap-1.5 whitespace-nowrap px-3 py-2 text-sm transition-colors cursor-pointer',
active ? 'text-foreground' : 'text-muted-foreground hover:text-foreground',
)}
>
@@ -21,6 +21,13 @@ const levelClass: Record<LogLevel, string> = {
const LEVELS: LogLevel[] = ['debug', 'info', 'success', 'warn', 'error'];
/** Show a locale time when the backend sends an ISO timestamp (it does);
* fall back to the raw string otherwise so we never render "Invalid Date". */
function formatTime(t: string): string {
const d = new Date(t);
return Number.isNaN(d.getTime()) ? t : d.toLocaleTimeString();
}
export function LogsPage() {
const api = useApi();
const [logs, setLogs] = useState<LogEntry[]>([]);
@@ -205,16 +212,19 @@ export function LogsPage() {
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.12 }}
className="flex gap-2 whitespace-pre-wrap px-3 py-0.5 leading-5 hover:bg-accent/30"
className="flex flex-col gap-0.5 px-3 py-1 leading-5 hover:bg-accent/30 sm:flex-row sm:gap-2 sm:py-0.5"
>
<span className="shrink-0 text-muted-foreground tabular-nums">
{new Date(log.time).toLocaleTimeString()}
</span>
<span className={cn('w-14 shrink-0 font-semibold', levelClass[log.level])}>
{log.level.toUpperCase()}
</span>
<span className="w-28 shrink-0 truncate text-muted-foreground">[{log.scope}]</span>
<span className="break-all">{log.message}</span>
{/* Meta drops to its own line on phones so the message gets
the full width instead of a ~40px column that breaks
every few characters. On sm+ it's the dense single row. */}
<div className="flex shrink-0 items-center gap-2">
<span className="shrink-0 text-muted-foreground tabular-nums">{formatTime(log.time)}</span>
<span className={cn('shrink-0 font-semibold sm:w-14', levelClass[log.level])}>
{log.level.toUpperCase()}
</span>
<span className="min-w-0 truncate text-muted-foreground sm:w-28">[{log.scope}]</span>
</div>
<span className="min-w-0 whitespace-pre-wrap break-all">{log.message}</span>
</motion.div>
))
)}
@@ -1,51 +1,28 @@
import { useEffect, useState } from 'react';
import { motion } from 'motion/react';
import { Link } from '@tanstack/react-router';
import {
Activity,
AlertCircle,
CheckCircle2,
ArrowRight,
Cpu,
Eye,
Loader2,
MemoryStick,
MonitorCog,
PlugZap,
RefreshCw,
Server,
Unplug,
Users,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Progress } from '@/components/ui/progress';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Skeleton } from '@/components/ui/skeleton';
import { ConfirmDialog } from '@/components/confirm-dialog';
import { ProcessProbeDialog } from '@/components/process-probe-dialog';
import { cn, formatBytes, formatUptime } from '@/lib/utils';
import type { HookProcessInfo } from '@/types';
import type { AppPath } from '@/router';
import { useAppState } from '@/contexts/AppStateContext';
import { useSession } from '@/contexts/SessionContext';
const processStatusLabel: Record<HookProcessInfo['status'], string> = {
available: '可加载',
loading: '加载中',
connecting: '等待连接',
loaded: '等待登录',
online: '已在线',
error: '错误',
disconnected: '已断开',
};
function processBadgeVariant(status: HookProcessInfo['status']) {
if (status === 'online') return 'success' as const;
if (status === 'error') return 'destructive' as const;
if (status === 'disconnected') return 'destructive' as const;
if (status === 'loading' || status === 'connecting' || status === 'loaded') return 'default' as const;
return 'secondary' as const;
}
function qqAvatarUrl(uin: string) {
return `/avatar/${encodeURIComponent(uin)}`;
}
@@ -56,44 +33,48 @@ function StatTile({
value,
subtext,
accent = false,
to,
}: {
icon: React.ReactNode;
label: string;
value: React.ReactNode;
subtext?: React.ReactNode;
accent?: boolean;
/** When set, the whole tile becomes a link to this route. */
to?: AppPath;
}) {
return (
<Card className="overflow-hidden">
<CardContent className="flex items-center gap-3 p-4">
<div
className={cn(
'flex size-10 shrink-0 items-center justify-center rounded-xl',
accent ? 'bg-primary text-primary-foreground' : 'bg-primary/10 text-primary'
)}
>
{icon}
</div>
<div className="min-w-0 flex-1">
<p className="text-[11px] font-medium uppercase tracking-wider text-muted-foreground">{label}</p>
<div className="mt-0.5 truncate text-base font-semibold tabular-nums">{value}</div>
{subtext && <p className="mt-0.5 truncate text-[11px] text-muted-foreground">{subtext}</p>}
</div>
</CardContent>
</Card>
const body = (
<CardContent className="flex items-center gap-3 p-4">
<div
className={cn(
'flex size-10 shrink-0 items-center justify-center rounded-xl',
accent ? 'bg-primary text-primary-foreground' : 'bg-primary/10 text-primary'
)}
>
{icon}
</div>
<div className="min-w-0 flex-1">
<p className="text-[11px] font-medium uppercase tracking-wider text-muted-foreground">{label}</p>
<div className="mt-0.5 truncate text-base font-semibold tabular-nums">{value}</div>
{subtext && <p className="mt-0.5 truncate text-[11px] text-muted-foreground">{subtext}</p>}
</div>
{to && <ArrowRight className="size-4 shrink-0 text-muted-foreground/60" />}
</CardContent>
);
if (to) {
return (
<Link to={to} className="block rounded-xl outline-none">
<Card className="overflow-hidden transition-colors hover:border-primary/40 hover:bg-accent/30">{body}</Card>
</Link>
);
}
return <Card className="overflow-hidden">{body}</Card>;
}
export function OverviewPage() {
const { qqList, processList, systemInfo, processOps, refreshProcesses, refreshSystem } =
useAppState();
const { qqList, processList, systemInfo, refreshSystem } = useAppState();
const { status } = useSession();
const { statusOf, banner: processActionStatus, load, unload, refresh } = processOps;
const [confirm, setConfirm] = useState<
| { kind: 'load' | 'unload'; pid: number; name: string }
| null
>(null);
const [probeDialog, setProbeDialog] = useState<{ pid: number; name: string } | null>(null);
// Lightweight tick to refresh "uptime" pretty-print every 30s
const [, force] = useState(0);
@@ -103,11 +84,14 @@ export function OverviewPage() {
}, []);
const online = status === '已连接';
// Read-only injection health for the dashboard. Control lives on /processes.
const onlineProcs = processList.filter((p) => p.status === 'online').length;
const loadableProcs = processList.filter((p) => !p.injected).length;
return (
<div className="flex flex-col gap-6">
{/* Top stats */}
<div className="grid grid-cols-2 gap-3 sm:gap-4 md:grid-cols-4">
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 sm:gap-4 lg:grid-cols-5">
<StatTile
icon={<Activity className="size-5" />}
label="服务状态"
@@ -121,6 +105,13 @@ export function OverviewPage() {
value={qqList.length}
subtext={`已接入 ${qqList.length} 个会话`}
/>
<StatTile
icon={<PlugZap className="size-5" />}
label="进程注入"
value={`${onlineProcs} 在线`}
subtext={`${processList.length} 进程 · ${loadableProcs} 可注入`}
to="/processes"
/>
<StatTile
icon={<Server className="size-5" />}
label="主机名"
@@ -135,6 +126,29 @@ export function OverviewPage() {
/>
</div>
{/* First-run nudge: nothing online yet → point at the injection page. */}
{qqList.length === 0 && (
<motion.div initial={{ opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }}>
<Link
to="/processes"
className="flex items-center gap-3 rounded-xl border border-primary/30 bg-primary/5 px-4 py-3 transition-colors hover:bg-primary/10"
>
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-primary/15 text-primary">
<PlugZap className="size-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-sm font-medium">
{loadableProcs > 0 ? `检测到 ${loadableProcs} 个可加载 QQ 进程` : '尚未接入任何账号'}
</p>
<p className="text-[11px] text-muted-foreground">
前往「进程注入」加载 QQ,登录后会自动接入 OneBot 流程。
</p>
</div>
<ArrowRight className="size-4 shrink-0 text-primary" />
</Link>
</motion.div>
)}
{/* System metrics */}
<Card>
<CardHeader className="flex flex-row items-center justify-between gap-3 space-y-0">
@@ -240,147 +254,6 @@ export function OverviewPage() {
</CardContent>
</Card>
{/* QQ Processes */}
<Card>
<CardHeader className="flex flex-row items-center justify-between gap-3 space-y-0">
<div>
<CardTitle>QQ 进程</CardTitle>
<CardDescription>
加载 SnowLuma 后会监听登录状态,登录后自动接入 OneBot 流程
</CardDescription>
</div>
<Button variant="outline" size="sm" onClick={refreshProcesses}>
<RefreshCw className="size-3.5" /> 刷新
</Button>
</CardHeader>
<CardContent>
{processActionStatus && (
<motion.div
initial={{ opacity: 0, y: -4 }}
animate={{ opacity: 1, y: 0 }}
className="mb-3 rounded-md border border-primary/20 bg-primary/5 px-3 py-2 text-xs text-primary"
>
{processActionStatus}
</motion.div>
)}
{processList.length === 0 ? (
<div className="flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed py-10 text-muted-foreground">
<Cpu className="size-7" strokeWidth={1.5} />
<p className="text-sm">未检测到可加载 QQ 主进程</p>
</div>
) : (
<div className="grid grid-cols-1 gap-3 xl:grid-cols-2">
{processList.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={{ opacity: 0, y: 6 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.03 + idx * 0.025, duration: 0.22 }}
className="flex items-center gap-3 rounded-lg border bg-card/50 p-3"
>
<div
className={cn(
'flex size-10 shrink-0 items-center justify-center rounded-lg',
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="truncate text-sm font-semibold">{proc.name || 'QQ.exe'}</span>
<Badge variant={processBadgeVariant(proc.status)}>{processStatusLabel[proc.status]}</Badge>
</div>
<div className="mt-0.5 truncate font-mono text-[11px] text-muted-foreground tabular-nums">
PID {proc.pid}
{proc.uin && proc.uin !== '0' ? ` · UIN ${proc.uin}` : ''}
</div>
{proc.path && (
<div className="truncate text-[11px] text-muted-foreground/80" title={proc.path}>
{proc.path}
</div>
)}
{proc.error && (
<div className="mt-0.5 truncate text-[11px] text-destructive" title={proc.error}>
{proc.error}
</div>
)}
</div>
<div className="flex shrink-0 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>
)}
</CardContent>
</Card>
{/* Online accounts */}
<Card>
<CardHeader>
@@ -395,7 +268,7 @@ export function OverviewPage() {
</div>
) : (
<ScrollArea className="max-h-[420px]" viewportClassName="[&>div]:!block">
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3">
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
{qqList.map((q, idx) => (
<motion.div
key={q.uin}
@@ -421,35 +294,6 @@ export function OverviewPage() {
)}
</CardContent>
</Card>
<ConfirmDialog
open={!!confirm}
onOpenChange={(o) => !o && setConfirm(null)}
title={confirm?.kind === 'unload' ? '确认卸载 SnowLuma?' : '确认加载 SnowLuma?'}
description={
confirm
? confirm.kind === 'unload'
? `将从进程 ${confirm.name} 卸载 SnowLuma 注入,可能导致当前会话断开。`
: `将向进程 ${confirm.name} 注入 SnowLuma,并开始监听登录状态。`
: ''
}
confirmText={confirm?.kind === 'unload' ? '卸载' : '加载'}
destructive={confirm?.kind === 'unload'}
onConfirm={async () => {
if (!confirm) return;
if (confirm.kind === 'unload') await unload(confirm.pid);
else await load(confirm.pid);
}}
/>
{probeDialog && (
<ProcessProbeDialog
pid={probeDialog.pid}
processName={probeDialog.name}
open={!!probeDialog}
onOpenChange={(open) => !open && setProbeDialog(null)}
/>
)}
</div>
);
}
@@ -0,0 +1,222 @@
import { useState } from 'react';
import { motion } from 'motion/react';
import { AlertCircle, CheckCircle2, Cpu, Eye, Loader2, RefreshCw, Unplug } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { ConfirmDialog } from '@/components/confirm-dialog';
import { ProcessProbeDialog } from '@/components/process-probe-dialog';
import { cn } from '@/lib/utils';
import type { HookProcessInfo } from '@/types';
import { useAppState } from '@/contexts/AppStateContext';
const processStatusLabel: Record<HookProcessInfo['status'], string> = {
available: '可加载',
loading: '加载中',
connecting: '等待连接',
loaded: '等待登录',
online: '已在线',
error: '错误',
disconnected: '已断开',
};
function processBadgeVariant(status: HookProcessInfo['status']) {
if (status === 'online') return 'success' as const;
if (status === 'error') return 'destructive' as const;
if (status === 'disconnected') return 'destructive' as const;
if (status === 'loading' || status === 'connecting' || status === 'loaded') return 'default' as const;
return 'secondary' as const;
}
/**
* Process / injection control surface. Split out of the overview page so the
* homepage stays a read-only monitoring dashboard. State (processList,
* processOps) is owned by AppLayout and read from context, so this page needs
* no plumbing of its own; the layout keeps polling and the unload-failed alert
* regardless of which page is mounted.
*/
export function ProcessesPage() {
const { processList, processOps, refreshProcesses } = useAppState();
const { statusOf, banner: processActionStatus, load, unload, refresh } = processOps;
const [confirm, setConfirm] = useState<{ kind: 'load' | 'unload'; pid: number; name: string } | null>(null);
const [probeDialog, setProbeDialog] = useState<{ pid: number; name: string } | null>(null);
return (
<div className="flex flex-col gap-6">
<Card>
<CardHeader className="flex flex-row items-center justify-between gap-3 space-y-0">
<div>
<CardTitle>进程注入</CardTitle>
<CardDescription>加载 SnowLuma 后会监听登录状态,登录后自动接入 OneBot 流程</CardDescription>
</div>
<Button variant="outline" size="sm" onClick={refreshProcesses}>
<RefreshCw className="size-3.5" /> 刷新
</Button>
</CardHeader>
<CardContent>
{processActionStatus && (
<motion.div
initial={{ opacity: 0, y: -4 }}
animate={{ opacity: 1, y: 0 }}
className="mb-3 rounded-md border border-primary/20 bg-primary/5 px-3 py-2 text-xs text-primary"
>
{processActionStatus}
</motion.div>
)}
{processList.length === 0 ? (
<div className="flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed py-16 text-muted-foreground">
<Cpu className="size-7" strokeWidth={1.5} />
<p className="text-sm">未检测到可加载 QQ 主进程</p>
<p className="text-[11px] text-muted-foreground/80">请确认 QQ 已启动后点击右上角刷新</p>
</div>
) : (
<div className="grid grid-cols-1 gap-3 xl:grid-cols-2 2xl:grid-cols-3">
{processList.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={{ opacity: 0, y: 6 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.03 + idx * 0.025, duration: 0.22 }}
className="flex flex-col gap-3 rounded-lg border bg-card/50 p-3 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-lg',
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-[11px] text-muted-foreground tabular-nums">
PID {proc.pid}
{proc.uin && proc.uin !== '0' ? ` · UIN ${proc.uin}` : ''}
</div>
{proc.path && (
<div className="truncate text-[11px] text-muted-foreground/80" title={proc.path}>
{proc.path}
</div>
)}
{proc.error && (
<div className="mt-0.5 truncate text-[11px] 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>
)}
</CardContent>
</Card>
<ConfirmDialog
open={!!confirm}
onOpenChange={(o) => !o && setConfirm(null)}
title={confirm?.kind === 'unload' ? '确认卸载 SnowLuma?' : '确认加载 SnowLuma?'}
description={
confirm
? confirm.kind === 'unload'
? `将从进程 ${confirm.name} 卸载 SnowLuma 注入,可能导致当前会话断开。`
: `将向进程 ${confirm.name} 注入 SnowLuma,并开始监听登录状态。`
: ''
}
confirmText={confirm?.kind === 'unload' ? '卸载' : '加载'}
destructive={confirm?.kind === 'unload'}
onConfirm={async () => {
if (!confirm) return;
if (confirm.kind === 'unload') await unload(confirm.pid);
else await load(confirm.pid);
}}
/>
{probeDialog && (
<ProcessProbeDialog
pid={probeDialog.pid}
processName={probeDialog.name}
open={!!probeDialog}
onOpenChange={(open) => !open && setProbeDialog(null)}
/>
)}
</div>
);
}
+5 -1
View File
@@ -32,7 +32,11 @@ const DialogContent = React.forwardRef<
<DialogPrimitive.Content
ref={ref}
className={cn(
'fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl border bg-card p-6 shadow-lg outline-none',
// `w-[calc(100vw-2rem)]` keeps a 1rem gutter on every side on small
// phones (plain `w-full` made the dialog touch both edges). Callers
// only ever override `max-w-*` (the desktop cap), so the width floor
// here survives those overrides — width and max-width are distinct.
'fixed left-1/2 top-1/2 z-50 grid w-[calc(100vw_-_2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl border bg-card p-6 shadow-lg outline-none',
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
className
+26 -1
View File
@@ -63,4 +63,29 @@ const SheetContent = React.forwardRef<React.ElementRef<typeof DialogPrimitive.Co
);
SheetContent.displayName = 'SheetContent';
export { Sheet, SheetTrigger, SheetClose, SheetContent, SheetPortal, SheetOverlay };
const SheetTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title ref={ref} className={cn('text-lg font-semibold tracking-tight', className)} {...props} />
));
SheetTitle.displayName = 'SheetTitle';
const SheetDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
));
SheetDescription.displayName = 'SheetDescription';
export {
Sheet,
SheetTrigger,
SheetClose,
SheetContent,
SheetPortal,
SheetOverlay,
SheetTitle,
SheetDescription,
};
+11 -2
View File
@@ -37,6 +37,15 @@ const overviewRoute = createRoute({
),
});
const processesRoute = createRoute({
path: '/processes',
getParentRoute: () => appLayoutRoute,
component: lazyRouteComponent(
() => import('@/components/pages/processes-page'),
'ProcessesPage',
),
});
const configRoute = createRoute({
path: '/config',
getParentRoute: () => appLayoutRoute,
@@ -65,7 +74,7 @@ const settingsRoute = createRoute({
});
const routeTree = rootRoute.addChildren([
appLayoutRoute.addChildren([overviewRoute, configRoute, logsRoute, settingsRoute]),
appLayoutRoute.addChildren([overviewRoute, processesRoute, configRoute, logsRoute, settingsRoute]),
]);
export const appRouter = createRouter({
@@ -82,4 +91,4 @@ declare module '@tanstack/react-router' {
}
/** Paths registered on the layout — single source of truth for nav metadata. */
export type AppPath = '/' | '/config' | '/logs' | '/settings';
export type AppPath = '/' | '/processes' | '/config' | '/logs' | '/settings';