From cbe88dd5923ff898706a79535314833f126cd3b3 Mon Sep 17 00:00:00 2001 From: YokiiroBW Date: Mon, 20 Jul 2026 12:58:42 +0800 Subject: [PATCH] feat(ui): split main shell into navigable pages --- docs/progress.md | 8 + src/App.test.tsx | 18 +- src/App.tsx | 487 +++++++++++++++++++++++++++++++++++------------ src/styles.css | 384 +++++++++++++++++++++++++++++++++++++ 4 files changed, 771 insertions(+), 126 deletions(-) diff --git a/docs/progress.md b/docs/progress.md index 4ccb5da..de68572 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -112,3 +112,11 @@ Still not claimed complete: automatic startup activation, real Tauri multi-windo - Q5????????????/???????????????????????????? - Q6????? JSON manifest ???? UI?????????????PNG/WebP ?????????????? - ?????`2e84ea5`?`5dfac59`?`e0b48c0`?`9f235a3`?`4f13581`?`1828c61` ???? Forgejo? + +## 2026-07-20?????????? + +- ????????????????????????????????????? +- ????????????????/????/???????????? +- ??????????????????????????????????????????? +- ??????????????/?????????????????? Windows ????? +- ?????TypeScript?ESLint?Vitest 6/6?Vite production build ??? diff --git a/src/App.test.tsx b/src/App.test.tsx index c329f96..7644f6b 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -1,4 +1,4 @@ -import { invoke } from "@tauri-apps/api/core"; +import { invoke } from "@tauri-apps/api/core"; import { fireEvent, render, screen, waitFor } from "@testing-library/react"; import { beforeEach, describe, expect, it, vi } from "vitest"; @@ -46,6 +46,14 @@ const emptyPolicy: ConnectionPolicyStatus = { duplicateServerInstanceWarnings: [], }; +function openConnectionsPage() { + fireEvent.click(screen.getByRole("button", { name: /连接/ })); +} + +function openDiagnosticsPage() { + fireEvent.click(screen.getByRole("button", { name: /诊断与设置/ })); +} + function mockBaseCommands(options?: { profiles?: ConnectionProfile[]; slots?: ConnectionSlot[]; @@ -110,8 +118,10 @@ describe("App", () => { it("renders the verified Rust bootstrap status", async () => { render(); + openDiagnosticsPage(); expect(await screen.findByText("ready")).toBeInTheDocument(); expect(screen.getByText("desktop-v1alpha1")).toBeInTheDocument(); + openConnectionsPage(); expect(screen.getByText("连接 Profile")).toBeInTheDocument(); }); @@ -137,7 +147,7 @@ describe("App", () => { render(); - expect(await screen.findByText(/IPC unavailable:/)).toBeInTheDocument(); + expect(await screen.findByText(/IPC .*不可用:/)).toBeInTheDocument(); expect(screen.queryByText("unexpected")).not.toBeInTheDocument(); }); @@ -194,6 +204,7 @@ describe("App", () => { vi.spyOn(window, "confirm").mockReturnValue(true); render(); + openConnectionsPage(); expect(await screen.findByText("尚未保存 Profile。")).toBeInTheDocument(); fireEvent.change(screen.getByLabelText("显示名称"), { @@ -280,6 +291,7 @@ describe("App", () => { mockBaseCommands({ profiles }); render(); + openConnectionsPage(); fireEvent.change(await screen.findByLabelText("陪伴 Profile"), { target: { value: profiles[0].id }, @@ -333,6 +345,7 @@ describe("App", () => { }); render(); + openConnectionsPage(); expect(await screen.findByText("尚未保存 Profile。")).toBeInTheDocument(); fireEvent.change(screen.getByLabelText("显示名称"), { @@ -433,6 +446,7 @@ describe("App", () => { }); render(); + openConnectionsPage(); expect( await screen.findByLabelText("重复服务器实例提示"), diff --git a/src/App.tsx b/src/App.tsx index 6fe60bd..6ad49b1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,10 @@ import { ProfileManager } from "./features/profiles/ProfileManager"; import { PetPackImporter } from "./features/pet/PetPackImporter"; import { bootstrapStatusSchema, type BootstrapStatus } from "./types/bootstrap"; +type PageKey = "chat" | "connections" | "desktop" | "pet" | "diagnostics"; +type ChatLayout = "single" | "focus-companion" | "focus-operations"; +type ChatSlot = "companion" | "operations"; + const initialStatus: BootstrapStatus = { appVersion: "unknown", platform: "unknown", @@ -15,21 +19,33 @@ const initialStatus: BootstrapStatus = { databaseSchemaVersion: 4, }; +const navigation: Array<{ key: PageKey; label: string; description: string }> = + [ + { key: "chat", label: "聊天", description: "陪伴与运维对话" }, + { key: "connections", label: "连接", description: "实例与槽位管理" }, + { key: "desktop", label: "桌面行为", description: "快速聊天与状态气泡" }, + { key: "pet", label: "桌宠", description: "形象与活动范围" }, + { + key: "diagnostics", + label: "诊断与设置", + description: "运行状态与安全边界", + }, + ]; + export function App() { - const view = new URLSearchParams(window.location.search).get("view"); + const params = new URLSearchParams(window.location.search); + const view = params.get("view"); const isQuickView = view === "quick"; const isBubbleView = view === "bubble"; - const quickSlot = new URLSearchParams(window.location.search).get("slot"); + const quickSlot = params.get("slot"); + const [page, setPage] = useState("chat"); const [status, setStatus] = useState(initialStatus); const [error, setError] = useState(null); - const [chatLayout, setChatLayout] = useState< - "single" | "focus-companion" | "focus-operations" - >("single"); - const [quickTarget, setQuickTarget] = useState<"companion" | "operations">( - () => - localStorage.getItem("astrbot.quickTarget") === "operations" - ? "operations" - : "companion", + const [chatLayout, setChatLayout] = useState("single"); + const [quickTarget, setQuickTarget] = useState(() => + localStorage.getItem("astrbot.quickTarget") === "operations" + ? "operations" + : "companion", ); const [bubbleTarget, setBubbleTarget] = useState<"main" | "quick">(() => localStorage.getItem("astrbot.bubbleTarget") === "quick" ? "quick" : "main", @@ -50,7 +66,7 @@ export function App() { }, [refreshStatus]); if (isBubbleView) return ; - if (isQuickView) + if (isQuickView) { return (
); + } return (
-
-

P02 路 dual connections

-

AstrBot Desktop

-

- 鍙屽疄渚嬮櫔浼翠笌鏈満鍔╂墜鐨勫畨鍏?Windows - 瀹㈡埛绔伐绋嬪簳搴с€?{" "} -

-
+ -
- - - - -
- - - {error ?

IPC unavailable: {error}

: null} - -
-

瀹夊叏杈圭晫

-
    -
  • 凭据只在 Rust 与 Windows 安全存储之间流动。
  • -
  • 两个 REST/SSE 槽位保持独立状态与事件来源。
  • -
  • 本机操作必须经过白名单、策略与用户授权。
  • -
  • 文件事务默认保留源文件,且不会静默覆盖。
  • -
-
-
- -
-
- - + onQuickTargetChange={(value) => { + setQuickTarget(value); + localStorage.setItem("astrbot.quickTarget", value); + }} + onOpenQuickChat={() => + void invoke("open_quick_chat_window", { slot: quickTarget }) + } + /> + ) : null} + {page === "pet" ? : null} + {page === "diagnostics" ? ( + void refreshStatus()} + /> + ) : null}
+
+ ); +} -
-
- ???? - - - +function navIcon(page: PageKey) { + return { + chat: "⌁", + connections: "◎", + desktop: "◈", + pet: "✦", + diagnostics: "⚙", + }[page]; +} + +function PageHeader({ page }: { page: PageKey }) { + const current = navigation.find((item) => item.key === page) ?? navigation[0]; + return ( +
+
+

AstrBot Desktop

+

{current.label}

+

+ {current.description},所有本机能力都经过客户端权限边界。 +

+
+
+ + 双槽位架构 +
+
+ ); +} + +function ChatPage({ + chatLayout, + quickTarget, + onLayoutChange, + onOpenQuickChat, +}: { + chatLayout: ChatLayout; + quickTarget: ChatSlot; + onLayoutChange: (layout: ChatLayout) => void; + onOpenQuickChat: () => void; +}) { + return ( +
+
+
+ Conversation hub +

今天想和哪个实例聊天?

+

陪伴实例适合日常交流,运维实例用于经过确认的本机诊断提案。

+
+ +
+
+
+
+ Workspace view + 对话布局 +
+
+ onLayoutChange("single")} + > + 单面板 + + onLayoutChange("focus-companion")} + > + 聚焦陪伴 + + onLayoutChange("focus-operations")} + > + 聚焦运维 + +
+ + 快速聊天目标:{slotLabel(quickTarget)} +
- - - - - +
); } +function LayoutButton({ + active, + children, + onClick, +}: { + active: boolean; + children: React.ReactNode; + onClick: () => void; +}) { + return ( + + ); +} + +function DesktopBehaviorPage({ + bubbleTarget, + quickTarget, + onBubbleTargetChange, + onQuickTargetChange, + onOpenQuickChat, +}: { + bubbleTarget: "main" | "quick"; + quickTarget: ChatSlot; + onBubbleTargetChange: (value: "main" | "quick") => void; + onQuickTargetChange: (value: ChatSlot) => void; + onOpenQuickChat: () => void; +}) { + return ( +
+
+ + + + + + +
+ + 气泡状态显示已预留 +
+
+
+
+ Desktop companion +

后续桌面能力

+
+ 托盘与单实例 + 窗口置顶开关 + 多显示器策略 + 游戏模式靠边活动 +
+

+ 这些能力先保留为独立设置区,后续接入 Rust + 本机能力层,不会与聊天状态混在一起。 +

+
+
+ ); +} + +function PetPage() { + return ( +
+ +
+ + + + + + +
+
+ ); +} + +function DiagnosticsPage({ + status, + onRefresh, +}: { + status: BootstrapStatus; + onRefresh: () => void; +}) { + return ( +
+
+ + + + + +
+
+ Security boundary +

本机能力保持可审计

+
    +
  • 凭据只在 Rust 与 Windows 安全存储之间流动。
  • +
  • 两个 REST/SSE 槽位保持独立状态、会话、消息与未读数。
  • +
  • 本机操作必须经过白名单、角色、路径和用户授权。
  • +
  • 文件事务默认保留源文件,不静默覆盖目标。
  • +
+
+ +
+ ); +} + +function SettingCard({ + title, + description, + children, +}: { + title: string; + description: string; + children: React.ReactNode; +}) { + return ( +
+
+ Settings +

{title}

+

{description}

+
+
{children}
+
+ ); +} + +function slotLabel(slot: ChatSlot) { + return slot === "companion" ? "陪伴实例" : "运维实例"; +} + interface StatusCardProps { label: string; value: string; } - function StatusCard({ label, value }: StatusCardProps) { return (
diff --git a/src/styles.css b/src/styles.css index 3a7f840..7ea414e 100644 --- a/src/styles.css +++ b/src/styles.css @@ -717,3 +717,387 @@ select:focus { color: #c8f7dc; background: rgb(20 83 57 / 45%); } + + +/* Main shell information architecture */ +.app-shell { + display: grid; + grid-template-columns: 248px minmax(0, 1fr); + width: min(1440px, calc(100% - 2rem)); + min-height: calc(100vh - 2rem); + margin: 1rem auto; + padding: 0; + overflow: hidden; + border: 1px solid rgb(137 175 232 / 22%); + border-radius: 1.4rem; + background: rgb(8 17 31 / 72%); + box-shadow: 0 2rem 5rem rgb(0 0 0 / 25%); +} + +.app-sidebar { + display: flex; + flex-direction: column; + gap: 2rem; + padding: 1.5rem 1rem; + border-right: 1px solid rgb(137 175 232 / 18%); + background: rgb(7 18 34 / 70%); +} + +.brand-lockup { + display: flex; + gap: 0.75rem; + align-items: center; + padding: 0.25rem 0.5rem; +} +.brand-lockup > div:last-child { + display: grid; + gap: 0.2rem; +} +.brand-lockup strong { + font-size: 0.95rem; +} +.brand-lockup span { + color: #8fa4c5; + font-size: 0.72rem; +} +.brand-mark { + display: grid; + width: 2.35rem; + height: 2.35rem; + place-items: center; + border: 1px solid #79aaff; + border-radius: 0.75rem; + color: #08111f; + background: linear-gradient(145deg, #b9d5ff, #6aa3ff); + font-weight: 800; +} +.primary-nav { + display: grid; + gap: 0.45rem; +} +.nav-item { + display: flex; + gap: 0.75rem; + align-items: center; + width: 100%; + padding: 0.75rem 0.7rem; + border: 1px solid transparent; + border-radius: 0.8rem; + text-align: left; + background: transparent; +} +.nav-item:hover { + border-color: rgb(137 175 232 / 25%); + background: rgb(36 80 140 / 28%); +} +.nav-item.active { + border-color: rgb(125 176 255 / 55%); + background: rgb(36 80 140 / 55%); +} +.nav-item > span:last-child { + display: grid; + gap: 0.2rem; +} +.nav-item strong { + font-size: 0.9rem; +} +.nav-item small { + color: #91a7c9; + font-size: 0.72rem; +} +.nav-item-icon { + display: grid; + width: 1.8rem; + height: 1.8rem; + place-items: center; + border-radius: 0.55rem; + color: #aaccff; + background: rgb(106 163 255 / 15%); + font-size: 1.1rem; +} +.sidebar-footer { + display: flex; + gap: 0.5rem; + align-items: center; + margin-top: auto; + padding: 0.75rem 0.5rem 0; + border-top: 1px solid rgb(137 175 232 / 16%); + color: #91a7c9; + font-size: 0.75rem; +} +.connection-dot { + display: inline-block; + width: 0.55rem; + height: 0.55rem; + flex: 0 0 auto; + border-radius: 50%; + background: #60d399; + box-shadow: 0 0 0.8rem rgb(96 211 153 / 75%); +} +.app-content { + min-width: 0; + padding: 2.25rem clamp(1.25rem, 4vw, 3.5rem) 3rem; + overflow: auto; +} +.page-header { + display: flex; + justify-content: space-between; + gap: 1.5rem; + align-items: start; + margin-bottom: 2rem; +} +.page-header h1 { + margin: 0.35rem 0 0.55rem; + font-size: clamp(2rem, 5vw, 3.4rem); +} +.page-header .subtitle { + margin: 0; + font-size: 0.98rem; +} +.header-status-pill { + display: flex; + gap: 0.5rem; + align-items: center; + padding: 0.6rem 0.8rem; + border: 1px solid rgb(96 211 153 / 35%); + border-radius: 999px; + color: #c8f7dc; + background: rgb(20 83 57 / 28%); + font-size: 0.78rem; + white-space: nowrap; +} +.page-stack { + display: grid; + gap: 1.25rem; +} +.welcome-card, +.info-card, +.setting-card { + display: flex; + justify-content: space-between; + gap: 1.5rem; + align-items: center; + padding: 1.35rem 1.5rem; + border: 1px solid rgb(137 175 232 / 24%); + border-radius: 1rem; + background: linear-gradient(135deg, rgb(25 55 96 / 75%), rgb(13 29 52 / 82%)); +} +.welcome-card h2, +.info-card h2, +.setting-card h2 { + margin: 0.35rem 0 0.45rem; + font-size: 1.25rem; +} +.welcome-card p, +.info-card p, +.setting-card p { + margin: 0; + color: #aebfda; + line-height: 1.55; +} +.section-kicker { + display: block; + color: #8db9ff; + font-size: 0.7rem; + font-weight: 700; + letter-spacing: 0.1em; + text-transform: uppercase; +} +.chat-workspace { + margin: 0; +} +.workspace-toolbar { + display: flex; + flex-wrap: wrap; + gap: 1rem; + align-items: center; + margin-bottom: 0.85rem; + padding: 0.8rem 1rem; + border: 1px solid rgb(137 175 232 / 20%); + border-radius: 0.8rem; + background: rgb(7 18 34 / 62%); +} +.workspace-toolbar > div:first-child { + display: grid; + gap: 0.25rem; + margin-right: auto; +} +.toolbar-note { + color: #91a7c9; + font-size: 0.8rem; +} +.segmented-control { + display: flex; + gap: 0.25rem; + padding: 0.25rem; + border: 1px solid rgb(137 175 232 / 24%); + border-radius: 0.7rem; + background: rgb(7 18 34 / 65%); +} +.segment { + padding: 0.5rem 0.7rem; + border: 0; + border-radius: 0.45rem; + color: #aebfda; + background: transparent; + font-size: 0.8rem; +} +.segment:hover, +.segment.active { + color: #f7faff; + background: #24508c; +} +.settings-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 1rem; +} +.setting-card { + display: grid; + align-items: start; +} +.setting-card-controls { + display: grid; + min-width: min(280px, 100%); + gap: 0.8rem; +} +.setting-card-controls label { + display: grid; + gap: 0.4rem; +} +.setting-card-controls label span { + color: #c7d4e9; + font-size: 0.82rem; + font-weight: 650; +} +.status-preview { + display: flex; + gap: 0.5rem; + align-items: center; + padding: 0.7rem 0.8rem; + border: 1px solid rgb(96 211 153 / 28%); + border-radius: 0.65rem; + color: #c8f7dc; + background: rgb(20 83 57 / 25%); + font-size: 0.8rem; +} +.feature-list { + display: flex; + flex-wrap: wrap; + gap: 0.5rem; + margin: 1rem 0; +} +.feature-list span { + padding: 0.45rem 0.65rem; + border: 1px solid rgb(137 175 232 / 22%); + border-radius: 999px; + color: #c7d4e9; + background: rgb(7 18 34 / 45%); + font-size: 0.78rem; +} +.info-card { + display: block; +} +.app-content > .profile-manager, +.app-content .pet-pack-importer { + margin: 0; +} +.app-content .status-grid { + margin: 0; +} +.app-content .boundaries { + margin: 0; +} + +@media (max-width: 900px) { + .app-shell { + grid-template-columns: 76px minmax(0, 1fr); + } + .app-sidebar { + padding: 1.25rem 0.65rem; + } + .brand-lockup { + justify-content: center; + padding: 0; + } + .brand-lockup > div:last-child, + .nav-item > span:last-child, + .sidebar-footer > span:last-child { + display: none; + } + .nav-item { + justify-content: center; + padding: 0.7rem; + } + .nav-item-icon { + width: 2.1rem; + height: 2.1rem; + } + .sidebar-footer { + justify-content: center; + } +} + +@media (max-width: 680px) { + .app-shell { + display: block; + width: 100%; + min-height: 100vh; + margin: 0; + border: 0; + border-radius: 0; + } + .app-sidebar { + display: block; + padding: 0.75rem; + border-right: 0; + border-bottom: 1px solid rgb(137 175 232 / 18%); + } + .brand-lockup { + justify-content: flex-start; + } + .brand-lockup > div:last-child { + display: grid; + } + .primary-nav { + display: flex; + gap: 0.4rem; + margin-top: 0.75rem; + overflow-x: auto; + } + .nav-item { + min-width: 8.2rem; + justify-content: flex-start; + } + .nav-item > span:last-child { + display: grid; + } + .sidebar-footer { + display: none; + } + .app-content { + padding: 1.5rem 1rem 2rem; + } + .page-header, + .welcome-card, + .setting-card { + display: grid; + } + .header-status-pill { + justify-self: start; + } + .settings-grid { + grid-template-columns: 1fr; + } + .setting-card-controls { + min-width: 0; + width: 100%; + } + .segmented-control { + width: 100%; + overflow-x: auto; + } + .segment { + flex: 1 0 auto; + } +}