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
+1170
-204
No files matched your search
@@ -11,6 +11,13 @@ status, OneBot configuration, logs, storage, and server settings.
|
|||||||
automatically after a visible countdown.
|
automatically after a visible countdown.
|
||||||
- Routine, high-frequency adjustments should not generate a notice for every
|
- Routine, high-frequency adjustments should not generate a notice for every
|
||||||
intermediate edit.
|
intermediate edit.
|
||||||
|
- Data-backed surfaces use the Interior Skeleton Swap defaults (120 ms delay,
|
||||||
|
380 ms minimum visibility) so fast local responses do not flash a placeholder.
|
||||||
|
Submission, upload, and other explicit operation progress keeps its spinner.
|
||||||
|
- Variable-height content must release the skeleton's reserved box after it is
|
||||||
|
ready; do not introduce a second scrolling region inside the page.
|
||||||
|
- The mobile navigation menu uses a controlled Icon Morph whose visual state
|
||||||
|
follows the actual drawer state.
|
||||||
- Failures must remain visible in the affected control and in the operation
|
- Failures must remain visible in the affected control and in the operation
|
||||||
result; do not convert failed responses into successful feedback.
|
result; do not convert failed responses into successful feedback.
|
||||||
- Password change flows use floating labels and inline validation consistently.
|
- Password change flows use floating labels and inline validation consistently.
|
||||||
|
|||||||
+76
-10
@@ -1,17 +1,22 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { RouterProvider } from '@tanstack/react-router';
|
import { RouterProvider } from '@tanstack/react-router';
|
||||||
|
import { AlertTriangle, LogOut, RefreshCw } from 'lucide-react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Card, CardContent } from '@/components/ui/card';
|
||||||
import { TooltipProvider } from '@/components/ui/tooltip';
|
import { TooltipProvider } from '@/components/ui/tooltip';
|
||||||
import { ThemeProvider } from '@/contexts/ThemeContext';
|
import { ThemeProvider } from '@/contexts/ThemeContext';
|
||||||
import { SessionProvider } from '@/contexts/SessionContext';
|
import { SessionProvider } from '@/contexts/SessionContext';
|
||||||
import { LoginPage } from '@/components/pages/login-page';
|
import { LoginPage } from '@/components/pages/login-page';
|
||||||
import { ChangePasswordPage } from '@/components/pages/change-password-page';
|
import { ChangePasswordPage } from '@/components/pages/change-password-page';
|
||||||
import { ConsentPage } from '@/components/pages/consent-page';
|
import { ConsentPage } from '@/components/pages/consent-page';
|
||||||
|
import { SkeletonSwap, useSkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { ApiProvider, createApiClient, useApi, type ApiClient } from '@/lib/api';
|
import { ApiProvider, createApiClient, useApi, type ApiClient } from '@/lib/api';
|
||||||
import { DebugTaskProvider } from '@/contexts/DebugTaskContext';
|
import { DebugTaskProvider } from '@/contexts/DebugTaskContext';
|
||||||
import { TaskBadge } from '@/components/debug/task-badge';
|
import { TaskBadge } from '@/components/debug/task-badge';
|
||||||
import { AdaptivePointer } from '@/components/ui/adaptive-pointer';
|
import { AdaptivePointer } from '@/components/ui/adaptive-pointer';
|
||||||
import { GlobalContextMenu } from '@/components/ui/global-context-menu';
|
import { GlobalContextMenu } from '@/components/ui/global-context-menu';
|
||||||
import {
|
import {
|
||||||
|
actionErrorMessage,
|
||||||
ActionFeedbackProvider,
|
ActionFeedbackProvider,
|
||||||
ActionFeedbackViewport,
|
ActionFeedbackViewport,
|
||||||
useActionFeedback,
|
useActionFeedback,
|
||||||
@@ -58,12 +63,15 @@ function AuthBoundary() {
|
|||||||
// Agreement consent gate, shown after login but BEFORE the forced password
|
// Agreement consent gate, shown after login but BEFORE the forced password
|
||||||
// change. `agreements === null` while the post-auth fetch is in flight.
|
// change. `agreements === null` while the post-auth fetch is in flight.
|
||||||
const [agreements, setAgreements] = useState<AgreementsPayload | null>(null);
|
const [agreements, setAgreements] = useState<AgreementsPayload | null>(null);
|
||||||
|
const [agreementsError, setAgreementsError] = useState<string | null>(null);
|
||||||
const [needsConsent, setNeedsConsent] = useState(false);
|
const [needsConsent, setNeedsConsent] = useState(false);
|
||||||
// The password from *this* session's login, carried into the forced
|
// The password from *this* session's login, carried into the forced
|
||||||
// change-password gate so it doesn't have to render an old-password field
|
// change-password gate so it doesn't have to render an old-password field
|
||||||
// (which browsers autofill, misleading users on upgrade). Stays undefined
|
// (which browsers autofill, misleading users on upgrade). Stays undefined
|
||||||
// for a returning session that's already authed but still must change.
|
// for a returning session that's already authed but still must change.
|
||||||
const [loginPassword, setLoginPassword] = useState<string | undefined>(undefined);
|
const [loginPassword, setLoginPassword] = useState<string | undefined>(undefined);
|
||||||
|
const authLoading = !authChecked || (authed && agreements === null && agreementsError === null);
|
||||||
|
const { showSkeleton: showAuthSkeleton } = useSkeletonSwap({ ready: !authLoading });
|
||||||
|
|
||||||
const client = useMemo<ApiClient>(
|
const client = useMemo<ApiClient>(
|
||||||
() =>
|
() =>
|
||||||
@@ -77,14 +85,15 @@ function AuthBoundary() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const refreshAgreements = useCallback(async () => {
|
const refreshAgreements = useCallback(async () => {
|
||||||
|
setAgreements(null);
|
||||||
|
setAgreementsError(null);
|
||||||
try {
|
try {
|
||||||
const payload = await client.agreements.get();
|
const payload = await client.agreements.get();
|
||||||
setAgreements(payload);
|
setAgreements(payload);
|
||||||
setNeedsConsent(payload.consentRequired);
|
setNeedsConsent(payload.consentRequired);
|
||||||
} catch {
|
} catch (error) {
|
||||||
// Fail open on a fetch error so a transient hiccup can't wedge the gate.
|
console.error('agreement status load failed', error);
|
||||||
setAgreements({ version: '', consentRequired: false, documents: [] });
|
setAgreementsError(actionErrorMessage(error));
|
||||||
setNeedsConsent(false);
|
|
||||||
}
|
}
|
||||||
}, [client]);
|
}, [client]);
|
||||||
|
|
||||||
@@ -126,6 +135,7 @@ function AuthBoundary() {
|
|||||||
setStatus('未连接');
|
setStatus('未连接');
|
||||||
setMustChange(false);
|
setMustChange(false);
|
||||||
setAgreements(null);
|
setAgreements(null);
|
||||||
|
setAgreementsError(null);
|
||||||
setNeedsConsent(false);
|
setNeedsConsent(false);
|
||||||
setLoginPassword(undefined);
|
setLoginPassword(undefined);
|
||||||
}, []);
|
}, []);
|
||||||
@@ -136,8 +146,8 @@ function AuthBoundary() {
|
|||||||
}, [client, handleLoggedOut]);
|
}, [client, handleLoggedOut]);
|
||||||
|
|
||||||
let view: React.ReactNode;
|
let view: React.ReactNode;
|
||||||
if (!authChecked) {
|
if (authLoading || showAuthSkeleton) {
|
||||||
view = <Splash>初始化中…</Splash>;
|
view = <Splash>{authChecked ? '加载中…' : '初始化中…'}</Splash>;
|
||||||
} else if (!authed) {
|
} else if (!authed) {
|
||||||
view = (
|
view = (
|
||||||
<LoginGate
|
<LoginGate
|
||||||
@@ -150,9 +160,15 @@ function AuthBoundary() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else if (agreements === null) {
|
} else if (agreementsError) {
|
||||||
view = <Splash>加载中…</Splash>;
|
view = (
|
||||||
} else if (needsConsent) {
|
<AgreementLoadFailure
|
||||||
|
detail={agreementsError}
|
||||||
|
onRetry={() => { void refreshAgreements(); }}
|
||||||
|
onLogout={() => { void handleDecline(); }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else if (needsConsent && agreements) {
|
||||||
view = (
|
view = (
|
||||||
<ConsentGate
|
<ConsentGate
|
||||||
payload={agreements}
|
payload={agreements}
|
||||||
@@ -189,10 +205,60 @@ function AuthBoundary() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function AgreementLoadFailure({
|
||||||
|
detail,
|
||||||
|
onRetry,
|
||||||
|
onLogout,
|
||||||
|
}: {
|
||||||
|
detail: string;
|
||||||
|
onRetry: () => void;
|
||||||
|
onLogout: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen items-center justify-center bg-background px-4 py-8">
|
||||||
|
<Card className="w-full max-w-lg border-destructive/30">
|
||||||
|
<CardContent className="p-7 sm:p-9">
|
||||||
|
<div className="flex items-start gap-3">
|
||||||
|
<div className="flex size-11 shrink-0 items-center justify-center rounded-xl bg-destructive/10 text-destructive">
|
||||||
|
<AlertTriangle className="size-5" />
|
||||||
|
</div>
|
||||||
|
<div className="min-w-0">
|
||||||
|
<h1 className="text-base font-semibold">协议状态加载失败</h1>
|
||||||
|
<p role="alert" className="mt-1.5 text-sm leading-relaxed text-muted-foreground">
|
||||||
|
无法确认当前用户协议与隐私政策状态。为避免绕过必要确认,控制台暂不放行。
|
||||||
|
</p>
|
||||||
|
<p className="mt-2 break-words text-xs text-destructive">{detail}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-6 flex flex-wrap justify-end gap-2">
|
||||||
|
<Button type="button" variant="ghost" onClick={onLogout}>
|
||||||
|
<LogOut className="size-4" />
|
||||||
|
退出登录
|
||||||
|
</Button>
|
||||||
|
<Button type="button" onClick={onRetry}>
|
||||||
|
<RefreshCw className="size-4" />
|
||||||
|
重新加载
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function Splash({ children }: { children: React.ReactNode }) {
|
function Splash({ children }: { children: React.ReactNode }) {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen items-center justify-center bg-background text-sm text-muted-foreground">
|
<div className="flex min-h-screen items-center justify-center bg-background text-sm text-muted-foreground">
|
||||||
{children}
|
<SkeletonSwap
|
||||||
|
ready={false}
|
||||||
|
lines={3}
|
||||||
|
lineHeight={24}
|
||||||
|
reserve={72}
|
||||||
|
label={typeof children === 'string' ? children : 'WebUI'}
|
||||||
|
className="w-64 max-w-[70vw]"
|
||||||
|
>
|
||||||
|
{null}
|
||||||
|
</SkeletonSwap>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,12 @@
|
|||||||
// Scales to many channels (40+): collapsed by default to a one-line summary of
|
// Scales to many channels (40+): collapsed by default to a one-line summary of
|
||||||
// selected channels as removable chips; expanded into a searchable, bulk-
|
// selected channels as removable chips; expanded into a searchable, bulk-
|
||||||
// actionable, height-bounded scroll list so it never blows up the page.
|
// actionable, height-bounded scroll list so it never blows up the page.
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { AnimatePresence, motion } from 'motion/react';
|
import { AnimatePresence, motion } from 'motion/react';
|
||||||
import { ChevronDown, Loader2, Search, X } from 'lucide-react';
|
import { ChevronDown, Search, X } from 'lucide-react';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
@@ -29,24 +31,27 @@ const CHIP_CAP = 8;
|
|||||||
export function NotificationOptIn({ selectedIds, onChange }: NotificationOptInProps) {
|
export function NotificationOptIn({ selectedIds, onChange }: NotificationOptInProps) {
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
const [channels, setChannels] = useState<NotificationChannel[] | null>(null);
|
const [channels, setChannels] = useState<NotificationChannel[] | null>(null);
|
||||||
|
const [loadError, setLoadError] = useState<string | null>(null);
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
const [query, setQuery] = useState('');
|
const [query, setQuery] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
const load = useCallback(async () => {
|
||||||
let cancelled = false;
|
setChannels(null);
|
||||||
void (async () => {
|
setLoadError(null);
|
||||||
try {
|
try {
|
||||||
const cfg = await api.notifications.getConfig();
|
const cfg = await api.notifications.getConfig();
|
||||||
if (!cancelled) setChannels(cfg.channels);
|
setChannels(cfg.channels);
|
||||||
} catch {
|
} catch (error) {
|
||||||
if (!cancelled) setChannels([]);
|
console.error('load notification opt-ins failed', error);
|
||||||
|
setLoadError(error instanceof Error ? error.message : '加载通知渠道失败');
|
||||||
|
setChannels([]);
|
||||||
}
|
}
|
||||||
})();
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, [api]);
|
}, [api]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load();
|
||||||
|
}, [load]);
|
||||||
|
|
||||||
const selected = useMemo(() => new Set(selectedIds), [selectedIds]);
|
const selected = useMemo(() => new Set(selectedIds), [selectedIds]);
|
||||||
|
|
||||||
const toggle = (id: string, on: boolean) => {
|
const toggle = (id: string, on: boolean) => {
|
||||||
@@ -105,9 +110,19 @@ export function NotificationOptIn({ selectedIds, onChange }: NotificationOptInPr
|
|||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{channels === null ? (
|
<SkeletonSwap
|
||||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
ready={channels !== null}
|
||||||
<Loader2 className="size-3.5 animate-spin" /> 加载渠道…
|
lines={2}
|
||||||
|
lineHeight={20}
|
||||||
|
reserve={40}
|
||||||
|
label="通知渠道"
|
||||||
|
className={channels !== null ? 'skeleton-swap-fluid min-h-[40px]' : ''}
|
||||||
|
>
|
||||||
|
{channels !== null ? (
|
||||||
|
loadError ? (
|
||||||
|
<div role="alert" className="flex items-center justify-between gap-3 text-xs text-destructive">
|
||||||
|
<span>{loadError}</span>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => void load()}>重试</Button>
|
||||||
</div>
|
</div>
|
||||||
) : total === 0 ? (
|
) : total === 0 ? (
|
||||||
<p className="text-xs text-muted-foreground">还没有全局渠道——先到「设置 → 通知」添加。</p>
|
<p className="text-xs text-muted-foreground">还没有全局渠道——先到「设置 → 通知」添加。</p>
|
||||||
@@ -222,7 +237,9 @@ export function NotificationOptIn({ selectedIds, onChange }: NotificationOptInPr
|
|||||||
)}
|
)}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</>
|
</>
|
||||||
)}
|
)
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { AnimatePresence, motion, useReducedMotion } from 'motion/react';
|
||||||
|
|
||||||
|
const CROSSFADE = {
|
||||||
|
type: 'spring',
|
||||||
|
stiffness: 260,
|
||||||
|
damping: 34,
|
||||||
|
mass: 0.8,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const WIDTHS = [100, 93, 97, 88, 95, 91] as const;
|
||||||
|
|
||||||
|
function widthFor(index: number, total: number) {
|
||||||
|
if (total > 1 && index === total - 1) return 62;
|
||||||
|
return WIDTHS[(index * 7 + 3) % WIDTHS.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UseSkeletonSwapOptions = {
|
||||||
|
ready: boolean;
|
||||||
|
delay?: number;
|
||||||
|
minVisible?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useSkeletonSwap({
|
||||||
|
ready,
|
||||||
|
delay = 120,
|
||||||
|
minVisible = 380,
|
||||||
|
}: UseSkeletonSwapOptions) {
|
||||||
|
const [visible, setVisible] = useState(false);
|
||||||
|
const shownAt = useRef(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!ready) {
|
||||||
|
if (visible) return;
|
||||||
|
const t = setTimeout(() => {
|
||||||
|
shownAt.current = performance.now();
|
||||||
|
setVisible(true);
|
||||||
|
}, delay);
|
||||||
|
return () => clearTimeout(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!visible) return;
|
||||||
|
const rest = Math.max(0, minVisible - (performance.now() - shownAt.current));
|
||||||
|
const t = setTimeout(() => setVisible(false), rest);
|
||||||
|
return () => clearTimeout(t);
|
||||||
|
}, [ready, visible, delay, minVisible]);
|
||||||
|
|
||||||
|
return { showSkeleton: visible, busy: !ready };
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SkeletonSwapProps = {
|
||||||
|
ready: boolean;
|
||||||
|
children: React.ReactNode;
|
||||||
|
lines?: number;
|
||||||
|
lineHeight?: number;
|
||||||
|
barHeight?: number;
|
||||||
|
reserve?: number;
|
||||||
|
delay?: number;
|
||||||
|
minVisible?: number;
|
||||||
|
label?: string;
|
||||||
|
skeleton?: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function SkeletonSwap({
|
||||||
|
ready,
|
||||||
|
children,
|
||||||
|
lines = 3,
|
||||||
|
lineHeight = 21,
|
||||||
|
barHeight = 9,
|
||||||
|
reserve,
|
||||||
|
delay = 120,
|
||||||
|
minVisible = 380,
|
||||||
|
label,
|
||||||
|
skeleton,
|
||||||
|
className = '',
|
||||||
|
}: SkeletonSwapProps) {
|
||||||
|
const { showSkeleton } = useSkeletonSwap({ ready, delay, minVisible });
|
||||||
|
const reduced = useReducedMotion();
|
||||||
|
|
||||||
|
const shell = useRef<HTMLDivElement>(null);
|
||||||
|
const body = useRef<HTMLDivElement>(null);
|
||||||
|
const [scrollable, setScrollable] = useState(false);
|
||||||
|
|
||||||
|
const box = reserve ?? lines * lineHeight;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const el = shell.current;
|
||||||
|
const inner = body.current;
|
||||||
|
if (!el || typeof ResizeObserver === 'undefined') return;
|
||||||
|
|
||||||
|
const check = () => setScrollable(el.scrollHeight - el.clientHeight > 1);
|
||||||
|
check();
|
||||||
|
|
||||||
|
const ro = new ResizeObserver(check);
|
||||||
|
ro.observe(el);
|
||||||
|
if (inner) ro.observe(inner);
|
||||||
|
return () => ro.disconnect();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={shell}
|
||||||
|
aria-busy={!ready}
|
||||||
|
aria-label={label}
|
||||||
|
tabIndex={scrollable ? 0 : undefined}
|
||||||
|
style={{ height: box }}
|
||||||
|
className={`relative grid overflow-y-auto overscroll-contain text-foreground ${className}`}
|
||||||
|
>
|
||||||
|
<motion.div
|
||||||
|
ref={body}
|
||||||
|
aria-hidden={showSkeleton || undefined}
|
||||||
|
inert={showSkeleton || undefined}
|
||||||
|
className="col-start-1 row-start-1 min-w-0"
|
||||||
|
initial={false}
|
||||||
|
animate={
|
||||||
|
reduced
|
||||||
|
? { opacity: showSkeleton ? 0 : 1 }
|
||||||
|
: {
|
||||||
|
opacity: showSkeleton ? 0 : 1,
|
||||||
|
scale: showSkeleton ? 0.99 : 1,
|
||||||
|
filter: showSkeleton ? 'blur(4px)' : 'blur(0px)',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transition={reduced ? { duration: 0 } : CROSSFADE}
|
||||||
|
style={{
|
||||||
|
transformOrigin: 'top left',
|
||||||
|
pointerEvents: showSkeleton ? 'none' : undefined,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</motion.div>
|
||||||
|
|
||||||
|
<AnimatePresence initial={false}>
|
||||||
|
{showSkeleton ? (
|
||||||
|
<motion.div
|
||||||
|
key="skeleton"
|
||||||
|
aria-hidden
|
||||||
|
className="pointer-events-none col-start-1 row-start-1 w-full self-start"
|
||||||
|
initial={reduced ? { opacity: 1 } : { opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
exit={reduced ? { opacity: 0 } : { opacity: 0, filter: 'blur(3px)' }}
|
||||||
|
transition={reduced ? { duration: 0 } : CROSSFADE}
|
||||||
|
>
|
||||||
|
{skeleton ?? (
|
||||||
|
<div className="w-full">
|
||||||
|
{Array.from({ length: lines }, (_, i) => (
|
||||||
|
<div
|
||||||
|
key={i}
|
||||||
|
className="flex items-center"
|
||||||
|
style={{ height: lineHeight }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rounded-[5px] bg-muted"
|
||||||
|
style={{
|
||||||
|
height: barHeight,
|
||||||
|
width: `${widthFor(i, lines)}%`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</motion.div>
|
||||||
|
) : null}
|
||||||
|
</AnimatePresence>
|
||||||
|
|
||||||
|
{label ? (
|
||||||
|
<span role="status" className="sr-only">
|
||||||
|
{ready ? `${label} loaded` : ''}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Bell, CheckCircle2, XCircle } from 'lucide-react';
|
import { Bell, CheckCircle2, XCircle } from 'lucide-react';
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
import { useTheme } from '@/contexts/ThemeContext';
|
import { useTheme } from '@/contexts/ThemeContext';
|
||||||
@@ -15,6 +16,7 @@ export function DeliveriesWidget() {
|
|||||||
const api = useApi();
|
const api = useApi();
|
||||||
const { formatClock } = useTheme();
|
const { formatClock } = useTheme();
|
||||||
const [records, setRecords] = useState<NotificationDeliveryRecord[] | null>(null);
|
const [records, setRecords] = useState<NotificationDeliveryRecord[] | null>(null);
|
||||||
|
const [loadError, setLoadError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let active = true;
|
let active = true;
|
||||||
@@ -27,10 +29,17 @@ export function DeliveriesWidget() {
|
|||||||
api.notifications
|
api.notifications
|
||||||
.recent(50)
|
.recent(50)
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
if (active) setRecords(r);
|
if (active) {
|
||||||
|
setLoadError(null);
|
||||||
|
setRecords(r);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((error) => {
|
||||||
if (active) setRecords((prev) => prev ?? []);
|
console.error('load recent notification deliveries failed', error);
|
||||||
|
if (active) {
|
||||||
|
setLoadError(error instanceof Error ? error.message : '加载最近投递失败');
|
||||||
|
setRecords((prev) => prev ?? []);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => { inFlight = false; });
|
.finally(() => { inFlight = false; });
|
||||||
};
|
};
|
||||||
@@ -55,8 +64,19 @@ export function DeliveriesWidget() {
|
|||||||
</CardTitle>
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="min-h-0 flex-1 overflow-auto">
|
<CardContent className="min-h-0 flex-1 overflow-auto">
|
||||||
{records === null ? (
|
<SkeletonSwap
|
||||||
<p className="py-10 text-center text-sm text-muted-foreground">加载中…</p>
|
ready={records !== null}
|
||||||
|
reserve={120}
|
||||||
|
lines={5}
|
||||||
|
lineHeight={24}
|
||||||
|
label="最近投递"
|
||||||
|
className={records !== null ? 'skeleton-swap-fluid min-h-[120px]' : ''}
|
||||||
|
>
|
||||||
|
{records !== null ? (
|
||||||
|
loadError && records.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>
|
||||||
) : records.length === 0 ? (
|
) : records.length === 0 ? (
|
||||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
<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} />
|
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||||
@@ -64,6 +84,11 @@ export function DeliveriesWidget() {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col gap-1 text-meta">
|
<div className="flex flex-col gap-1 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>
|
||||||
|
)}
|
||||||
{records.map((r, i) => (
|
{records.map((r, i) => (
|
||||||
<div key={i} className="flex items-center gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
<div key={i} className="flex items-center gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
||||||
{r.ok ? (
|
{r.ok ? (
|
||||||
@@ -88,7 +113,9 @@ export function DeliveriesWidget() {
|
|||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|||||||
import { motion } from 'motion/react';
|
import { motion } from 'motion/react';
|
||||||
import { Check, Loader2, MousePointerClick, Plus, Save } from 'lucide-react';
|
import { Check, Loader2, MousePointerClick, Plus, Save } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { ScrollableTabList } from '@/components/ui/tabs';
|
import { ScrollableTabList } from '@/components/ui/tabs';
|
||||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import type {
|
import type {
|
||||||
AdapterStatus,
|
AdapterStatus,
|
||||||
@@ -41,9 +41,19 @@ type DialogState =
|
|||||||
// index: null → create with `seed`, otherwise edit the item at that position.
|
// index: null → create with `seed`, otherwise edit the item at that position.
|
||||||
|
|
||||||
export function ConfigPage() {
|
export function ConfigPage() {
|
||||||
const { qqList, connections, selectedUin, setSelectedUin } = useAppState();
|
const {
|
||||||
|
qqList,
|
||||||
|
connections,
|
||||||
|
selectedUin,
|
||||||
|
setSelectedUin,
|
||||||
|
resources,
|
||||||
|
refreshQqList,
|
||||||
|
} = useAppState();
|
||||||
const {
|
const {
|
||||||
config,
|
config,
|
||||||
|
loading,
|
||||||
|
loadError,
|
||||||
|
reload,
|
||||||
setConfig,
|
setConfig,
|
||||||
dirty,
|
dirty,
|
||||||
requestSwitchUin,
|
requestSwitchUin,
|
||||||
@@ -57,7 +67,6 @@ export function ConfigPage() {
|
|||||||
selectedUin,
|
selectedUin,
|
||||||
onSelectedUinChange: setSelectedUin,
|
onSelectedUinChange: setSelectedUin,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { pages, setPages } = useLayout();
|
const { pages, setPages } = useLayout();
|
||||||
const [activeTab, setActiveTabState] = useState<TabKey>(() => {
|
const [activeTab, setActiveTabState] = useState<TabKey>(() => {
|
||||||
const t = pages.configTab;
|
const t = pages.configTab;
|
||||||
@@ -169,6 +178,25 @@ export function ConfigPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<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-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">
|
<div className="flex gap-4">
|
||||||
<AccountSidebar
|
<AccountSidebar
|
||||||
accounts={qqList}
|
accounts={qqList}
|
||||||
@@ -181,8 +209,19 @@ export function ConfigPage() {
|
|||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
{!selectedUin ? (
|
{!selectedUin ? (
|
||||||
<EmptyState />
|
<EmptyState />
|
||||||
) : !config ? (
|
) : (
|
||||||
<LoadingSkeleton />
|
<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">
|
<div className="flex flex-col gap-4">
|
||||||
<HeaderBar
|
<HeaderBar
|
||||||
@@ -223,6 +262,9 @@ export function ConfigPage() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -262,6 +304,10 @@ export function ConfigPage() {
|
|||||||
onConfirm={confirmSwitch}
|
onConfirm={confirmSwitch}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,13 +540,13 @@ function EmptyState() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function LoadingSkeleton() {
|
function ConfigLoadError({ message, onRetry }: { message: string; onRetry: () => void }) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-3">
|
<div className="flex h-64 flex-col items-center justify-center gap-3 rounded-xl border border-dashed text-muted-foreground">
|
||||||
<Skeleton className="h-9 w-48" />
|
<p className="max-w-md text-center text-sm text-destructive">{message}</p>
|
||||||
<Skeleton className="h-10" />
|
<Button variant="outline" size="sm" onClick={onRetry}>
|
||||||
<Skeleton className="h-20" />
|
重试
|
||||||
<Skeleton className="h-20" />
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { ActionTester } from '@/components/debug/action-tester';
|
|||||||
import { MessageComposer } from '@/components/debug/message-composer';
|
import { MessageComposer } from '@/components/debug/message-composer';
|
||||||
import { LiveActivity } from '@/components/debug/live-activity';
|
import { LiveActivity } from '@/components/debug/live-activity';
|
||||||
import { ApiBrowser } from '@/components/debug/api-browser';
|
import { ApiBrowser } from '@/components/debug/api-browser';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
import type { DebugActionDoc, QQInfo } from '@/types';
|
import type { DebugActionDoc, QQInfo } from '@/types';
|
||||||
|
|
||||||
@@ -20,6 +21,8 @@ export function DebugPage() {
|
|||||||
const api = useApi();
|
const api = useApi();
|
||||||
const [accounts, setAccounts] = useState<QQInfo[]>([]);
|
const [accounts, setAccounts] = useState<QQInfo[]>([]);
|
||||||
const [docs, setDocs] = useState<DebugActionDoc[]>([]);
|
const [docs, setDocs] = useState<DebugActionDoc[]>([]);
|
||||||
|
const [ready, setReady] = useState(false);
|
||||||
|
const [loadError, setLoadError] = useState<string | null>(null);
|
||||||
const [tab, setTab] = useState<Tab>('tester');
|
const [tab, setTab] = useState<Tab>('tester');
|
||||||
const [preset, setPreset] = useState<{ name: string; nonce: number } | undefined>();
|
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()]);
|
const [qq, acts] = await Promise.all([api.qqList(), api.debug.actions()]);
|
||||||
setAccounts(qq);
|
setAccounts(qq);
|
||||||
setDocs(acts.actions);
|
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]);
|
}, [api]);
|
||||||
|
|
||||||
@@ -66,6 +74,23 @@ export function DebugPage() {
|
|||||||
/>
|
/>
|
||||||
</motion.header>
|
</motion.header>
|
||||||
|
|
||||||
|
{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
|
{/* Tester / compose / activity stay MOUNTED and toggle via CSS so the
|
||||||
live feed's SSE never drops (it must capture events fired from other
|
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.
|
tabs) and in-progress params/messages survive a peek at another tab.
|
||||||
@@ -75,6 +100,9 @@ export function DebugPage() {
|
|||||||
<div className={cn(tab !== 'compose' && 'hidden')}><MessageComposer accounts={accounts} /></div>
|
<div className={cn(tab !== 'compose' && 'hidden')}><MessageComposer accounts={accounts} /></div>
|
||||||
<div className={cn(tab !== 'activity' && 'hidden')}><LiveActivity /></div>
|
<div className={cn(tab !== 'activity' && 'hidden')}><LiveActivity /></div>
|
||||||
{tab === 'api' && <ApiBrowser docs={docs} onTry={tryAction} />}
|
{tab === 'api' && <ApiBrowser docs={docs} onTry={tryAction} />}
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ import { Input } from '@/components/ui/input';
|
|||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
||||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import type { LogEntry, LogLevel, LogsPreset, UiHighlightRule } from '@/types';
|
import type { LogEntry, LogLevel, LogsPreset, UiHighlightRule } from '@/types';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
@@ -107,10 +108,14 @@ export function LogsPage() {
|
|||||||
const prefs = pages.logs;
|
const prefs = pages.logs;
|
||||||
|
|
||||||
const [logs, setLogs] = useState<LogEntry[]>([]);
|
const [logs, setLogs] = useState<LogEntry[]>([]);
|
||||||
|
const [logsReady, setLogsReady] = useState(false);
|
||||||
|
const [logsError, setLogsError] = useState<string | null>(null);
|
||||||
const [streamStatus, setStreamStatus] = useState('连接中');
|
const [streamStatus, setStreamStatus] = useState('连接中');
|
||||||
const [filter, setFilter] = useState('');
|
const [filter, setFilter] = useState('');
|
||||||
const [confirmClear, setConfirmClear] = useState(false);
|
const [confirmClear, setConfirmClear] = useState(false);
|
||||||
const [serverLevel, setServerLevel] = useState<LogLevel | null>(null);
|
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 [levelBusy, setLevelBusy] = useState(false);
|
||||||
const [confirmTrace, setConfirmTrace] = useState(false);
|
const [confirmTrace, setConfirmTrace] = useState(false);
|
||||||
const [traceExportBusy, setTraceExportBusy] = 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 enabled = useMemo(() => new Set(prefs.visibleLevels as LogLevel[]), [prefs.visibleLevels]);
|
||||||
|
|
||||||
const loadLogs = useCallback(async () => {
|
const loadLogs = useCallback(async () => {
|
||||||
|
setLogsError(null);
|
||||||
try {
|
try {
|
||||||
// Backfill is capped at the server's ring-buffer size (1000); `maxLines`
|
// 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.
|
// can exceed that, but only the live SSE stream grows the view past 1000.
|
||||||
setLogs(await api.logs.list(Math.min(1000, maxLinesRef.current)));
|
setLogs(await api.logs.list(Math.min(1000, maxLinesRef.current)));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('logs', e);
|
console.error('logs', e);
|
||||||
|
setLogsError(e instanceof Error ? e.message : '加载日志失败');
|
||||||
|
} finally {
|
||||||
|
setLogsReady(true);
|
||||||
}
|
}
|
||||||
}, [api]);
|
}, [api]);
|
||||||
|
|
||||||
useEffect(() => { void loadLogs(); }, [loadLogs]);
|
useEffect(() => { void loadLogs(); }, [loadLogs]);
|
||||||
|
|
||||||
useEffect(() => {
|
const loadServerLevel = useCallback(async () => {
|
||||||
api.logs.getLevel().then(({ level }) => setServerLevel(level)).catch((err) => {
|
setServerLevelReady(false);
|
||||||
console.error('getLevel', err);
|
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]);
|
}, [api]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadServerLevel();
|
||||||
|
}, [loadServerLevel]);
|
||||||
|
|
||||||
const applyServerLevel = useCallback(async (lv: LogLevel) => {
|
const applyServerLevel = useCallback(async (lv: LogLevel) => {
|
||||||
if (lv === serverLevel || levelBusy) return;
|
if (lv === serverLevel || levelBusy) return;
|
||||||
setLevelBusy(true);
|
setLevelBusy(true);
|
||||||
@@ -587,6 +608,24 @@ export function LogsPage() {
|
|||||||
<span className="text-xs font-medium text-foreground">服务端日志级别</span>
|
<span className="text-xs font-medium text-foreground">服务端日志级别</span>
|
||||||
<span className="text-xs text-muted-foreground">· 普通日志仅影响控制台 / 实时流;首次登录凭据始终可见;文件等级由环境变量决定,默认为 debug</span>
|
<span className="text-xs text-muted-foreground">· 普通日志仅影响控制台 / 实时流;首次登录凭据始终可见;文件等级由环境变量决定,默认为 debug</span>
|
||||||
</div>
|
</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">
|
<div className="inline-flex flex-wrap gap-1 rounded-lg bg-muted/60 p-1">
|
||||||
{LEVELS.map((lv) => {
|
{LEVELS.map((lv) => {
|
||||||
const active = serverLevel === lv;
|
const active = serverLevel === lv;
|
||||||
@@ -610,6 +649,9 @@ export function LogsPage() {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Highlight rules */}
|
{/* 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">
|
<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
|
{/* Column header lives OUTSIDE the scroll viewport so the virtualizer's
|
||||||
scroll element contains only the rows (no sticky-offset math). */}
|
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">
|
<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-[104px] shrink-0">时间</span>
|
||||||
<span className="w-[76px] shrink-0">级别</span>
|
<span className="w-[76px] shrink-0">级别</span>
|
||||||
@@ -682,9 +724,32 @@ export function LogsPage() {
|
|||||||
<span className="flex-1">消息</span>
|
<span className="flex-1">消息</span>
|
||||||
</div>
|
</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)}>
|
<ScrollArea viewportRef={scrollRef} className="min-h-0 flex-1" viewportClassName={cn('[&>div]:!block', maskCls)}>
|
||||||
|
<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">
|
<div className="font-mono text-xs">
|
||||||
{filtered.length === 0 ? (
|
{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">
|
<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 ? (
|
{logs.length === 0 ? (
|
||||||
<>
|
<>
|
||||||
@@ -751,6 +816,8 @@ export function LogsPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { Progress } from '@/components/ui/progress';
|
|||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
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 { cn, formatBytes, formatUptime } from '@/lib/utils';
|
||||||
import type { AppPath } from '@/router';
|
import type { AppPath } from '@/router';
|
||||||
import type {
|
import type {
|
||||||
@@ -64,7 +64,7 @@ function renderWidget(block: UiLayoutItem): ReactNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function OverviewPage() {
|
export function OverviewPage() {
|
||||||
const { qqList, processList } = useAppState();
|
const { qqList, processList, resources } = useAppState();
|
||||||
const {
|
const {
|
||||||
overviewBlocks, setOverviewBlocks, overviewMobile, setOverviewMobile,
|
overviewBlocks, setOverviewBlocks, overviewMobile, setOverviewMobile,
|
||||||
resetLayout, editing, setEditing,
|
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. */}
|
{/* 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 }}>
|
<motion.div initial={off ? false : { opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }}>
|
||||||
<Link
|
<Link
|
||||||
to="/processes"
|
to="/processes"
|
||||||
@@ -475,7 +475,7 @@ function shortDistro(distro: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function StatTile({
|
function StatTile({
|
||||||
icon, label, value, subtext, details, accent = false, to,
|
icon, label, value, subtext, details, accent = false, to, ready = true,
|
||||||
}: {
|
}: {
|
||||||
icon: ReactNode;
|
icon: ReactNode;
|
||||||
label: string;
|
label: string;
|
||||||
@@ -484,6 +484,7 @@ function StatTile({
|
|||||||
details?: string;
|
details?: string;
|
||||||
accent?: boolean;
|
accent?: boolean;
|
||||||
to?: AppPath;
|
to?: AppPath;
|
||||||
|
ready?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const copy = (
|
const copy = (
|
||||||
<>
|
<>
|
||||||
@@ -502,10 +503,32 @@ function StatTile({
|
|||||||
>
|
>
|
||||||
{icon}
|
{icon}
|
||||||
</div>
|
</div>
|
||||||
{details ? (
|
{details && ready ? (
|
||||||
<StatTileDetails label={label} details={details}>{copy}</StatTileDetails>
|
<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" />}
|
{to && <ArrowRight className="optical-forward size-4 shrink-0 text-muted-foreground/60" />}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
@@ -521,7 +544,7 @@ function StatTile({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function StatTileWidget({ id }: { id: string }) {
|
function StatTileWidget({ id }: { id: string }) {
|
||||||
const { qqList, processList, systemInfo } = useAppState();
|
const { qqList, processList, systemInfo, resources } = useAppState();
|
||||||
const { status } = useSession();
|
const { status } = useSession();
|
||||||
const online = status === '已连接';
|
const online = status === '已连接';
|
||||||
|
|
||||||
@@ -541,8 +564,11 @@ function StatTileWidget({ id }: { id: string }) {
|
|||||||
<StatTile
|
<StatTile
|
||||||
icon={<Users className="size-5" />}
|
icon={<Users className="size-5" />}
|
||||||
label="在线账号"
|
label="在线账号"
|
||||||
value={qqList.length}
|
ready={resources.qqList.ready}
|
||||||
subtext={`已接入 ${qqList.length} 个会话`}
|
value={resources.qqList.error && qqList.length === 0 ? '—' : qqList.length}
|
||||||
|
subtext={resources.qqList.error
|
||||||
|
? qqList.length > 0 ? '更新失败,显示上次数据' : '加载失败'
|
||||||
|
: `已接入 ${qqList.length} 个会话`}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'stat:processes': {
|
case 'stat:processes': {
|
||||||
@@ -552,19 +578,25 @@ function StatTileWidget({ id }: { id: string }) {
|
|||||||
<StatTile
|
<StatTile
|
||||||
icon={<PlugZap className="size-5" />}
|
icon={<PlugZap className="size-5" />}
|
||||||
label="进程注入"
|
label="进程注入"
|
||||||
value={`${onlineProcs} 在线`}
|
ready={resources.processList.ready}
|
||||||
subtext={`${processList.length} 进程 · ${loadableProcs} 可注入`}
|
value={resources.processList.error && processList.length === 0 ? '—' : `${onlineProcs} 在线`}
|
||||||
|
subtext={resources.processList.error
|
||||||
|
? processList.length > 0 ? '更新失败,显示上次数据' : '加载失败'
|
||||||
|
: `${processList.length} 进程 · ${loadableProcs} 可注入`}
|
||||||
to="/processes"
|
to="/processes"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case 'stat:host': {
|
case 'stat:host': {
|
||||||
const value = systemInfo?.hostname ?? '—';
|
const value = systemInfo?.hostname ?? '—';
|
||||||
const subtext = systemInfo ? `${shortDistro(systemInfo.distro)} · ${systemInfo.archLabel}` : '加载中';
|
const subtext = systemInfo
|
||||||
|
? `${shortDistro(systemInfo.distro)} · ${systemInfo.archLabel}`
|
||||||
|
: resources.systemInfo.error ? '加载失败' : '加载中';
|
||||||
return (
|
return (
|
||||||
<StatTile
|
<StatTile
|
||||||
icon={<Server className="size-5" />}
|
icon={<Server className="size-5" />}
|
||||||
label="主机名"
|
label="主机名"
|
||||||
|
ready={resources.systemInfo.ready}
|
||||||
value={value}
|
value={value}
|
||||||
subtext={subtext}
|
subtext={subtext}
|
||||||
details={systemInfo
|
details={systemInfo
|
||||||
@@ -580,6 +612,7 @@ function StatTileWidget({ id }: { id: string }) {
|
|||||||
<StatTile
|
<StatTile
|
||||||
icon={<MonitorCog className="size-5" />}
|
icon={<MonitorCog className="size-5" />}
|
||||||
label="系统运行"
|
label="系统运行"
|
||||||
|
ready={resources.systemInfo.ready}
|
||||||
value={systemUptime}
|
value={systemUptime}
|
||||||
subtext={processUptime ? `进程 ${processUptime}` : undefined}
|
subtext={processUptime ? `进程 ${processUptime}` : undefined}
|
||||||
details={processUptime
|
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' };
|
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 }) {
|
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;
|
const panelCount = [config.cpu, config.memory, config.runtime].filter(Boolean).length;
|
||||||
return (
|
return (
|
||||||
<Card className="flex h-full flex-col">
|
<Card className="flex h-full flex-col">
|
||||||
@@ -607,8 +640,10 @@ function HostBlock({ config }: { config: HostConfig }) {
|
|||||||
<CardTitle>主机资源</CardTitle>
|
<CardTitle>主机资源</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
{systemInfo
|
{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>
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
<Button variant="outline" size="sm" onClick={refreshSystem}>
|
<Button variant="outline" size="sm" onClick={refreshSystem}>
|
||||||
@@ -631,11 +666,22 @@ function HostBlock({ config }: { config: HostConfig }) {
|
|||||||
{systemInfo ? `${systemInfo.cpu.average.toFixed(1)}%` : '—'}
|
{systemInfo ? `${systemInfo.cpu.average.toFixed(1)}%` : '—'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<Progress value={systemInfo?.cpu.average ?? 0} />
|
<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">
|
<p className="mt-2 text-meta text-muted-foreground tabular-nums">
|
||||||
负载: {systemInfo ? systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ') : '—'}
|
负载: {systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ')}
|
||||||
</p>
|
</p>
|
||||||
{systemInfo && systemInfo.cpu.perCore.length > 0 && (
|
{systemInfo.cpu.perCore.length > 0 && (
|
||||||
<div
|
<div
|
||||||
className="mt-3 grid"
|
className="mt-3 grid"
|
||||||
style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(34px, 1fr))', gap: 3 }}
|
style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(34px, 1fr))', gap: 3 }}
|
||||||
@@ -659,6 +705,11 @@ function HostBlock({ config }: { config: HostConfig }) {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
</>
|
||||||
|
) : resources.systemInfo.error ? (
|
||||||
|
<p role="alert" className="text-xs text-destructive">{resources.systemInfo.error}</p>
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{/* Memory */}
|
{/* Memory */}
|
||||||
@@ -673,6 +724,15 @@ function HostBlock({ config }: { config: HostConfig }) {
|
|||||||
{systemInfo ? `${systemInfo.memory.usagePercent.toFixed(1)}%` : '—'}
|
{systemInfo ? `${systemInfo.memory.usagePercent.toFixed(1)}%` : '—'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<SkeletonSwap
|
||||||
|
ready={resources.systemInfo.ready}
|
||||||
|
reserve={72}
|
||||||
|
lines={3}
|
||||||
|
lineHeight={24}
|
||||||
|
barHeight={9}
|
||||||
|
label="内存使用"
|
||||||
|
className="skeleton-swap-fluid min-h-[72px]"
|
||||||
|
>
|
||||||
{systemInfo ? (() => {
|
{systemInfo ? (() => {
|
||||||
const m = systemInfo.memory;
|
const m = systemInfo.memory;
|
||||||
const rss = Math.min(systemInfo.runtime.rss, m.used);
|
const rss = Math.min(systemInfo.runtime.rss, m.used);
|
||||||
@@ -705,7 +765,10 @@ function HostBlock({ config }: { config: HostConfig }) {
|
|||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
})() : <Progress value={0} />}
|
})() : resources.systemInfo.error ? (
|
||||||
|
<p role="alert" className="text-xs text-destructive">{resources.systemInfo.error}</p>
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{/* Runtime */}
|
{/* Runtime */}
|
||||||
@@ -720,12 +783,16 @@ function HostBlock({ config }: { config: HostConfig }) {
|
|||||||
{systemInfo ? `PID ${systemInfo.runtime.pid}` : '—'}
|
{systemInfo ? `PID ${systemInfo.runtime.pid}` : '—'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{!systemInfo ? (
|
<SkeletonSwap
|
||||||
<div className="space-y-2">
|
ready={resources.systemInfo.ready}
|
||||||
<Skeleton className="h-4 w-3/4" />
|
reserve={88}
|
||||||
<Skeleton className="h-4 w-1/2" />
|
lines={3}
|
||||||
</div>
|
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="space-y-1.5 text-xs">
|
||||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
<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="text-muted-foreground">RSS</span>
|
||||||
@@ -742,7 +809,10 @@ function HostBlock({ config }: { config: HostConfig }) {
|
|||||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.external)}</span>
|
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.external)}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
) : resources.systemInfo.error ? (
|
||||||
|
<p role="alert" className="text-xs text-destructive">{resources.systemInfo.error}</p>
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
@@ -753,7 +823,7 @@ function HostBlock({ config }: { config: HostConfig }) {
|
|||||||
// ─────────────── online sessions ───────────────
|
// ─────────────── online sessions ───────────────
|
||||||
|
|
||||||
function SessionsBlock({ config }: { config: SessionsConfig }) {
|
function SessionsBlock({ config }: { config: SessionsConfig }) {
|
||||||
const { qqList } = useAppState();
|
const { qqList, resources } = useAppState();
|
||||||
const off = useTheme().appearance.disableMotion;
|
const off = useTheme().appearance.disableMotion;
|
||||||
const list = useMemo(() => {
|
const list = useMemo(() => {
|
||||||
const f = config.filter.trim().toLowerCase();
|
const f = config.filter.trim().toLowerCase();
|
||||||
@@ -775,12 +845,32 @@ function SessionsBlock({ config }: { config: SessionsConfig }) {
|
|||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="min-h-0 flex-1">
|
<CardContent className="min-h-0 flex-1">
|
||||||
{list.length === 0 ? (
|
<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">
|
<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} />
|
<Users className="size-8 opacity-40" strokeWidth={1.5} />
|
||||||
<p className="text-sm">{qqList.length === 0 ? '暂无在线会话' : '无匹配的会话'}</p>
|
<p className="text-sm">{qqList.length === 0 ? '暂无在线会话' : '无匹配的会话'}</p>
|
||||||
</div>
|
</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">
|
<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">
|
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
||||||
{list.map((q, idx) => (
|
{list.map((q, idx) => (
|
||||||
@@ -805,7 +895,10 @@ function SessionsBlock({ config }: { config: SessionsConfig }) {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
)}
|
</div>
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
@@ -837,7 +930,7 @@ const CONN_STATUS_RANK: Record<AdapterStatusLevel, number> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
||||||
const { connections } = useAppState();
|
const { connections, resources } = useAppState();
|
||||||
const list = useMemo(() => {
|
const list = useMemo(() => {
|
||||||
const f = config.filter.trim().toLowerCase();
|
const f = config.filter.trim().toLowerCase();
|
||||||
// Optionally drop healthy adapters, then accounts left with none.
|
// Optionally drop healthy adapters, then accounts left with none.
|
||||||
@@ -869,13 +962,32 @@ function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
|||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="min-h-0 flex-1 overflow-auto">
|
<CardContent className="min-h-0 flex-1 overflow-auto">
|
||||||
{list.length === 0 ? (
|
<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">
|
<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} />
|
<Cable className="size-8 opacity-40" strokeWidth={1.5} />
|
||||||
<p className="text-sm">{filtered ? '无匹配的连接' : '暂无已接入的账号实例'}</p>
|
<p className="text-sm">{filtered ? '无匹配的连接' : '暂无已接入的账号实例'}</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col gap-4">
|
<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) => (
|
{list.map((acc) => (
|
||||||
<div key={acc.uin} className="flex flex-col gap-2">
|
<div key={acc.uin} className="flex flex-col gap-2">
|
||||||
<div className="flex items-baseline gap-2">
|
<div className="flex items-baseline gap-2">
|
||||||
@@ -913,7 +1025,9 @@ function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
|||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
@@ -1013,7 +1127,7 @@ function LinkWidget({ config }: { config: LinkConfig }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function AccountWidget({ config }: { config: AccountConfig }) {
|
function AccountWidget({ config }: { config: AccountConfig }) {
|
||||||
const { qqList } = useAppState();
|
const { qqList, resources } = useAppState();
|
||||||
const acct = qqList.find((q) => q.uin === config.uin);
|
const acct = qqList.find((q) => q.uin === config.uin);
|
||||||
if (!config.uin) {
|
if (!config.uin) {
|
||||||
return (
|
return (
|
||||||
@@ -1027,20 +1141,34 @@ function AccountWidget({ config }: { config: AccountConfig }) {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Card className="h-full overflow-hidden">
|
<Card className="h-full overflow-hidden">
|
||||||
|
<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">
|
<CardContent className="flex h-full items-center gap-3 p-4">
|
||||||
<Avatar size={40}>
|
<Avatar size={40}>
|
||||||
<AvatarImage src={qqAvatarUrl(config.uin)} alt={acct?.nickname || config.uin} />
|
<AvatarImage src={qqAvatarUrl(config.uin)} alt={acct?.nickname || config.uin} />
|
||||||
<AvatarFallback>{(acct?.nickname || config.uin).slice(0, 2)}</AvatarFallback>
|
<AvatarFallback>{(acct?.nickname || config.uin).slice(0, 2)}</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
<p className="truncate text-sm font-semibold">{acct?.nickname || '未接入账号'}</p>
|
<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>
|
<p className="truncate font-mono text-meta text-muted-foreground tabular-nums">{config.uin}</p>
|
||||||
</div>
|
</div>
|
||||||
<span
|
<span
|
||||||
title={acct ? '在线' : '未接入'}
|
title={acct ? '在线' : resources.qqList.error ? '状态未知' : '未接入'}
|
||||||
className={cn('size-2 shrink-0 rounded-full', acct ? 'bg-success' : 'bg-muted-foreground/40')}
|
className={cn('size-2 shrink-0 rounded-full', acct ? 'bg-success' : 'bg-muted-foreground/40')}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1062,24 +1190,32 @@ const ALERT_LEVEL_CLASS: Record<LogLevel, string> = {
|
|||||||
function RecentAlertsCard({ config }: { config: AlertsConfig }) {
|
function RecentAlertsCard({ config }: { config: AlertsConfig }) {
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
const { formatClock } = useTheme();
|
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 { count } = config;
|
||||||
const levelsKey = config.levels.join(',');
|
const levelsKey = config.levels.join(',');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const levels = new Set(levelsKey.split(',') as LogLevel[]);
|
const levels = new Set(levelsKey.split(',') as LogLevel[]);
|
||||||
let active = true;
|
let active = true;
|
||||||
|
setAlerts(null);
|
||||||
|
setLoadError(null);
|
||||||
api.logs
|
api.logs
|
||||||
.list(Math.max(200, count * 4))
|
.list(Math.max(200, count * 4))
|
||||||
.then((list) => {
|
.then((list) => {
|
||||||
if (!active) return;
|
if (!active) return;
|
||||||
setAlerts(list.filter((l) => levels.has(l.level)).slice(-count));
|
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({
|
const stop = api.logs.stream({
|
||||||
onLine: (entry) => {
|
onLine: (entry) => {
|
||||||
if (!levels.has(entry.level)) return;
|
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(); };
|
return () => { active = false; stop(); };
|
||||||
@@ -1099,13 +1235,32 @@ function RecentAlertsCard({ config }: { config: AlertsConfig }) {
|
|||||||
</Link>
|
</Link>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="min-h-0 flex-1 overflow-auto">
|
<CardContent className="min-h-0 flex-1 overflow-auto">
|
||||||
{alerts.length === 0 ? (
|
<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">
|
<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} />
|
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||||
<p className="text-sm">暂无告警</p>
|
<p className="text-sm">暂无告警</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col gap-1 font-mono text-meta">
|
<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) => (
|
{alerts.map((a) => (
|
||||||
<div key={a.id} className="flex gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
<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="shrink-0 text-muted-foreground tabular-nums">{formatClock(a.time)}</span>
|
||||||
@@ -1116,7 +1271,9 @@ function RecentAlertsCard({ config }: { config: AlertsConfig }) {
|
|||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
|||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||||
import { ProcessProbeDialog } from '@/components/process-probe-dialog';
|
import { ProcessProbeDialog } from '@/components/process-probe-dialog';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import type { HookProcessInfo } from '@/types';
|
import type { HookProcessInfo } from '@/types';
|
||||||
import { useAppState } from '@/contexts/AppStateContext';
|
import { useAppState } from '@/contexts/AppStateContext';
|
||||||
@@ -48,7 +49,7 @@ function processBadgeVariant(status: HookProcessInfo['status']) {
|
|||||||
* regardless of which page is mounted.
|
* regardless of which page is mounted.
|
||||||
*/
|
*/
|
||||||
export function ProcessesPage() {
|
export function ProcessesPage() {
|
||||||
const { processList, processOps, refreshProcesses } = useAppState();
|
const { processList, processOps, refreshProcesses, resources } = useAppState();
|
||||||
const { statusOf, banner: processActionStatus, load, unload, refresh } = processOps;
|
const { statusOf, banner: processActionStatus, load, unload, refresh } = processOps;
|
||||||
const { pages, setPages } = useLayout();
|
const { pages, setPages } = useLayout();
|
||||||
const off = useTheme().appearance.disableMotion;
|
const off = useTheme().appearance.disableMotion;
|
||||||
@@ -95,7 +96,12 @@ export function ProcessesPage() {
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<Button variant="outline" size="sm" onClick={refreshProcesses}>
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={refreshProcesses}
|
||||||
|
disabled={!resources.processList.ready}
|
||||||
|
>
|
||||||
<RefreshCw className="size-3.5" /> 刷新
|
<RefreshCw className="size-3.5" /> 刷新
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -111,7 +117,30 @@ export function ProcessesPage() {
|
|||||||
{processActionStatus}
|
{processActionStatus}
|
||||||
</motion.div>
|
</motion.div>
|
||||||
)}
|
)}
|
||||||
{processList.length === 0 ? (
|
{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">
|
<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} />
|
<Cpu className="size-8 opacity-40" strokeWidth={1.5} />
|
||||||
<p className="text-sm">未检测到可加载 QQ 主进程</p>
|
<p className="text-sm">未检测到可加载 QQ 主进程</p>
|
||||||
@@ -233,7 +262,9 @@ export function ProcessesPage() {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import { NAV_ITEMS } from '@/components/layout/sidebar';
|
|||||||
import { TOPBAR_CATALOGUE } from '@/components/layout/top-bar';
|
import { TOPBAR_CATALOGUE } from '@/components/layout/top-bar';
|
||||||
import { ChangePasswordDialog } from '@/components/change-password-dialog';
|
import { ChangePasswordDialog } from '@/components/change-password-dialog';
|
||||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
import { useAppState } from '@/contexts/AppStateContext';
|
import { useAppState } from '@/contexts/AppStateContext';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
@@ -739,6 +740,7 @@ function FontField({
|
|||||||
const listId = useId();
|
const listId = useId();
|
||||||
const [fonts, setFonts] = useState<string[] | null>(null);
|
const [fonts, setFonts] = useState<string[] | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [fontLoadError, setFontLoadError] = useState<string | null>(null);
|
||||||
const canQuery = typeof (window as FontQueryWindow).queryLocalFonts === 'function';
|
const canQuery = typeof (window as FontQueryWindow).queryLocalFonts === 'function';
|
||||||
const isCustom = value === FONT_CUSTOM_ID;
|
const isCustom = value === FONT_CUSTOM_ID;
|
||||||
|
|
||||||
@@ -747,16 +749,17 @@ function FontField({
|
|||||||
{ value: FONT_CUSTOM_ID, label: '自定义' },
|
{ value: FONT_CUSTOM_ID, label: '自定义' },
|
||||||
];
|
];
|
||||||
|
|
||||||
// Lazily enumerate local fonts the first time the field is focused. A denied
|
// Lazily enumerate local fonts the first time the field is focused.
|
||||||
// permission (or any failure) just leaves the plain text box — no error UI.
|
|
||||||
const loadFonts = async () => {
|
const loadFonts = async () => {
|
||||||
if (fonts !== null || loading || !canQuery) return;
|
if (fonts !== null || loading || !canQuery) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
setFontLoadError(null);
|
||||||
try {
|
try {
|
||||||
const arr = await (window as FontQueryWindow).queryLocalFonts!();
|
const arr = await (window as FontQueryWindow).queryLocalFonts!();
|
||||||
setFonts(Array.from(new Set(arr.map((f) => f.family))).sort((x, y) => x.localeCompare(y)));
|
setFonts(Array.from(new Set(arr.map((f) => f.family))).sort((x, y) => x.localeCompare(y)));
|
||||||
} catch {
|
} catch (error) {
|
||||||
setFonts([]);
|
console.error('Failed to enumerate local fonts', error);
|
||||||
|
setFontLoadError('无法读取本机字体,请检查浏览器权限后重试。');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -784,11 +787,32 @@ function FontField({
|
|||||||
{fonts.map((f) => <option key={f} value={f} />)}
|
{fonts.map((f) => <option key={f} value={f} />)}
|
||||||
</datalist>
|
</datalist>
|
||||||
)}
|
)}
|
||||||
|
<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">
|
<p className="text-xs leading-snug text-muted-foreground">
|
||||||
{canQuery
|
{canQuery
|
||||||
? '可输入字体名称,或聚焦后从已安装字体中选择;找不到时回退到系统字体。'
|
? '可输入字体名称,或聚焦后从已安装字体中选择;找不到时回退到系统字体。'
|
||||||
: '输入已安装的字体名称(可写多个,用逗号分隔);找不到时回退到系统字体。'}
|
: '输入已安装的字体名称(可写多个,用逗号分隔);找不到时回退到系统字体。'}
|
||||||
</p>
|
</p>
|
||||||
|
)}
|
||||||
|
</SkeletonSwap>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</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
|
// Advisory software update, shown as a grouped list. Read-only: links to the
|
||||||
// GitHub release; SnowLuma never downloads or applies anything itself.
|
// GitHub release; SnowLuma never downloads or applies anything itself.
|
||||||
function UpdateGroup() {
|
function UpdateGroup() {
|
||||||
const { updateInfo, refreshUpdate, systemInfo } = useAppState();
|
const { updateInfo, refreshUpdate, systemInfo, resources } = useAppState();
|
||||||
const { runAction } = useActionFeedback();
|
const { runAction } = useActionFeedback();
|
||||||
const [checking, setChecking] = useState(false);
|
const [checking, setChecking] = useState(false);
|
||||||
|
|
||||||
@@ -1286,7 +1310,8 @@ function UpdateGroup() {
|
|||||||
const disabledCheck = updateInfo?.error === 'disabled';
|
const disabledCheck = updateInfo?.error === 'disabled';
|
||||||
|
|
||||||
let status: ReactNode;
|
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 (disabledCheck) status = <span className="text-muted-foreground">检查已关闭</span>;
|
||||||
else if (updateInfo.error) 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>;
|
else if (updateInfo.hasUpdate && updateInfo.latest) status = <span className="font-medium text-primary">发现新版本</span>;
|
||||||
@@ -1337,7 +1362,17 @@ function UpdateGroup() {
|
|||||||
</SettingRow>
|
</SettingRow>
|
||||||
<SettingRow label="检查更新">
|
<SettingRow label="检查更新">
|
||||||
<div className="flex items-center gap-2.5 text-[12px]">
|
<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 && (
|
{!disabledCheck && (
|
||||||
<Button variant="outline" size="sm" onClick={onCheck} disabled={checking}>
|
<Button variant="outline" size="sm" onClick={onCheck} disabled={checking}>
|
||||||
{checking ? <Loader2 className="size-4 animate-spin" /> : <RefreshCw className="size-4" />}
|
{checking ? <Loader2 className="size-4 animate-spin" /> : <RefreshCw className="size-4" />}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { Eye, Loader2, User, UserX } from 'lucide-react';
|
import { Eye, User, UserX } from 'lucide-react';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -92,20 +93,21 @@ export function ProcessProbeDialog({ pid, processName, open, onOpenChange, onLoa
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{loading && (
|
<SkeletonSwap
|
||||||
<div className="flex items-center justify-center py-8">
|
ready={!loading}
|
||||||
<Loader2 className="size-6 animate-spin text-muted-foreground" />
|
reserve={128}
|
||||||
</div>
|
lines={5}
|
||||||
)}
|
lineHeight={24}
|
||||||
|
label="登录状态"
|
||||||
{!loading && error && (
|
className={!loading ? 'skeleton-swap-fluid min-h-32' : ''}
|
||||||
|
>
|
||||||
|
{!loading ? (
|
||||||
|
error ? (
|
||||||
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-8 text-muted-foreground">
|
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-8 text-muted-foreground">
|
||||||
<UserX className="size-8" strokeWidth={1.5} />
|
<UserX className="size-8" strokeWidth={1.5} />
|
||||||
<p className="text-sm">{error}</p>
|
<p className="text-sm">{error}</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
) : info ? (
|
||||||
|
|
||||||
{!loading && info && (
|
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{info.loggedIn ? (
|
{info.loggedIn ? (
|
||||||
<div className="flex items-center gap-4 rounded-lg border bg-card/50 p-4">
|
<div className="flex items-center gap-4 rounded-lg border bg-card/50 p-4">
|
||||||
@@ -139,7 +141,9 @@ export function ProcessProbeDialog({ pid, processName, open, onOpenChange, onLoa
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
) : null
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
|
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button variant="outline" size="sm" onClick={() => onOpenChange(false)}>
|
<Button variant="outline" size="sm" onClick={() => onOpenChange(false)}>
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
// URL); the store reconciles on the next load. Invalid entries are flagged
|
// URL); the store reconciles on the next load. Invalid entries are flagged
|
||||||
// client-side and simply dropped by the server on save.
|
// client-side and simply dropped by the server on save.
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { AlertTriangle, KeyRound, Loader2, Music, Plus, RefreshCw, Trash2 } from 'lucide-react';
|
import { AlertTriangle, KeyRound, Music, Plus, RefreshCw, Trash2 } from 'lucide-react';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
@@ -42,7 +43,8 @@ export function GlobalConfigPanel() {
|
|||||||
setLoadFailed(false);
|
setLoadFailed(false);
|
||||||
try {
|
try {
|
||||||
setConfig(await api.globalConfig.get());
|
setConfig(await api.globalConfig.get());
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.error('load global config failed', error);
|
||||||
setLoadFailed(true);
|
setLoadFailed(true);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -103,16 +105,17 @@ export function GlobalConfigPanel() {
|
|||||||
}, 500);
|
}, 500);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (loading) {
|
if (loading || !config) {
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-2 rounded-lg border bg-card/40 p-6 text-sm text-muted-foreground">
|
|
||||||
<Loader2 className="size-4 animate-spin" /> 加载中…
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loadFailed || !config) {
|
|
||||||
return (
|
return (
|
||||||
|
<SkeletonSwap
|
||||||
|
ready={!loading}
|
||||||
|
lines={6}
|
||||||
|
lineHeight={26}
|
||||||
|
reserve={156}
|
||||||
|
label="全局配置"
|
||||||
|
className={!loading ? 'skeleton-swap-fluid min-h-[156px]' : ''}
|
||||||
|
>
|
||||||
|
{!loading && (loadFailed || !config) ? (
|
||||||
<div className="flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16 text-muted-foreground">
|
<div className="flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||||
<AlertTriangle className="size-8 opacity-40" strokeWidth={1.5} />
|
<AlertTriangle className="size-8 opacity-40" strokeWidth={1.5} />
|
||||||
<p className="text-sm">加载全局配置失败</p>
|
<p className="text-sm">加载全局配置失败</p>
|
||||||
@@ -120,6 +123,8 @@ export function GlobalConfigPanel() {
|
|||||||
<RefreshCw className="size-3.5" /> 重试
|
<RefreshCw className="size-3.5" /> 重试
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +133,14 @@ export function GlobalConfigPanel() {
|
|||||||
commit({ ...config, rkey: { fallbackServers: next } }, false);
|
commit({ ...config, rkey: { fallbackServers: next } }, false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<SkeletonSwap
|
||||||
|
ready
|
||||||
|
lines={6}
|
||||||
|
lineHeight={26}
|
||||||
|
reserve={156}
|
||||||
|
label="全局配置"
|
||||||
|
className="skeleton-swap-fluid min-h-[156px]"
|
||||||
|
>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
{/* rkey fallback servers */}
|
{/* rkey fallback servers */}
|
||||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||||
@@ -224,5 +237,6 @@ export function GlobalConfigPanel() {
|
|||||||
|
|
||||||
{msg && <p className={cn('text-xs', msg.kind === 'ok' ? 'text-success' : 'text-destructive')}>{msg.text}</p>}
|
{msg && <p className={cn('text-xs', msg.kind === 'ok' ? 'text-success' : 'text-destructive')}>{msg.text}</p>}
|
||||||
</div>
|
</div>
|
||||||
|
</SkeletonSwap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2,11 +2,12 @@
|
|||||||
// info-only cards (name / url / template + an inline enable toggle); creating
|
// info-only cards (name / url / template + an inline enable toggle); creating
|
||||||
// and editing always go through a dialog. All changes auto-save (debounced),
|
// and editing always go through a dialog. All changes auto-save (debounced),
|
||||||
// like the per-account config page — no explicit save button.
|
// like the per-account config page — no explicit save button.
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { motion } from 'motion/react';
|
import { motion } from 'motion/react';
|
||||||
import { Bell, Loader2, Pencil, Plus, Send, Trash2 } from 'lucide-react';
|
import { Bell, Loader2, Pencil, Plus, Send, Trash2 } from 'lucide-react';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||||
@@ -48,23 +49,22 @@ export function NotificationsPanel() {
|
|||||||
const saveTimer = useRef<number | null>(null);
|
const saveTimer = useRef<number | null>(null);
|
||||||
const saveGen = useRef(0);
|
const saveGen = useRef(0);
|
||||||
|
|
||||||
useEffect(() => {
|
const load = useCallback(async () => {
|
||||||
let cancelled = false;
|
setLoading(true);
|
||||||
void (async () => {
|
|
||||||
try {
|
try {
|
||||||
const cfg = await api.notifications.getConfig();
|
setConfig(await api.notifications.getConfig());
|
||||||
if (!cancelled) setConfig(cfg);
|
} catch (error) {
|
||||||
} catch {
|
console.error('load notifications config failed', error);
|
||||||
if (!cancelled) setMsg({ kind: 'err', text: '加载通知配置失败' });
|
setMsg({ kind: 'err', text: '加载通知配置失败' });
|
||||||
} finally {
|
} finally {
|
||||||
if (!cancelled) setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
})();
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, [api, setMsg]);
|
}, [api, setMsg]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load();
|
||||||
|
}, [load]);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => {
|
||||||
if (saveTimer.current) clearTimeout(saveTimer.current);
|
if (saveTimer.current) clearTimeout(saveTimer.current);
|
||||||
@@ -111,9 +111,23 @@ export function NotificationsPanel() {
|
|||||||
|
|
||||||
if (loading || !config) {
|
if (loading || !config) {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2 rounded-lg border bg-card/40 p-6 text-sm text-muted-foreground">
|
<SkeletonSwap
|
||||||
<Loader2 className="size-4 animate-spin" /> 加载中…
|
ready={!loading}
|
||||||
|
lines={6}
|
||||||
|
lineHeight={26}
|
||||||
|
reserve={156}
|
||||||
|
label="通知配置"
|
||||||
|
className={!loading ? 'skeleton-swap-fluid min-h-[156px]' : ''}
|
||||||
|
>
|
||||||
|
{!loading && !config ? (
|
||||||
|
<div role="alert" className="flex items-center justify-between gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-sm text-destructive">
|
||||||
|
<span>{msg?.text ?? '加载通知配置失败'}</span>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => void load()}>
|
||||||
|
重试
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,6 +186,14 @@ export function NotificationsPanel() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<SkeletonSwap
|
||||||
|
ready
|
||||||
|
lines={6}
|
||||||
|
lineHeight={26}
|
||||||
|
reserve={156}
|
||||||
|
label="通知配置"
|
||||||
|
className="skeleton-swap-fluid min-h-[156px]"
|
||||||
|
>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
{/* Global settings */}
|
{/* Global settings */}
|
||||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||||
@@ -255,6 +277,7 @@ export function NotificationsPanel() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</SkeletonSwap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { Label } from '@/components/ui/label';
|
|||||||
import { Progress } from '@/components/ui/progress';
|
import { Progress } from '@/components/ui/progress';
|
||||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
import { useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
||||||
import { useFlashMessage } from '@/hooks/use-flash-message';
|
import { useFlashMessage } from '@/hooks/use-flash-message';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
@@ -107,12 +108,16 @@ export function StoragePanel() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const load = async (showSpinner = false): Promise<boolean> => {
|
const load = async (showSpinner = false): Promise<boolean> => {
|
||||||
if (showSpinner) setRefreshing(true);
|
if (showSpinner) {
|
||||||
|
if (data === null) setLoading(true);
|
||||||
|
else setRefreshing(true);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const overview = await api.storage.get();
|
const overview = await api.storage.get();
|
||||||
applyOverview(overview);
|
applyOverview(overview);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('load storage overview failed', error);
|
||||||
setMsg({
|
setMsg({
|
||||||
kind: 'err',
|
kind: 'err',
|
||||||
text: error instanceof Error ? error.message : '加载存储信息失败',
|
text: error instanceof Error ? error.message : '加载存储信息失败',
|
||||||
@@ -222,17 +227,17 @@ export function StoragePanel() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (loading) {
|
if (loading || !data) {
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-2 px-1 py-8 text-sm text-muted-foreground">
|
|
||||||
<Loader2 className="size-4 animate-spin" />
|
|
||||||
加载存储信息…
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
return (
|
return (
|
||||||
|
<SkeletonSwap
|
||||||
|
ready={!loading}
|
||||||
|
lines={7}
|
||||||
|
lineHeight={26}
|
||||||
|
reserve={182}
|
||||||
|
label="存储信息"
|
||||||
|
className={!loading ? 'skeleton-swap-fluid min-h-[182px]' : ''}
|
||||||
|
>
|
||||||
|
{!loading && !data ? (
|
||||||
<Card>
|
<Card>
|
||||||
<CardContent className="flex flex-col items-start gap-3 pt-5">
|
<CardContent className="flex flex-col items-start gap-3 pt-5">
|
||||||
<p className="text-sm text-muted-foreground">存储信息暂时不可用。</p>
|
<p className="text-sm text-muted-foreground">存储信息暂时不可用。</p>
|
||||||
@@ -242,6 +247,8 @@ export function StoragePanel() {
|
|||||||
</Button>
|
</Button>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,6 +266,14 @@ export function StoragePanel() {
|
|||||||
) as Record<AccountStorageCategory, number>;
|
) as Record<AccountStorageCategory, number>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<SkeletonSwap
|
||||||
|
ready
|
||||||
|
lines={7}
|
||||||
|
lineHeight={26}
|
||||||
|
reserve={182}
|
||||||
|
label="存储信息"
|
||||||
|
className="skeleton-swap-fluid min-h-[182px]"
|
||||||
|
>
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
{msg && (
|
{msg && (
|
||||||
<div
|
<div
|
||||||
@@ -563,6 +578,7 @@ export function StoragePanel() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</SkeletonSwap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { motion } from 'motion/react';
|
|||||||
import { AlertTriangle, Database, Download, Loader2, Lock, Pencil, Save, ShieldCheck, Trash2, Upload } from 'lucide-react';
|
import { AlertTriangle, Database, Download, Loader2, Lock, Pencil, Save, ShieldCheck, Trash2, Upload } from 'lucide-react';
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
@@ -57,7 +58,8 @@ export function SystemPanel() {
|
|||||||
setTrustProxy(res.settings.trustProxy);
|
setTrustProxy(res.settings.trustProxy);
|
||||||
setTlsEnabled(res.settings.tlsEnabled);
|
setTlsEnabled(res.settings.tlsEnabled);
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.error('load system settings failed', error);
|
||||||
setMsg({ kind: 'err', text: '加载系统设置失败' });
|
setMsg({ kind: 'err', text: '加载系统设置失败' });
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -211,8 +213,33 @@ export function SystemPanel() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (loading) {
|
if (loading || !data) {
|
||||||
return <div className="flex items-center gap-2 px-1 py-8 text-sm text-muted-foreground"><Loader2 className="h-4 w-4 animate-spin" /> 加载中…</div>;
|
return (
|
||||||
|
<SkeletonSwap
|
||||||
|
ready={!loading}
|
||||||
|
lines={7}
|
||||||
|
lineHeight={26}
|
||||||
|
reserve={182}
|
||||||
|
label="系统设置"
|
||||||
|
className={!loading ? 'skeleton-swap-fluid min-h-[182px]' : ''}
|
||||||
|
>
|
||||||
|
{!loading && !data ? (
|
||||||
|
<div role="alert" className="flex items-center justify-between gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-sm text-destructive">
|
||||||
|
<span>{msg?.text ?? '加载系统设置失败'}</span>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setLoading(true);
|
||||||
|
void load();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重试
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const EnvBadge = ({ field }: { field: string }) =>
|
const EnvBadge = ({ field }: { field: string }) =>
|
||||||
@@ -221,6 +248,14 @@ export function SystemPanel() {
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<SkeletonSwap
|
||||||
|
ready
|
||||||
|
lines={7}
|
||||||
|
lineHeight={26}
|
||||||
|
reserve={182}
|
||||||
|
label="系统设置"
|
||||||
|
className="skeleton-swap-fluid min-h-[182px]"
|
||||||
|
>
|
||||||
<motion.div initial={{ opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} className="flex flex-col gap-5">
|
<motion.div initial={{ opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} className="flex flex-col gap-5">
|
||||||
{/* restart-to-apply notice */}
|
{/* restart-to-apply notice */}
|
||||||
<div className="flex items-start gap-2 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300">
|
<div className="flex items-start gap-2 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300">
|
||||||
@@ -406,5 +441,6 @@ export function SystemPanel() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
</SkeletonSwap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,8 @@
|
|||||||
// the raw-value input so the picker never traps you.
|
// the raw-value input so the picker never traps you.
|
||||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { AnimatePresence, motion } from 'motion/react';
|
import { AnimatePresence, motion } from 'motion/react';
|
||||||
import { ChevronDown, Loader2, RefreshCw, Search } from 'lucide-react';
|
import { ChevronDown, RefreshCw, Search } from 'lucide-react';
|
||||||
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
export interface PickerOption {
|
export interface PickerOption {
|
||||||
@@ -51,6 +52,7 @@ export function Picker({
|
|||||||
const listRef = useRef<HTMLDivElement>(null);
|
const listRef = useRef<HTMLDivElement>(null);
|
||||||
const searchRef = useRef<HTMLInputElement>(null);
|
const searchRef = useRef<HTMLInputElement>(null);
|
||||||
const suppressTriggerClick = useRef(false);
|
const suppressTriggerClick = useRef(false);
|
||||||
|
const waitingForOptions = Boolean(loading && options.length === 0);
|
||||||
|
|
||||||
const selected = options.find((o) => o.value === value);
|
const selected = options.find((o) => o.value === value);
|
||||||
|
|
||||||
@@ -177,11 +179,16 @@ export function Picker({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{loading && options.length === 0 ? (
|
<SkeletonSwap
|
||||||
<div className="flex items-center justify-center gap-2 py-8 text-sm text-muted-foreground">
|
ready={!waitingForOptions}
|
||||||
<Loader2 className="h-4 w-4 animate-spin" /> 加载中…
|
lines={4}
|
||||||
</div>
|
lineHeight={28}
|
||||||
) : error ? (
|
reserve={112}
|
||||||
|
label={ariaLabel}
|
||||||
|
className={waitingForOptions ? 'mx-3 my-2' : 'skeleton-swap-fluid'}
|
||||||
|
>
|
||||||
|
{!waitingForOptions ? (
|
||||||
|
error ? (
|
||||||
<div className="px-3 py-6 text-center text-xs text-muted-foreground">
|
<div className="px-3 py-6 text-center text-xs text-muted-foreground">
|
||||||
<p className="text-destructive">{error}</p>
|
<p className="text-destructive">{error}</p>
|
||||||
<p className="mt-1">可直接在上方输入号码后回车使用</p>
|
<p className="mt-1">可直接在上方输入号码后回车使用</p>
|
||||||
@@ -229,7 +236,9 @@ export function Picker({
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)
|
||||||
|
) : null}
|
||||||
|
</SkeletonSwap>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
)}
|
)}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
|
|||||||
@@ -2,6 +2,19 @@ import { createContext, useContext, type ReactNode } from 'react';
|
|||||||
import type { AccountConnections, HookProcessInfo, QQInfo, SystemInfo, UpdateInfo } from '@/types';
|
import type { AccountConnections, HookProcessInfo, QQInfo, SystemInfo, UpdateInfo } from '@/types';
|
||||||
import type { HookProcessOps } from '@/hooks/use-hook-process-ops';
|
import type { HookProcessOps } from '@/hooks/use-hook-process-ops';
|
||||||
|
|
||||||
|
export interface ResourceLoadState {
|
||||||
|
ready: boolean;
|
||||||
|
error: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AppResourceState {
|
||||||
|
qqList: ResourceLoadState;
|
||||||
|
processList: ResourceLoadState;
|
||||||
|
systemInfo: ResourceLoadState;
|
||||||
|
connections: ResourceLoadState;
|
||||||
|
updateInfo: ResourceLoadState;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Live mutable state owned by AppLayout and shared with the child route
|
* Live mutable state owned by AppLayout and shared with the child route
|
||||||
* components rendered inside its `<Outlet />`. Pages used to receive these
|
* components rendered inside its `<Outlet />`. Pages used to receive these
|
||||||
@@ -15,9 +28,12 @@ export interface AppStateValue {
|
|||||||
connections: AccountConnections[];
|
connections: AccountConnections[];
|
||||||
/** Advisory update-availability info; null until the first check resolves. */
|
/** Advisory update-availability info; null until the first check resolves. */
|
||||||
updateInfo: UpdateInfo | null;
|
updateInfo: UpdateInfo | null;
|
||||||
|
/** Distinguishes an empty result from an unresolved or failed initial read. */
|
||||||
|
resources: AppResourceState;
|
||||||
selectedUin: string | null;
|
selectedUin: string | null;
|
||||||
setSelectedUin: (uin: string | null) => void;
|
setSelectedUin: (uin: string | null) => void;
|
||||||
processOps: HookProcessOps;
|
processOps: HookProcessOps;
|
||||||
|
refreshQqList: () => void;
|
||||||
refreshProcesses: () => void;
|
refreshProcesses: () => void;
|
||||||
refreshSystem: () => void;
|
refreshSystem: () => void;
|
||||||
refreshConnections: () => void;
|
refreshConnections: () => void;
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ export interface UseOneBotInstanceConfig {
|
|||||||
selectedUin: string | null;
|
selectedUin: string | null;
|
||||||
/** Loaded config for the current UIN. Null while loading or before a selection. */
|
/** Loaded config for the current UIN. Null while loading or before a selection. */
|
||||||
config: OneBotConfig | null;
|
config: OneBotConfig | null;
|
||||||
|
loading: boolean;
|
||||||
|
loadError: string | null;
|
||||||
|
reload: () => void;
|
||||||
setConfig: (next: OneBotConfig) => void;
|
setConfig: (next: OneBotConfig) => void;
|
||||||
/** True if the in-memory config diverges from the last server-confirmed snapshot. */
|
/** True if the in-memory config diverges from the last server-confirmed snapshot. */
|
||||||
dirty: boolean;
|
dirty: boolean;
|
||||||
@@ -54,6 +57,10 @@ export function useOneBotInstanceConfig(
|
|||||||
const { runAction } = useActionFeedback();
|
const { runAction } = useActionFeedback();
|
||||||
const { selectedUin, onSelectedUinChange } = options;
|
const { selectedUin, onSelectedUinChange } = options;
|
||||||
const [config, setConfigState] = useState<OneBotConfig | null>(null);
|
const [config, setConfigState] = useState<OneBotConfig | null>(null);
|
||||||
|
const [loadedUin, setLoadedUin] = useState<string | null>(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [loadError, setLoadError] = useState<string | null>(null);
|
||||||
|
const [reloadGeneration, setReloadGeneration] = useState(0);
|
||||||
const [savedSnapshot, setSavedSnapshot] = useState<string | null>(null);
|
const [savedSnapshot, setSavedSnapshot] = useState<string | null>(null);
|
||||||
const [saveStatus, setSaveStatus] = useState('');
|
const [saveStatus, setSaveStatus] = useState('');
|
||||||
const [saveStatusTone, setSaveStatusTone] = useState<UseOneBotInstanceConfig['saveStatusTone']>('idle');
|
const [saveStatusTone, setSaveStatusTone] = useState<UseOneBotInstanceConfig['saveStatusTone']>('idle');
|
||||||
@@ -80,10 +87,18 @@ export function useOneBotInstanceConfig(
|
|||||||
setSaveStatus('');
|
setSaveStatus('');
|
||||||
setSaveStatusTone('idle');
|
setSaveStatusTone('idle');
|
||||||
if (!selectedUin) {
|
if (!selectedUin) {
|
||||||
|
setLoading(false);
|
||||||
|
setLoadError(null);
|
||||||
setConfigState(null);
|
setConfigState(null);
|
||||||
|
setLoadedUin(null);
|
||||||
setSavedSnapshot(null);
|
setSavedSnapshot(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setLoading(true);
|
||||||
|
setLoadError(null);
|
||||||
|
setConfigState(null);
|
||||||
|
setLoadedUin(null);
|
||||||
|
setSavedSnapshot(null);
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -91,15 +106,21 @@ export function useOneBotInstanceConfig(
|
|||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
editRevisionRef.current += 1;
|
editRevisionRef.current += 1;
|
||||||
setConfigState(loaded);
|
setConfigState(loaded);
|
||||||
|
setLoadedUin(selectedUin);
|
||||||
setSavedSnapshot(JSON.stringify(loaded));
|
setSavedSnapshot(JSON.stringify(loaded));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('load-config', e);
|
console.error('load-config', e);
|
||||||
|
if (!cancelled) {
|
||||||
|
setLoadError(e instanceof Error ? e.message : '加载账号配置失败');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (!cancelled) setLoading(false);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [selectedUin, api]);
|
}, [selectedUin, api, reloadGeneration]);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => {
|
||||||
@@ -108,15 +129,20 @@ export function useOneBotInstanceConfig(
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const currentConfig = loadedUin === selectedUin ? config : null;
|
||||||
|
const currentLoading = selectedUin !== null
|
||||||
|
&& (loading || (loadError === null && currentConfig === null));
|
||||||
|
|
||||||
const dirty = useMemo(() => {
|
const dirty = useMemo(() => {
|
||||||
if (config == null || savedSnapshot == null) return false;
|
if (currentConfig == null || savedSnapshot == null) return false;
|
||||||
return JSON.stringify(config) !== savedSnapshot;
|
return JSON.stringify(currentConfig) !== savedSnapshot;
|
||||||
}, [config, savedSnapshot]);
|
}, [currentConfig, savedSnapshot]);
|
||||||
|
|
||||||
const setConfig = useCallback((next: OneBotConfig) => {
|
const setConfig = useCallback((next: OneBotConfig) => {
|
||||||
editRevisionRef.current += 1;
|
editRevisionRef.current += 1;
|
||||||
setConfigState(next);
|
setConfigState(next);
|
||||||
}, []);
|
}, []);
|
||||||
|
const reload = useCallback(() => setReloadGeneration((generation) => generation + 1), []);
|
||||||
|
|
||||||
const requestSwitchUin = useCallback(
|
const requestSwitchUin = useCallback(
|
||||||
(uin: string) => {
|
(uin: string) => {
|
||||||
@@ -146,7 +172,7 @@ export function useOneBotInstanceConfig(
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const save = useCallback(async (override?: OneBotConfig) => {
|
const save = useCallback(async (override?: OneBotConfig) => {
|
||||||
const target = override ?? config;
|
const target = override ?? currentConfig;
|
||||||
if (!selectedUin || !target) return;
|
if (!selectedUin || !target) return;
|
||||||
const uin = selectedUin;
|
const uin = selectedUin;
|
||||||
const editRevision = editRevisionRef.current;
|
const editRevision = editRevisionRef.current;
|
||||||
@@ -211,11 +237,14 @@ export function useOneBotInstanceConfig(
|
|||||||
scheduleStatusClear(uin, generation);
|
scheduleStatusClear(uin, generation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [api, selectedUin, config, scheduleStatusClear, runAction]);
|
}, [api, selectedUin, currentConfig, scheduleStatusClear, runAction]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selectedUin,
|
selectedUin,
|
||||||
config,
|
config: currentConfig,
|
||||||
|
loading: currentLoading,
|
||||||
|
loadError,
|
||||||
|
reload,
|
||||||
setConfig,
|
setConfig,
|
||||||
dirty,
|
dirty,
|
||||||
requestSwitchUin,
|
requestSwitchUin,
|
||||||
|
|||||||
@@ -219,6 +219,19 @@
|
|||||||
box-shadow: var(--shadow-card);
|
box-shadow: var(--shadow-card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Skeleton Swap reserves a fixed box by default. Data panels that can grow
|
||||||
|
after the swap keep the original timing/motion but release that box once
|
||||||
|
real content is present, so the component never becomes an inner scroller. */
|
||||||
|
.skeleton-swap-fluid {
|
||||||
|
height: auto !important;
|
||||||
|
overflow-y: visible !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skeleton-swap-fill {
|
||||||
|
height: 100% !important;
|
||||||
|
overflow-y: visible !important;
|
||||||
|
}
|
||||||
|
|
||||||
/* Triangles and forward-pointing glyphs carry more visual mass on the left.
|
/* Triangles and forward-pointing glyphs carry more visual mass on the left.
|
||||||
A one-pixel optical correction centers them without changing hit areas. */
|
A one-pixel optical correction centers them without changing hit areas. */
|
||||||
.optical-forward {
|
.optical-forward {
|
||||||
|
|||||||
@@ -6,14 +6,45 @@ import { useHookProcessOps } from '@/hooks/use-hook-process-ops';
|
|||||||
import { MainLayout } from '@/components/layout/main-layout';
|
import { MainLayout } from '@/components/layout/main-layout';
|
||||||
import { NAV_ITEMS } from '@/components/layout/sidebar';
|
import { NAV_ITEMS } from '@/components/layout/sidebar';
|
||||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { AppStateProvider } from '@/contexts/AppStateContext';
|
import { AppStateProvider, type AppResourceState } from '@/contexts/AppStateContext';
|
||||||
import { KioskProvider } from '@/contexts/KioskContext';
|
import { KioskProvider } from '@/contexts/KioskContext';
|
||||||
import { LayoutProvider, useLayout } from '@/contexts/LayoutContext';
|
import { LayoutProvider, useLayout } from '@/contexts/LayoutContext';
|
||||||
import { useSession } from '@/contexts/SessionContext';
|
import { useSession } from '@/contexts/SessionContext';
|
||||||
import type { AppPath } from '@/router';
|
import type { AppPath } from '@/router';
|
||||||
import type { AccountConnections, HookProcessInfo, QQInfo, SystemInfo, UpdateInfo } from '@/types';
|
import type { AccountConnections, HookProcessInfo, QQInfo, SystemInfo, UpdateInfo } from '@/types';
|
||||||
|
|
||||||
|
function createInitialResources(): AppResourceState {
|
||||||
|
return {
|
||||||
|
qqList: { ready: false, error: null },
|
||||||
|
processList: { ready: false, error: null },
|
||||||
|
systemInfo: { ready: false, error: null },
|
||||||
|
connections: { ready: false, error: null },
|
||||||
|
updateInfo: { ready: false, error: null },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppResourceKey = keyof AppResourceState;
|
||||||
|
|
||||||
|
function createResourceCounters(): Record<AppResourceKey, number> {
|
||||||
|
return {
|
||||||
|
qqList: 0,
|
||||||
|
processList: 0,
|
||||||
|
systemInfo: 0,
|
||||||
|
connections: 0,
|
||||||
|
updateInfo: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ResourceRequestTicket {
|
||||||
|
generation: number;
|
||||||
|
streamRevision: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function errorMessage(error: unknown, fallback: string): string {
|
||||||
|
return error instanceof Error && error.message ? error.message : fallback;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirects to the operator's configured landing page once (after the layout
|
* Redirects to the operator's configured landing page once (after the layout
|
||||||
* config loads), but only when arriving at the root and the target is a real,
|
* config loads), but only when arriving at the root and the target is a real,
|
||||||
@@ -58,51 +89,126 @@ export function AppLayout() {
|
|||||||
const [systemInfo, setSystemInfo] = useState<SystemInfo | null>(null);
|
const [systemInfo, setSystemInfo] = useState<SystemInfo | null>(null);
|
||||||
const [connections, setConnections] = useState<AccountConnections[]>([]);
|
const [connections, setConnections] = useState<AccountConnections[]>([]);
|
||||||
const [updateInfo, setUpdateInfo] = useState<UpdateInfo | null>(null);
|
const [updateInfo, setUpdateInfo] = useState<UpdateInfo | null>(null);
|
||||||
|
const [resources, setResources] = useState<AppResourceState>(createInitialResources);
|
||||||
const [selectedUin, setSelectedUin] = useState<string | null>(null);
|
const [selectedUin, setSelectedUin] = useState<string | null>(null);
|
||||||
|
const requestGenerationRef = useRef(createResourceCounters());
|
||||||
|
const streamRevisionRef = useRef(createResourceCounters());
|
||||||
|
|
||||||
|
const settleResource = useCallback((
|
||||||
|
resource: AppResourceKey,
|
||||||
|
error: string | null,
|
||||||
|
) => {
|
||||||
|
setResources((current) => ({
|
||||||
|
...current,
|
||||||
|
[resource]: { ready: true, error },
|
||||||
|
}));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const beginResourceRequest = useCallback((resource: AppResourceKey): ResourceRequestTicket => ({
|
||||||
|
generation: ++requestGenerationRef.current[resource],
|
||||||
|
streamRevision: streamRevisionRef.current[resource],
|
||||||
|
}), []);
|
||||||
|
|
||||||
|
const isCurrentResourceRequest = useCallback((
|
||||||
|
resource: AppResourceKey,
|
||||||
|
ticket: ResourceRequestTicket,
|
||||||
|
): boolean => (
|
||||||
|
requestGenerationRef.current[resource] === ticket.generation
|
||||||
|
&& streamRevisionRef.current[resource] === ticket.streamRevision
|
||||||
|
), []);
|
||||||
|
|
||||||
|
const settleStreamResource = useCallback((resource: AppResourceKey) => {
|
||||||
|
streamRevisionRef.current[resource] += 1;
|
||||||
|
settleResource(resource, null);
|
||||||
|
}, [settleResource]);
|
||||||
|
|
||||||
const refreshQqList = useCallback(async () => {
|
const refreshQqList = useCallback(async () => {
|
||||||
|
const ticket = beginResourceRequest('qqList');
|
||||||
try {
|
try {
|
||||||
setQqList(await api.qqList());
|
const next = await api.qqList();
|
||||||
|
if (!isCurrentResourceRequest('qqList', ticket)) return;
|
||||||
|
setQqList(next);
|
||||||
|
settleResource('qqList', null);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('qq-list', e);
|
if (!isCurrentResourceRequest('qqList', ticket)) {
|
||||||
|
console.warn('ignored stale qq-list request failure', e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, [api]);
|
console.error('qq-list', e);
|
||||||
|
settleResource('qqList', errorMessage(e, '加载账号列表失败'));
|
||||||
|
}
|
||||||
|
}, [api, beginResourceRequest, isCurrentResourceRequest, settleResource]);
|
||||||
|
|
||||||
const refreshProcesses = useCallback(async () => {
|
const refreshProcesses = useCallback(async () => {
|
||||||
|
const ticket = beginResourceRequest('processList');
|
||||||
try {
|
try {
|
||||||
setProcessList(await api.processes.list());
|
const next = await api.processes.list();
|
||||||
|
if (!isCurrentResourceRequest('processList', ticket)) return;
|
||||||
|
setProcessList(next);
|
||||||
|
settleResource('processList', null);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('processes', e);
|
if (!isCurrentResourceRequest('processList', ticket)) {
|
||||||
|
console.warn('ignored stale process-list request failure', e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, [api]);
|
console.error('processes', e);
|
||||||
|
settleResource('processList', errorMessage(e, '加载进程列表失败'));
|
||||||
|
}
|
||||||
|
}, [api, beginResourceRequest, isCurrentResourceRequest, settleResource]);
|
||||||
|
|
||||||
const refreshSystem = useCallback(async () => {
|
const refreshSystem = useCallback(async () => {
|
||||||
|
const ticket = beginResourceRequest('systemInfo');
|
||||||
try {
|
try {
|
||||||
setSystemInfo(await api.system());
|
const next = await api.system();
|
||||||
|
if (!isCurrentResourceRequest('systemInfo', ticket)) return;
|
||||||
|
setSystemInfo(next);
|
||||||
|
settleResource('systemInfo', null);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('system', e);
|
if (!isCurrentResourceRequest('systemInfo', ticket)) {
|
||||||
|
console.warn('ignored stale system-info request failure', e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, [api]);
|
console.error('system', e);
|
||||||
|
settleResource('systemInfo', errorMessage(e, '加载系统信息失败'));
|
||||||
|
}
|
||||||
|
}, [api, beginResourceRequest, isCurrentResourceRequest, settleResource]);
|
||||||
|
|
||||||
const refreshConnections = useCallback(async () => {
|
const refreshConnections = useCallback(async () => {
|
||||||
|
const ticket = beginResourceRequest('connections');
|
||||||
try {
|
try {
|
||||||
setConnections(await api.connections());
|
const next = await api.connections();
|
||||||
|
if (!isCurrentResourceRequest('connections', ticket)) return;
|
||||||
|
setConnections(next);
|
||||||
|
settleResource('connections', null);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('connections', e);
|
if (!isCurrentResourceRequest('connections', ticket)) {
|
||||||
|
console.warn('ignored stale connections request failure', e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, [api]);
|
console.error('connections', e);
|
||||||
|
settleResource('connections', errorMessage(e, '加载连接状态失败'));
|
||||||
|
}
|
||||||
|
}, [api, beginResourceRequest, isCurrentResourceRequest, settleResource]);
|
||||||
|
|
||||||
const refreshUpdate = useCallback(async (force = false) => {
|
const refreshUpdate = useCallback(async (force = false) => {
|
||||||
|
const ticket = beginResourceRequest('updateInfo');
|
||||||
try {
|
try {
|
||||||
const next = await api.update.check(force);
|
const next = await api.update.check(force);
|
||||||
|
if (!isCurrentResourceRequest('updateInfo', ticket)) return null;
|
||||||
setUpdateInfo(next);
|
setUpdateInfo(next);
|
||||||
|
settleResource('updateInfo', null);
|
||||||
return next;
|
return next;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (!isCurrentResourceRequest('updateInfo', ticket)) {
|
||||||
|
console.warn('ignored stale update-check request failure', e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
console.error('update-check', e);
|
console.error('update-check', e);
|
||||||
|
settleResource('updateInfo', errorMessage(e, '检查更新失败'));
|
||||||
if (force) throw e;
|
if (force) throw e;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, [api]);
|
}, [api, beginResourceRequest, isCurrentResourceRequest, settleResource]);
|
||||||
|
|
||||||
const { ops: processOps, unloadFailedAlert, dismissUnloadFailedAlert } = useHookProcessOps({
|
const { ops: processOps, unloadFailedAlert, dismissUnloadFailedAlert } = useHookProcessOps({
|
||||||
onAfterOp: refreshProcesses,
|
onAfterOp: refreshProcesses,
|
||||||
@@ -121,9 +227,16 @@ export function AppLayout() {
|
|||||||
const dispose = api.stateStream({
|
const dispose = api.stateStream({
|
||||||
onEvent: (event) => {
|
onEvent: (event) => {
|
||||||
if ('resource' in event) {
|
if ('resource' in event) {
|
||||||
if (event.resource === 'processes') setProcessList(event.data);
|
if (event.resource === 'processes') {
|
||||||
else if (event.resource === 'qq-list') setQqList(event.data);
|
setProcessList(event.data);
|
||||||
else if (event.resource === 'connections') setConnections(event.data);
|
settleStreamResource('processList');
|
||||||
|
} else if (event.resource === 'qq-list') {
|
||||||
|
setQqList(event.data);
|
||||||
|
settleStreamResource('qqList');
|
||||||
|
} else if (event.resource === 'connections') {
|
||||||
|
setConnections(event.data);
|
||||||
|
settleStreamResource('connections');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ('kind' in event && event.kind === 'dropped') {
|
if ('kind' in event && event.kind === 'dropped') {
|
||||||
@@ -135,14 +248,13 @@ export function AppLayout() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
return () => { dispose(); };
|
return () => { dispose(); };
|
||||||
}, [api, refreshQqList, refreshProcesses, refreshConnections]);
|
}, [api, refreshQqList, refreshProcesses, refreshConnections, settleStreamResource]);
|
||||||
|
|
||||||
// Slow reconcile fallback for the SSE-covered resources. SSE drops can
|
// Slow reconcile fallback for the SSE-covered resources. SSE drops can
|
||||||
// be silent (proxy rewrites text/event-stream, tab thrashing). One REST
|
// be silent (proxy rewrites text/event-stream, tab thrashing). One REST
|
||||||
// tick per (pollInterval × 10, min 10s) recovers from those without
|
// tick per (pollInterval × 10, min 10s) recovers from those without
|
||||||
// hammering the server.
|
// hammering the server.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (pollInterval <= 0) return;
|
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
let running = false;
|
let running = false;
|
||||||
const reconcileMs = Math.max(pollInterval * 10, 10_000);
|
const reconcileMs = Math.max(pollInterval * 10, 10_000);
|
||||||
@@ -162,12 +274,12 @@ export function AppLayout() {
|
|||||||
// Initial tick primes the lists before the SSE handshake completes
|
// Initial tick primes the lists before the SSE handshake completes
|
||||||
// (avoids a flash of empty state in the chrome).
|
// (avoids a flash of empty state in the chrome).
|
||||||
tick();
|
tick();
|
||||||
const interval = setInterval(tick, reconcileMs);
|
const interval = pollInterval > 0 ? setInterval(tick, reconcileMs) : null;
|
||||||
const onVisible = () => { if (!document.hidden) void tick(); };
|
const onVisible = () => { if (!document.hidden) void tick(); };
|
||||||
document.addEventListener('visibilitychange', onVisible);
|
document.addEventListener('visibilitychange', onVisible);
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
clearInterval(interval);
|
if (interval !== null) clearInterval(interval);
|
||||||
document.removeEventListener('visibilitychange', onVisible);
|
document.removeEventListener('visibilitychange', onVisible);
|
||||||
};
|
};
|
||||||
}, [pollInterval, refreshQqList, refreshProcesses, refreshConnections]);
|
}, [pollInterval, refreshQqList, refreshProcesses, refreshConnections]);
|
||||||
@@ -178,7 +290,6 @@ export function AppLayout() {
|
|||||||
// would visibly lag the dashboard. Keep the user's configured
|
// would visibly lag the dashboard. Keep the user's configured
|
||||||
// pollInterval (default 3s) here.
|
// pollInterval (default 3s) here.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (pollInterval <= 0) return;
|
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
let running = false;
|
let running = false;
|
||||||
const tick = async () => {
|
const tick = async () => {
|
||||||
@@ -187,12 +298,12 @@ export function AppLayout() {
|
|||||||
try { await refreshSystem(); } finally { running = false; }
|
try { await refreshSystem(); } finally { running = false; }
|
||||||
};
|
};
|
||||||
tick();
|
tick();
|
||||||
const interval = setInterval(tick, pollInterval);
|
const interval = pollInterval > 0 ? setInterval(tick, pollInterval) : null;
|
||||||
const onVisible = () => { if (!document.hidden) void tick(); };
|
const onVisible = () => { if (!document.hidden) void tick(); };
|
||||||
document.addEventListener('visibilitychange', onVisible);
|
document.addEventListener('visibilitychange', onVisible);
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
clearInterval(interval);
|
if (interval !== null) clearInterval(interval);
|
||||||
document.removeEventListener('visibilitychange', onVisible);
|
document.removeEventListener('visibilitychange', onVisible);
|
||||||
};
|
};
|
||||||
}, [pollInterval, refreshSystem]);
|
}, [pollInterval, refreshSystem]);
|
||||||
@@ -213,12 +324,17 @@ export function AppLayout() {
|
|||||||
}, [refreshUpdate]);
|
}, [refreshUpdate]);
|
||||||
|
|
||||||
const handleLogout = useCallback(async () => {
|
const handleLogout = useCallback(async () => {
|
||||||
|
for (const resource of Object.keys(requestGenerationRef.current) as AppResourceKey[]) {
|
||||||
|
requestGenerationRef.current[resource] += 1;
|
||||||
|
streamRevisionRef.current[resource] += 1;
|
||||||
|
}
|
||||||
await api.logout();
|
await api.logout();
|
||||||
setQqList([]);
|
setQqList([]);
|
||||||
setProcessList([]);
|
setProcessList([]);
|
||||||
setSystemInfo(null);
|
setSystemInfo(null);
|
||||||
setConnections([]);
|
setConnections([]);
|
||||||
setUpdateInfo(null);
|
setUpdateInfo(null);
|
||||||
|
setResources(createInitialResources());
|
||||||
setSelectedUin(null);
|
setSelectedUin(null);
|
||||||
session.onLogoutComplete();
|
session.onLogoutComplete();
|
||||||
}, [api, session]);
|
}, [api, session]);
|
||||||
@@ -262,9 +378,11 @@ export function AppLayout() {
|
|||||||
systemInfo,
|
systemInfo,
|
||||||
connections,
|
connections,
|
||||||
updateInfo,
|
updateInfo,
|
||||||
|
resources,
|
||||||
selectedUin,
|
selectedUin,
|
||||||
setSelectedUin,
|
setSelectedUin,
|
||||||
processOps,
|
processOps,
|
||||||
|
refreshQqList,
|
||||||
refreshProcesses,
|
refreshProcesses,
|
||||||
refreshSystem,
|
refreshSystem,
|
||||||
refreshConnections,
|
refreshConnections,
|
||||||
@@ -310,17 +428,17 @@ export function AppLayout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function PageFallback() {
|
function PageFallback() {
|
||||||
// Generic page placeholder. Kept intentionally low-detail (just a
|
|
||||||
// header + a couple of card-shaped blocks) so it works for every
|
|
||||||
// route — overview's stat grid, config's tabbed editor, logs' list,
|
|
||||||
// and the settings page all converge on roughly this skeleton on
|
|
||||||
// their own loading states.
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-4">
|
<SkeletonSwap
|
||||||
<Skeleton className="h-9 w-48" />
|
ready={false}
|
||||||
<Skeleton className="h-10" />
|
lines={7}
|
||||||
<Skeleton className="h-32" />
|
lineHeight={28}
|
||||||
<Skeleton className="h-32" />
|
barHeight={11}
|
||||||
</div>
|
reserve={196}
|
||||||
|
label="页面内容"
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
{null}
|
||||||
|
</SkeletonSwap>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { renderToStaticMarkup } from 'react-dom/server';
|
||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { SkeletonSwap } from '../src/components/interior/skeleton-swap';
|
||||||
|
|
||||||
|
describe('SkeletonSwap', () => {
|
||||||
|
it('reserves the requested space without painting a skeleton immediately', () => {
|
||||||
|
const html = renderToStaticMarkup(
|
||||||
|
<SkeletonSwap ready={false} reserve={84} lines={4} label="测试内容">
|
||||||
|
<div>尚未就绪</div>
|
||||||
|
</SkeletonSwap>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(html).toContain('aria-busy="true"');
|
||||||
|
expect(html).toContain('height:84px');
|
||||||
|
expect(html).toContain('尚未就绪');
|
||||||
|
expect(html).not.toContain('aria-hidden="true"');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('exposes ready content without a loading announcement', () => {
|
||||||
|
const html = renderToStaticMarkup(
|
||||||
|
<SkeletonSwap ready label="测试内容">
|
||||||
|
<div>内容已加载</div>
|
||||||
|
</SkeletonSwap>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(html).toContain('aria-busy="false"');
|
||||||
|
expect(html).toContain('内容已加载');
|
||||||
|
expect(html).toContain('测试内容 loaded');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user