diff --git a/packages/webui/src/components/layout/main-layout.tsx b/packages/webui/src/components/layout/main-layout.tsx index 6a39f70a..22e71261 100644 --- a/packages/webui/src/components/layout/main-layout.tsx +++ b/packages/webui/src/components/layout/main-layout.tsx @@ -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 && ( + {/* Radix Dialog (the Sheet primitive) requires an accessible name + + description; the nav itself is the visible content, so these are + screen-reader-only. */} + 导航菜单 + 切换 SnowLuma 控制台的页面。 setMobileOpen(false)} /> @@ -62,7 +67,7 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
-
+
('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}
-
+
{saveStatus && ( +
{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', )} > diff --git a/packages/webui/src/components/pages/logs-page.tsx b/packages/webui/src/components/pages/logs-page.tsx index 6201bc06..05dbe644 100644 --- a/packages/webui/src/components/pages/logs-page.tsx +++ b/packages/webui/src/components/pages/logs-page.tsx @@ -21,6 +21,13 @@ const levelClass: Record = { 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([]); @@ -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" > - - {new Date(log.time).toLocaleTimeString()} - - - {log.level.toUpperCase()} - - [{log.scope}] - {log.message} + {/* 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. */} +
+ {formatTime(log.time)} + + {log.level.toUpperCase()} + + [{log.scope}] +
+ {log.message} )) )} diff --git a/packages/webui/src/components/pages/overview-page.tsx b/packages/webui/src/components/pages/overview-page.tsx index 096d1db2..d585aabb 100644 --- a/packages/webui/src/components/pages/overview-page.tsx +++ b/packages/webui/src/components/pages/overview-page.tsx @@ -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 = { - 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 ( - - -
- {icon} -
-
-

{label}

-
{value}
- {subtext &&

{subtext}

} -
-
-
+ const body = ( + +
+ {icon} +
+
+

{label}

+
{value}
+ {subtext &&

{subtext}

} +
+ {to && } +
); + + if (to) { + return ( + + {body} + + ); + } + return {body}; } 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 (
{/* Top stats */} -
+
} label="服务状态" @@ -121,6 +105,13 @@ export function OverviewPage() { value={qqList.length} subtext={`已接入 ${qqList.length} 个会话`} /> + } + label="进程注入" + value={`${onlineProcs} 在线`} + subtext={`${processList.length} 进程 · ${loadableProcs} 可注入`} + to="/processes" + /> } label="主机名" @@ -135,6 +126,29 @@ export function OverviewPage() { />
+ {/* First-run nudge: nothing online yet → point at the injection page. */} + {qqList.length === 0 && ( + + +
+ +
+
+

+ {loadableProcs > 0 ? `检测到 ${loadableProcs} 个可加载 QQ 进程` : '尚未接入任何账号'} +

+

+ 前往「进程注入」加载 QQ,登录后会自动接入 OneBot 流程。 +

+
+ + +
+ )} + {/* System metrics */} @@ -240,147 +254,6 @@ export function OverviewPage() { - {/* QQ Processes */} - - -
- QQ 进程 - - 加载 SnowLuma 后会监听登录状态,登录后自动接入 OneBot 流程 - -
- -
- - {processActionStatus && ( - - {processActionStatus} - - )} - {processList.length === 0 ? ( -
- -

未检测到可加载 QQ 主进程

-
- ) : ( -
- {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 ( - -
- {isOnline ? ( - - ) : proc.status === 'error' ? ( - - ) : ( - - )} -
-
-
- {proc.name || 'QQ.exe'} - {processStatusLabel[proc.status]} -
-
- PID {proc.pid} - {proc.uin && proc.uin !== '0' ? ` · UIN ${proc.uin}` : ''} -
- {proc.path && ( -
- {proc.path} -
- )} - {proc.error && ( -
- {proc.error} -
- )} -
-
- - {showRefresh && ( - - )} - -
-
- ); - })} -
- )} -
-
- {/* Online accounts */} @@ -395,7 +268,7 @@ export function OverviewPage() {
) : ( -
+
{qqList.map((q, idx) => ( - - !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 && ( - !open && setProbeDialog(null)} - /> - )}
); } diff --git a/packages/webui/src/components/pages/processes-page.tsx b/packages/webui/src/components/pages/processes-page.tsx new file mode 100644 index 00000000..d011d8a4 --- /dev/null +++ b/packages/webui/src/components/pages/processes-page.tsx @@ -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 = { + 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 ( +
+ + +
+ 进程注入 + 加载 SnowLuma 后会监听登录状态,登录后自动接入 OneBot 流程 +
+ +
+ + {processActionStatus && ( + + {processActionStatus} + + )} + {processList.length === 0 ? ( +
+ +

未检测到可加载 QQ 主进程

+

请确认 QQ 已启动后点击右上角刷新

+
+ ) : ( +
+ {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 ( + + {/* 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..". */} +
+
+ {isOnline ? ( + + ) : proc.status === 'error' ? ( + + ) : ( + + )} +
+
+
+ {proc.name || 'QQ.exe'} + + {processStatusLabel[proc.status]} + +
+
+ PID {proc.pid} + {proc.uin && proc.uin !== '0' ? ` · UIN ${proc.uin}` : ''} +
+ {proc.path && ( +
+ {proc.path} +
+ )} + {proc.error && ( +
+ {proc.error} +
+ )} +
+
+
+ + {showRefresh && ( + + )} + +
+
+ ); + })} +
+ )} +
+
+ + !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 && ( + !open && setProbeDialog(null)} + /> + )} +
+ ); +} diff --git a/packages/webui/src/components/ui/dialog.tsx b/packages/webui/src/components/ui/dialog.tsx index 4352566a..91a115d8 100644 --- a/packages/webui/src/components/ui/dialog.tsx +++ b/packages/webui/src/components/ui/dialog.tsx @@ -32,7 +32,11 @@ const DialogContent = React.forwardRef< , + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +SheetTitle.displayName = 'SheetTitle'; + +const SheetDescription = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +SheetDescription.displayName = 'SheetDescription'; + +export { + Sheet, + SheetTrigger, + SheetClose, + SheetContent, + SheetPortal, + SheetOverlay, + SheetTitle, + SheetDescription, +}; diff --git a/packages/webui/src/router/index.tsx b/packages/webui/src/router/index.tsx index 4f871197..238f1edc 100644 --- a/packages/webui/src/router/index.tsx +++ b/packages/webui/src/router/index.tsx @@ -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';