feat(webui): add developer settings tools

Expose onboarding replay and page crash testing from a dedicated settings page.\n\nKeep replay actions isolated from persisted consent and password state.
This commit is contained in:
DrSmoothl committed 2026-08-01 00:40:44 +08:00
1 parent 8080104311
commit 958d17ecc0
11 files changed
+365 -29

No files matched your search

@@ -1,4 +1,4 @@
import { createContext, useContext, useId, useRef, useState, type ComponentProps, type ReactNode } from 'react';
import { createContext, useContext, useId, useReducer, useRef, useState, type ComponentProps, type ReactNode } from 'react';
import { motion } from 'motion/react';
import {
Accessibility, AlertTriangle, Bell, Bug, Check, Clock, Code2, Download, ExternalLink, Github, Image as ImageIcon,
@@ -34,6 +34,7 @@ import {
} from '@/contexts/ThemeContext';
import { DEFAULT_LAYOUT, DEFAULT_PAGES, reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext';
import { useActionFeedback } from '@/contexts/ActionFeedbackContext';
import { useSession } from '@/contexts/SessionContext';
import { NAV_ITEMS } from '@/components/layout/sidebar';
import { TOPBAR_CATALOGUE } from '@/components/layout/top-bar';
import { ChangePasswordDialog } from '@/components/change-password-dialog';
@@ -48,6 +49,10 @@ import { NotificationsPanel } from '@/components/settings/notifications-panel';
import { GlobalConfigPanel } from '@/components/settings/global-config-panel';
import { SystemPanel } from '@/components/settings/system-panel';
import { StoragePanel } from '@/components/settings/storage-panel';
import {
DeveloperCrashProbe,
developerCrashReducer,
} from '@/components/settings/developer-tools';
interface TabDef { key: SettingsTab; label: string; icon: typeof Sun }
@@ -77,6 +82,7 @@ const TAB_GROUPS: { title: string; tabs: TabDef[] }[] = [
tabs: [
{ key: 'system', label: '服务', icon: Server },
{ key: 'advanced', label: '高级', icon: Code2 },
{ key: 'developer', label: '开发者', icon: Bug },
{ key: 'about', label: '关于', icon: Info },
],
},
@@ -115,6 +121,7 @@ export function SettingsPage() {
{tab === 'storage' && <StoragePanel />}
{tab === 'notifications' && <NotificationsPanel />}
{tab === 'globalConfig' && <GlobalConfigPanel />}
{tab === 'developer' && <DeveloperPanel />}
{tab === 'about' && <AboutPanel />}
</motion.div>
</div>
@@ -1254,6 +1261,63 @@ function AccountPanel() {
);
}
// ─────────────── 开发者 ───────────────
function DeveloperPanel() {
const { restartOnboarding } = useSession();
const [confirmOnboarding, setConfirmOnboarding] = useState(false);
const [confirmCrash, setConfirmCrash] = useState(false);
const [crashRequested, requestCrash] = useReducer(developerCrashReducer, false);
return (
<div className="flex flex-col gap-5">
{/* Event-handler errors bypass React boundaries; the probe throws on render. */}
<DeveloperCrashProbe requested={crashRequested} />
<Group
title="界面测试"
icon={Bug}
description="直接验证首次使用流程与页面级异常恢复;这些工具始终可见,不受环境开关限制。"
>
<SettingRow
label="首次使用引导"
hint="以演练模式重新进入完整引导,不会修改协议确认记录或真实访问密码。"
>
<Button variant="outline" size="sm" onClick={() => setConfirmOnboarding(true)}>
<RotateCcw className="size-4" /> 重新进入
</Button>
</SettingRow>
<SettingRow
label="崩溃界面"
hint="主动抛出测试异常并交给页面错误边界;在崩溃界面点击“重试”即可返回。"
>
<Button variant="destructive" size="sm" onClick={() => setConfirmCrash(true)}>
<AlertTriangle className="size-4" /> 触发崩溃
</Button>
</SettingRow>
</Group>
<ConfirmDialog
open={confirmOnboarding}
onOpenChange={setConfirmOnboarding}
title="重新进入首次使用引导?"
description="将以演练模式展示完整流程,不会修改协议确认记录或真实访问密码。"
confirmText="进入引导"
onConfirm={restartOnboarding}
/>
<ConfirmDialog
open={confirmCrash}
onOpenChange={setConfirmCrash}
title="触发 WebUI 崩溃测试?"
description="当前设置页面将主动抛出测试异常,并交由崩溃界面接管。"
confirmText="触发崩溃"
destructive
onConfirm={() => requestCrash('confirm')}
/>
</div>
);
}
// ─────────────── 关于 ───────────────
const REPO_URL = 'https://github.com/SnowLuma/SnowLuma';
@@ -0,0 +1,19 @@
export const DEVELOPER_CRASH_MESSAGE = '开发者工具主动触发的 WebUI 崩溃测试';
/** Throws the deliberate render-time exception used to exercise ErrorPage. */
export function raiseDeveloperCrash(): never {
throw new Error(DEVELOPER_CRASH_MESSAGE);
}
export function developerCrashReducer(
_requested: boolean,
action: 'confirm',
): boolean {
if (action === 'confirm') return true;
throw new Error(`Unknown developer crash action: ${String(action)}`);
}
export function DeveloperCrashProbe({ requested }: { requested: boolean }): null {
if (requested) raiseDeveloperCrash();
return null;
}