2026-07-21 14:43:14 +08:00
|
|
|
|
import { invoke } from "@tauri-apps/api/core";
|
2026-07-20 20:50:27 +08:00
|
|
|
|
import { listen } from "@tauri-apps/api/event";
|
2026-07-21 14:43:14 +08:00
|
|
|
|
import { getCurrentWindow } from "@tauri-apps/api/window";
|
2026-07-20 20:50:27 +08:00
|
|
|
|
import { useCallback, useEffect, useRef, useState } from "react";
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
2026-07-20 11:31:41 +08:00
|
|
|
|
import { ChatPanel } from "./features/chat/ChatPanel";
|
|
|
|
|
|
import { StatusBubble } from "./features/chat/StatusBubble";
|
2026-07-18 23:36:59 +08:00
|
|
|
|
import { ProfileManager } from "./features/profiles/ProfileManager";
|
2026-07-20 12:36:20 +08:00
|
|
|
|
import { PetPackImporter } from "./features/pet/PetPackImporter";
|
2026-07-21 14:43:14 +08:00
|
|
|
|
import {
|
|
|
|
|
|
boundRuntimeEventSchema,
|
|
|
|
|
|
connectionRuntimeStatusSchema,
|
|
|
|
|
|
} from "./features/chat/types";
|
2026-07-20 20:50:27 +08:00
|
|
|
|
import aemeathSpritesheet from "./features/pet/assets/aemeath/aemeath-spritesheet.png?inline";
|
2026-07-18 22:17:29 +08:00
|
|
|
|
import { bootstrapStatusSchema, type BootstrapStatus } from "./types/bootstrap";
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
2026-07-20 12:58:42 +08:00
|
|
|
|
type PageKey = "chat" | "connections" | "desktop" | "pet" | "diagnostics";
|
|
|
|
|
|
type ChatSlot = "companion" | "operations";
|
2026-07-20 20:50:27 +08:00
|
|
|
|
type PetDisplayMode = "app-ui" | "desktop-floating";
|
2026-07-21 14:43:14 +08:00
|
|
|
|
type ThemeMode = "dark" | "light";
|
2026-07-20 12:58:42 +08:00
|
|
|
|
|
2026-07-18 20:34:47 +08:00
|
|
|
|
const initialStatus: BootstrapStatus = {
|
|
|
|
|
|
appVersion: "unknown",
|
|
|
|
|
|
platform: "unknown",
|
|
|
|
|
|
rustCore: "pending",
|
|
|
|
|
|
protocolVersion: "desktop-v1alpha1",
|
2026-07-20 11:31:41 +08:00
|
|
|
|
databaseSchemaVersion: 4,
|
2026-07-18 20:34:47 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-07-20 17:28:56 +08:00
|
|
|
|
const AEMEATH_SPRITESHEET = aemeathSpritesheet;
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const PET_TARGET_SLOT = "companion" as const;
|
2026-07-20 17:20:43 +08:00
|
|
|
|
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const AEMEATH_FRAMES: Record<
|
|
|
|
|
|
"idle" | "working" | "resting" | "speaking" | "error",
|
|
|
|
|
|
number[]
|
|
|
|
|
|
> = {
|
2026-07-20 17:20:43 +08:00
|
|
|
|
idle: [0, 1, 2, 3, 4, 5],
|
2026-07-21 14:43:14 +08:00
|
|
|
|
working: [
|
|
|
|
|
|
80, 81, 82, 83, 84, 85, 86, 87, 104, 105, 106, 107, 108, 109, 110, 111,
|
|
|
|
|
|
],
|
2026-07-20 17:20:43 +08:00
|
|
|
|
resting: [48, 49, 50, 51, 52, 53],
|
|
|
|
|
|
speaking: [72, 73, 74, 75, 76, 77, 78, 79],
|
|
|
|
|
|
error: [40, 41, 42, 43, 44, 45, 46, 47],
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-07-20 12:58:42 +08:00
|
|
|
|
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: "运行状态与安全边界",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
2026-07-18 20:34:47 +08:00
|
|
|
|
export function App() {
|
2026-07-20 12:58:42 +08:00
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
|
|
const view = params.get("view");
|
2026-07-20 11:31:41 +08:00
|
|
|
|
const isQuickView = view === "quick";
|
|
|
|
|
|
const isBubbleView = view === "bubble";
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const isPetView =
|
|
|
|
|
|
view === "pet" ||
|
|
|
|
|
|
window.location.hash === "#pet" ||
|
|
|
|
|
|
document.documentElement.dataset.astrbotPet === "true";
|
2026-07-20 12:58:42 +08:00
|
|
|
|
const quickSlot = params.get("slot");
|
|
|
|
|
|
const [page, setPage] = useState<PageKey>("chat");
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const [theme, setTheme] = useState<ThemeMode>(() =>
|
|
|
|
|
|
localStorage.getItem("astrbot.theme") === "light" ? "light" : "dark",
|
|
|
|
|
|
);
|
2026-07-18 20:34:47 +08:00
|
|
|
|
const [status, setStatus] = useState(initialStatus);
|
|
|
|
|
|
const [error, setError] = useState<string | null>(null);
|
2026-07-20 12:58:42 +08:00
|
|
|
|
const [quickTarget, setQuickTarget] = useState<ChatSlot>(() =>
|
|
|
|
|
|
localStorage.getItem("astrbot.quickTarget") === "operations"
|
|
|
|
|
|
? "operations"
|
|
|
|
|
|
: "companion",
|
2026-07-20 12:34:56 +08:00
|
|
|
|
);
|
|
|
|
|
|
const [bubbleTarget, setBubbleTarget] = useState<"main" | "quick">(() =>
|
|
|
|
|
|
localStorage.getItem("astrbot.bubbleTarget") === "quick" ? "quick" : "main",
|
|
|
|
|
|
);
|
2026-07-20 20:50:27 +08:00
|
|
|
|
const [petDisplayMode, setPetDisplayMode] = useState<PetDisplayMode>(() =>
|
|
|
|
|
|
localStorage.getItem("astrbot.petDisplayMode") === "desktop-floating"
|
|
|
|
|
|
? "desktop-floating"
|
|
|
|
|
|
: "app-ui",
|
|
|
|
|
|
);
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
|
|
|
|
|
const refreshStatus = useCallback(async () => {
|
|
|
|
|
|
try {
|
2026-07-18 22:17:29 +08:00
|
|
|
|
const result = await invoke<unknown>("bootstrap_status");
|
|
|
|
|
|
setStatus(bootstrapStatusSchema.parse(result));
|
2026-07-18 20:34:47 +08:00
|
|
|
|
setError(null);
|
|
|
|
|
|
} catch (reason) {
|
|
|
|
|
|
setError(reason instanceof Error ? reason.message : String(reason));
|
|
|
|
|
|
}
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
2026-07-21 14:43:14 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
document.documentElement.dataset.theme = theme;
|
|
|
|
|
|
localStorage.setItem("astrbot.theme", theme);
|
|
|
|
|
|
}, [theme]);
|
|
|
|
|
|
|
2026-07-18 20:34:47 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
void refreshStatus();
|
|
|
|
|
|
}, [refreshStatus]);
|
|
|
|
|
|
|
2026-07-20 20:50:27 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (isBubbleView || isPetView || isQuickView) return;
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const command =
|
|
|
|
|
|
petDisplayMode === "desktop-floating"
|
|
|
|
|
|
? "open_pet_window"
|
|
|
|
|
|
: "close_pet_window";
|
2026-07-20 20:50:27 +08:00
|
|
|
|
void invoke(command).catch((reason) => {
|
|
|
|
|
|
setError(reason instanceof Error ? reason.message : String(reason));
|
|
|
|
|
|
});
|
|
|
|
|
|
}, [isBubbleView, isPetView, isQuickView, petDisplayMode]);
|
|
|
|
|
|
|
2026-07-20 11:31:41 +08:00
|
|
|
|
if (isBubbleView) return <StatusBubble />;
|
2026-07-20 16:28:42 +08:00
|
|
|
|
if (isPetView) return <DesktopPetView />;
|
2026-07-20 12:58:42 +08:00
|
|
|
|
if (isQuickView) {
|
2026-07-20 11:31:41 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<main className="quick-app-shell">
|
2026-07-20 12:34:56 +08:00
|
|
|
|
<ChatPanel
|
|
|
|
|
|
fixedSlot={
|
|
|
|
|
|
quickSlot === "operations"
|
|
|
|
|
|
? "operations"
|
|
|
|
|
|
: quickSlot === "companion"
|
|
|
|
|
|
? "companion"
|
|
|
|
|
|
: undefined
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
2026-07-20 11:31:41 +08:00
|
|
|
|
</main>
|
|
|
|
|
|
);
|
2026-07-20 12:58:42 +08:00
|
|
|
|
}
|
2026-07-20 11:31:41 +08:00
|
|
|
|
|
2026-07-18 20:34:47 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<main className="app-shell">
|
2026-07-21 14:43:14 +08:00
|
|
|
|
<WindowChrome
|
|
|
|
|
|
theme={theme}
|
|
|
|
|
|
onToggleTheme={() =>
|
|
|
|
|
|
setTheme((current) => (current === "dark" ? "light" : "dark"))
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<div className="app-shell-body">
|
|
|
|
|
|
<aside className="app-sidebar">
|
|
|
|
|
|
<div className="brand-lockup">
|
|
|
|
|
|
<div className="brand-mark">A</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<strong>AstrBot Desktop</strong>
|
|
|
|
|
|
<span>Companion workspace</span>
|
|
|
|
|
|
</div>
|
2026-07-20 12:58:42 +08:00
|
|
|
|
</div>
|
2026-07-21 14:43:14 +08:00
|
|
|
|
<nav className="primary-nav" aria-label="主导航">
|
|
|
|
|
|
{navigation.map((item) => (
|
|
|
|
|
|
<button
|
|
|
|
|
|
key={item.key}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
className={page === item.key ? "nav-item active" : "nav-item"}
|
|
|
|
|
|
onClick={() => setPage(item.key)}
|
|
|
|
|
|
>
|
|
|
|
|
|
<span className="nav-item-icon">{navIcon(item.key)}</span>
|
|
|
|
|
|
<span>
|
|
|
|
|
|
<strong>{item.label}</strong>
|
|
|
|
|
|
<small>{item.description}</small>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</nav>
|
|
|
|
|
|
<div className="sidebar-footer">
|
|
|
|
|
|
<span className="connection-dot" />
|
|
|
|
|
|
<span>本地客户端已启动</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</aside>
|
|
|
|
|
|
|
|
|
|
|
|
<section
|
|
|
|
|
|
className={
|
|
|
|
|
|
page === "chat" ? "app-content app-content-chat" : "app-content"
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
{page === "chat" ? null : <PageHeader page={page} />}
|
|
|
|
|
|
{error ? <p className="error-banner">IPC 暂不可用:{error}</p> : null}
|
|
|
|
|
|
{page === "chat" ? <ChatPage /> : null}
|
|
|
|
|
|
{page === "connections" ? <ProfileManager /> : null}
|
|
|
|
|
|
{page === "desktop" ? (
|
|
|
|
|
|
<DesktopBehaviorPage
|
|
|
|
|
|
bubbleTarget={bubbleTarget}
|
|
|
|
|
|
quickTarget={quickTarget}
|
|
|
|
|
|
onBubbleTargetChange={(value) => {
|
|
|
|
|
|
setBubbleTarget(value);
|
|
|
|
|
|
localStorage.setItem("astrbot.bubbleTarget", value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
onQuickTargetChange={(value) => {
|
|
|
|
|
|
setQuickTarget(value);
|
|
|
|
|
|
localStorage.setItem("astrbot.quickTarget", value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
onOpenQuickChat={() =>
|
|
|
|
|
|
void invoke("open_quick_chat_window", { slot: quickTarget })
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
{page === "pet" ? (
|
|
|
|
|
|
<PetPage
|
|
|
|
|
|
displayMode={petDisplayMode}
|
|
|
|
|
|
onDisplayModeChange={(value) => {
|
|
|
|
|
|
setPetDisplayMode(value);
|
|
|
|
|
|
localStorage.setItem("astrbot.petDisplayMode", value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
{page === "diagnostics" ? (
|
|
|
|
|
|
<DiagnosticsPage
|
|
|
|
|
|
status={status}
|
|
|
|
|
|
onRefresh={() => void refreshStatus()}
|
|
|
|
|
|
/>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
</section>
|
|
|
|
|
|
</div>
|
2026-07-20 20:50:27 +08:00
|
|
|
|
{petDisplayMode === "app-ui" ? <InAppPetOverlay /> : null}
|
2026-07-20 12:58:42 +08:00
|
|
|
|
</main>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
2026-07-21 14:43:14 +08:00
|
|
|
|
function WindowChrome({
|
|
|
|
|
|
theme,
|
|
|
|
|
|
onToggleTheme,
|
|
|
|
|
|
}: {
|
|
|
|
|
|
theme: ThemeMode;
|
|
|
|
|
|
onToggleTheme: () => void;
|
|
|
|
|
|
}) {
|
|
|
|
|
|
const [currentWindow, setCurrentWindow] = useState<ReturnType<
|
|
|
|
|
|
typeof getCurrentWindow
|
|
|
|
|
|
> | null>(null);
|
|
|
|
|
|
const [maximized, setMaximized] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const windowHandle = getCurrentWindow();
|
|
|
|
|
|
setCurrentWindow(windowHandle);
|
|
|
|
|
|
void windowHandle.isMaximized().then(setMaximized);
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
const toggleMaximize = async () => {
|
|
|
|
|
|
if (!currentWindow) return;
|
|
|
|
|
|
await currentWindow.toggleMaximize();
|
|
|
|
|
|
setMaximized(await currentWindow.isMaximized());
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<header
|
|
|
|
|
|
className="window-chrome"
|
|
|
|
|
|
data-tauri-drag-region
|
|
|
|
|
|
onDoubleClick={() => void toggleMaximize()}
|
|
|
|
|
|
onMouseDown={(event) => {
|
|
|
|
|
|
if (event.button === 0) void currentWindow?.startDragging();
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<span className="window-chrome-title">AstrBot Desktop</span>
|
|
|
|
|
|
<div className="window-chrome-actions" data-tauri-drag-region="false">
|
|
|
|
|
|
<button
|
|
|
|
|
|
aria-label={
|
|
|
|
|
|
theme === "dark" ? "Switch to light theme" : "Switch to dark theme"
|
|
|
|
|
|
}
|
|
|
|
|
|
className="window-theme-toggle"
|
|
|
|
|
|
onClick={onToggleTheme}
|
|
|
|
|
|
onMouseDown={(event) => event.stopPropagation()}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
>
|
|
|
|
|
|
{theme === "dark" ? "Light" : "Dark"}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<div className="window-controls" data-tauri-drag-region="false">
|
|
|
|
|
|
<button
|
|
|
|
|
|
aria-label="Minimize window"
|
|
|
|
|
|
className="window-control"
|
|
|
|
|
|
onClick={() => void currentWindow?.minimize()}
|
|
|
|
|
|
onMouseDown={(event) => event.stopPropagation()}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span
|
|
|
|
|
|
className="window-glyph window-glyph-minimize"
|
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
aria-label={maximized ? "Restore window" : "Maximize window"}
|
|
|
|
|
|
className="window-control"
|
|
|
|
|
|
onClick={() => void toggleMaximize()}
|
|
|
|
|
|
onMouseDown={(event) => event.stopPropagation()}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span
|
|
|
|
|
|
className={`window-glyph window-glyph-maximize${maximized ? " is-restored" : ""}`}
|
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
aria-label="Close window"
|
|
|
|
|
|
className="window-control window-control-close"
|
|
|
|
|
|
onClick={() => void currentWindow?.close()}
|
|
|
|
|
|
onMouseDown={(event) => event.stopPropagation()}
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span
|
|
|
|
|
|
className="window-glyph window-glyph-close"
|
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-20 20:50:27 +08:00
|
|
|
|
function InAppPetOverlay() {
|
|
|
|
|
|
const [visible, setVisible] = useState(true);
|
|
|
|
|
|
const [position, setPosition] = useState(() => {
|
|
|
|
|
|
try {
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const saved = JSON.parse(
|
|
|
|
|
|
localStorage.getItem("astrbot.petPosition") ?? "null",
|
|
|
|
|
|
);
|
2026-07-20 20:50:27 +08:00
|
|
|
|
return saved && typeof saved.x === "number" && typeof saved.y === "number"
|
|
|
|
|
|
? saved
|
|
|
|
|
|
: { x: 24, y: 96 };
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
return { x: 24, y: 96 };
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const dragRef = useRef<{
|
|
|
|
|
|
pointerId: number;
|
|
|
|
|
|
offsetX: number;
|
|
|
|
|
|
offsetY: number;
|
|
|
|
|
|
} | null>(null);
|
2026-07-20 20:50:27 +08:00
|
|
|
|
|
|
|
|
|
|
const savePosition = (x: number, y: number) => {
|
|
|
|
|
|
const next = {
|
|
|
|
|
|
x: Math.max(0, Math.min(x, window.innerWidth - 188)),
|
|
|
|
|
|
y: Math.max(0, Math.min(y, window.innerHeight - 226)),
|
|
|
|
|
|
};
|
|
|
|
|
|
setPosition(next);
|
|
|
|
|
|
localStorage.setItem("astrbot.petPosition", JSON.stringify(next));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
let unlisten: (() => void) | undefined;
|
2026-07-21 14:43:14 +08:00
|
|
|
|
void listen("pet-hide-requested", () => setVisible(false)).then(
|
|
|
|
|
|
(cleanup) => {
|
|
|
|
|
|
unlisten = cleanup;
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
2026-07-20 20:50:27 +08:00
|
|
|
|
return () => unlisten?.();
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
return visible ? (
|
|
|
|
|
|
<div
|
|
|
|
|
|
className="app-pet-overlay"
|
|
|
|
|
|
style={{ left: position.x, top: position.y }}
|
|
|
|
|
|
onContextMenu={(event) => {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
void invoke("show_pet_context_menu");
|
|
|
|
|
|
}}
|
|
|
|
|
|
onPointerDown={(event) => {
|
|
|
|
|
|
if (event.button !== 0) return;
|
|
|
|
|
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
|
|
|
|
dragRef.current = {
|
|
|
|
|
|
pointerId: event.pointerId,
|
|
|
|
|
|
offsetX: event.clientX - position.x,
|
|
|
|
|
|
offsetY: event.clientY - position.y,
|
|
|
|
|
|
};
|
|
|
|
|
|
}}
|
|
|
|
|
|
onPointerMove={(event) => {
|
|
|
|
|
|
if (dragRef.current?.pointerId !== event.pointerId) return;
|
|
|
|
|
|
savePosition(
|
|
|
|
|
|
event.clientX - dragRef.current.offsetX,
|
|
|
|
|
|
event.clientY - dragRef.current.offsetY,
|
|
|
|
|
|
);
|
|
|
|
|
|
}}
|
|
|
|
|
|
onPointerUp={(event) => {
|
2026-07-21 14:43:14 +08:00
|
|
|
|
if (dragRef.current?.pointerId === event.pointerId)
|
|
|
|
|
|
dragRef.current = null;
|
2026-07-20 20:50:27 +08:00
|
|
|
|
}}
|
|
|
|
|
|
onPointerCancel={() => {
|
|
|
|
|
|
dragRef.current = null;
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<DesktopPetView embedded />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-20 12:58:42 +08:00
|
|
|
|
function navIcon(page: PageKey) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
chat: "⌁",
|
|
|
|
|
|
connections: "◎",
|
|
|
|
|
|
desktop: "◈",
|
|
|
|
|
|
pet: "✦",
|
|
|
|
|
|
diagnostics: "⚙",
|
|
|
|
|
|
}[page];
|
|
|
|
|
|
}
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
2026-07-20 12:58:42 +08:00
|
|
|
|
function PageHeader({ page }: { page: PageKey }) {
|
|
|
|
|
|
const current = navigation.find((item) => item.key === page) ?? navigation[0];
|
|
|
|
|
|
return (
|
|
|
|
|
|
<header className="page-header">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="eyebrow">AstrBot Desktop</p>
|
|
|
|
|
|
<h1>{current.label}</h1>
|
|
|
|
|
|
<p className="subtitle">
|
|
|
|
|
|
{current.description},所有本机能力都经过客户端权限边界。
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="header-status-pill">
|
|
|
|
|
|
<span className="connection-dot" />
|
|
|
|
|
|
双槽位架构
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-21 14:43:14 +08:00
|
|
|
|
function ChatPage() {
|
2026-07-20 12:58:42 +08:00
|
|
|
|
return (
|
2026-07-21 14:43:14 +08:00
|
|
|
|
<div className="chat-page">
|
|
|
|
|
|
<ChatPanel />
|
2026-07-20 12:58:42 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function DesktopBehaviorPage({
|
|
|
|
|
|
bubbleTarget,
|
|
|
|
|
|
quickTarget,
|
|
|
|
|
|
onBubbleTargetChange,
|
|
|
|
|
|
onQuickTargetChange,
|
|
|
|
|
|
onOpenQuickChat,
|
|
|
|
|
|
}: {
|
|
|
|
|
|
bubbleTarget: "main" | "quick";
|
|
|
|
|
|
quickTarget: ChatSlot;
|
|
|
|
|
|
onBubbleTargetChange: (value: "main" | "quick") => void;
|
|
|
|
|
|
onQuickTargetChange: (value: ChatSlot) => void;
|
|
|
|
|
|
onOpenQuickChat: () => void;
|
|
|
|
|
|
}) {
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const [quietHours, setQuietHours] = useState(
|
|
|
|
|
|
() => localStorage.getItem("astrbot.quietHours") ?? "off",
|
|
|
|
|
|
);
|
2026-07-20 12:58:42 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="page-stack">
|
|
|
|
|
|
<section className="settings-grid">
|
|
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="快速聊天"
|
|
|
|
|
|
description="设置气泡或快捷入口打开哪个实例。"
|
|
|
|
|
|
>
|
|
|
|
|
|
<label>
|
|
|
|
|
|
<span>默认目标槽位</span>
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={quickTarget}
|
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
|
onQuickTargetChange(event.target.value as ChatSlot)
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
<option value="companion">陪伴实例</option>
|
|
|
|
|
|
<option value="operations">运维实例</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<button type="button" onClick={onOpenQuickChat}>
|
|
|
|
|
|
立即打开快速聊天
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</SettingCard>
|
|
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="状态气泡"
|
|
|
|
|
|
description="气泡显示连接状态,并根据这里的设置响应点击。"
|
|
|
|
|
|
>
|
|
|
|
|
|
<label>
|
|
|
|
|
|
<span>点击气泡时</span>
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={bubbleTarget}
|
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
|
onBubbleTargetChange(event.target.value as "main" | "quick")
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
<option value="main">打开主界面</option>
|
|
|
|
|
|
<option value="quick">打开快速聊天</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<div className="status-preview">
|
|
|
|
|
|
<span className="connection-dot" />
|
|
|
|
|
|
气泡状态显示已预留
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</SettingCard>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
<section className="info-card">
|
|
|
|
|
|
<span className="section-kicker">Desktop companion</span>
|
|
|
|
|
|
<h2>后续桌面能力</h2>
|
|
|
|
|
|
<div className="feature-list">
|
|
|
|
|
|
<span>托盘与单实例</span>
|
|
|
|
|
|
<span>窗口置顶开关</span>
|
|
|
|
|
|
<span>多显示器策略</span>
|
|
|
|
|
|
<span>游戏模式靠边活动</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
这些能力先保留为独立设置区,后续接入 Rust
|
|
|
|
|
|
本机能力层,不会与聊天状态混在一起。
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</section>
|
2026-07-21 14:43:14 +08:00
|
|
|
|
<section className="settings-grid">
|
|
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="主动消息静默时段"
|
|
|
|
|
|
description="静默时段只抑制气泡提醒,不会删除消息,也不会影响聊天未读数。"
|
|
|
|
|
|
>
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={quietHours}
|
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
|
const next = event.target.value;
|
|
|
|
|
|
setQuietHours(next);
|
|
|
|
|
|
localStorage.setItem("astrbot.quietHours", next);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<option value="off">关闭</option>
|
|
|
|
|
|
<option value="night">每天 22:00–07:00</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</SettingCard>
|
|
|
|
|
|
</section>
|
2026-07-20 12:58:42 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-20 20:50:27 +08:00
|
|
|
|
function PetPage({
|
|
|
|
|
|
displayMode,
|
|
|
|
|
|
onDisplayModeChange,
|
|
|
|
|
|
}: {
|
|
|
|
|
|
displayMode: PetDisplayMode;
|
|
|
|
|
|
onDisplayModeChange: (value: PetDisplayMode) => void;
|
|
|
|
|
|
}) {
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const [monitors, setMonitors] = useState<
|
|
|
|
|
|
Array<{
|
|
|
|
|
|
name?: string;
|
|
|
|
|
|
width: number;
|
|
|
|
|
|
height: number;
|
|
|
|
|
|
scaleFactor: number;
|
|
|
|
|
|
isPrimary: boolean;
|
|
|
|
|
|
}>
|
|
|
|
|
|
>([]);
|
|
|
|
|
|
const [monitorIndex, setMonitorIndex] = useState(0);
|
|
|
|
|
|
const [positionMode, setPositionMode] = useState("edge");
|
|
|
|
|
|
const [alwaysOnTop, setAlwaysOnTop] = useState(true);
|
|
|
|
|
|
const [gameMode, setGameMode] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
void invoke<unknown>("list_monitor_geometries")
|
|
|
|
|
|
.then((value) => setMonitors(value as typeof monitors))
|
|
|
|
|
|
.catch(() => setMonitors([]));
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
const applyPetPreferences = (
|
|
|
|
|
|
next: Partial<{
|
|
|
|
|
|
positionMode: string;
|
|
|
|
|
|
monitorIndex: number;
|
|
|
|
|
|
alwaysOnTop: boolean;
|
|
|
|
|
|
gameMode: boolean;
|
|
|
|
|
|
}> = {},
|
|
|
|
|
|
) => {
|
|
|
|
|
|
const preferences = {
|
|
|
|
|
|
positionMode: next.positionMode ?? positionMode,
|
|
|
|
|
|
monitorIndex: next.monitorIndex ?? monitorIndex,
|
|
|
|
|
|
alwaysOnTop: next.alwaysOnTop ?? alwaysOnTop,
|
|
|
|
|
|
gameMode: next.gameMode ?? gameMode,
|
|
|
|
|
|
};
|
|
|
|
|
|
void invoke("set_pet_window_preferences", { preferences }).catch(
|
|
|
|
|
|
() => undefined,
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-07-20 12:58:42 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="page-stack">
|
2026-07-20 12:36:20 +08:00
|
|
|
|
<PetPackImporter />
|
2026-07-20 20:50:27 +08:00
|
|
|
|
{displayMode === "app-ui" ? (
|
|
|
|
|
|
<section className="pet-inline-preview" aria-label="应用内桌宠预览">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<span className="section-kicker">App UI</span>
|
|
|
|
|
|
<h2>应用内活动桌宠</h2>
|
|
|
|
|
|
<p>桌宠已叠加在主界面上,可直接拖动;关闭后可重新打开应用。</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
) : null}
|
2026-07-20 12:58:42 +08:00
|
|
|
|
<section className="settings-grid">
|
|
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="显示范围"
|
2026-07-20 20:50:27 +08:00
|
|
|
|
description="应用内活动桌宠不创建桌面浮窗,避免透明窗口白框。"
|
2026-07-20 12:58:42 +08:00
|
|
|
|
>
|
2026-07-20 20:50:27 +08:00
|
|
|
|
<select
|
|
|
|
|
|
value={displayMode}
|
2026-07-21 14:43:14 +08:00
|
|
|
|
onChange={(event) =>
|
|
|
|
|
|
onDisplayModeChange(event.target.value as PetDisplayMode)
|
|
|
|
|
|
}
|
2026-07-20 20:50:27 +08:00
|
|
|
|
>
|
|
|
|
|
|
<option value="app-ui">仅应用 UI 内</option>
|
2026-07-21 14:43:14 +08:00
|
|
|
|
<option value="desktop-floating">
|
|
|
|
|
|
桌面浮动
|
|
|
|
|
|
</option>
|
2026-07-20 12:58:42 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
</SettingCard>
|
|
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="活动策略"
|
2026-07-20 20:50:27 +08:00
|
|
|
|
description="为后续游戏模式和多显示器行为预留配置入口。"
|
2026-07-20 12:58:42 +08:00
|
|
|
|
>
|
|
|
|
|
|
<select defaultValue="smart">
|
|
|
|
|
|
<option value="smart">智能选择显示器</option>
|
|
|
|
|
|
<option value="primary">固定主屏</option>
|
|
|
|
|
|
<option value="secondary">优先副屏</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</SettingCard>
|
2026-07-20 16:28:42 +08:00
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="运行桌宠"
|
2026-07-20 20:50:27 +08:00
|
|
|
|
description="应用内桌宠可在主界面中自由移动,不再创建白色桌面浮窗。"
|
2026-07-20 16:28:42 +08:00
|
|
|
|
>
|
2026-07-20 20:50:27 +08:00
|
|
|
|
{displayMode === "desktop-floating" ? (
|
|
|
|
|
|
<button type="button" onClick={() => onDisplayModeChange("app-ui")}>
|
|
|
|
|
|
改用应用内活动桌宠
|
|
|
|
|
|
</button>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<span className="form-note">应用内活动桌宠已显示,可直接拖动</span>
|
|
|
|
|
|
)}
|
2026-07-20 16:28:42 +08:00
|
|
|
|
</SettingCard>
|
2026-07-21 14:43:14 +08:00
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="显示器与位置"
|
|
|
|
|
|
description="桌面版只会把桌宠放在屏幕安全边缘,不会覆盖游戏中心区域。"
|
|
|
|
|
|
>
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={monitorIndex}
|
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
|
const next = Number(event.target.value);
|
|
|
|
|
|
setMonitorIndex(next);
|
|
|
|
|
|
applyPetPreferences({ monitorIndex: next });
|
|
|
|
|
|
}}
|
|
|
|
|
|
disabled={monitors.length === 0}
|
|
|
|
|
|
>
|
|
|
|
|
|
{monitors.map((monitor, index) => (
|
|
|
|
|
|
<option
|
|
|
|
|
|
value={index}
|
|
|
|
|
|
key={`${monitor.name ?? "monitor"}-${index}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
{monitor.name ?? `显示器 ${index + 1}`}{" "}
|
|
|
|
|
|
{monitor.isPrimary ? "(主屏)" : ""}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</select>
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={positionMode}
|
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
|
const next = event.target.value;
|
|
|
|
|
|
setPositionMode(next);
|
|
|
|
|
|
applyPetPreferences({ positionMode: next });
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<option value="free">自由位置</option>
|
|
|
|
|
|
<option value="edge">安全边缘</option>
|
|
|
|
|
|
<option value="monitor">指定显示器</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</SettingCard>
|
|
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="桌面行为"
|
|
|
|
|
|
description="置顶和游戏模式都可以随时关闭;权限或显示器不可用时自动回退。"
|
|
|
|
|
|
>
|
|
|
|
|
|
<label className="toggle-row">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="checkbox"
|
|
|
|
|
|
checked={alwaysOnTop}
|
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
|
const next = event.target.checked;
|
|
|
|
|
|
setAlwaysOnTop(next);
|
|
|
|
|
|
applyPetPreferences({ alwaysOnTop: next });
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
始终置顶
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<label className="toggle-row">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="checkbox"
|
|
|
|
|
|
checked={gameMode}
|
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
|
const next = event.target.checked;
|
|
|
|
|
|
setGameMode(next);
|
|
|
|
|
|
applyPetPreferences({ gameMode: next });
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
游戏模式(安全边缘)
|
|
|
|
|
|
</label>
|
|
|
|
|
|
</SettingCard>
|
2026-07-20 12:58:42 +08:00
|
|
|
|
</section>
|
|
|
|
|
|
</div>
|
2026-07-20 16:28:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-20 20:50:27 +08:00
|
|
|
|
function DesktopPetView({ embedded = false }: { embedded?: boolean }) {
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const [state, setState] = useState<
|
|
|
|
|
|
"idle" | "working" | "resting" | "speaking" | "error"
|
|
|
|
|
|
>("idle");
|
2026-07-20 17:20:43 +08:00
|
|
|
|
const [frameIndex, setFrameIndex] = useState(0);
|
2026-07-20 20:50:27 +08:00
|
|
|
|
const [spriteReady, setSpriteReady] = useState(false);
|
|
|
|
|
|
const [spriteError, setSpriteError] = useState<string | null>(null);
|
|
|
|
|
|
const [gameMode, setGameMode] = useState(false);
|
|
|
|
|
|
const spriteImageRef = useRef<HTMLImageElement | null>(null);
|
|
|
|
|
|
const spriteCanvasRef = useRef<HTMLCanvasElement | null>(null);
|
2026-07-20 16:28:42 +08:00
|
|
|
|
|
2026-07-20 17:44:50 +08:00
|
|
|
|
useEffect(() => {
|
2026-07-20 20:50:27 +08:00
|
|
|
|
if (embedded) return;
|
2026-07-20 17:44:50 +08:00
|
|
|
|
document.documentElement.classList.add("pet-view");
|
|
|
|
|
|
return () => document.documentElement.classList.remove("pet-view");
|
2026-07-20 20:50:27 +08:00
|
|
|
|
}, [embedded]);
|
|
|
|
|
|
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const completionTimerRef = useRef<number | null>(null);
|
|
|
|
|
|
|
2026-07-20 20:50:27 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
let unlisten: (() => void) | undefined;
|
2026-07-21 14:43:14 +08:00
|
|
|
|
let unlistenRuntime: (() => void) | undefined;
|
|
|
|
|
|
void listen("pet-game-mode-toggle", () =>
|
|
|
|
|
|
setGameMode((current) => !current),
|
|
|
|
|
|
).then((cleanup) => {
|
2026-07-20 20:50:27 +08:00
|
|
|
|
unlisten = cleanup;
|
|
|
|
|
|
});
|
2026-07-21 14:43:14 +08:00
|
|
|
|
void listen<unknown>("connection-runtime-event", (event) => {
|
|
|
|
|
|
const parsed = boundRuntimeEventSchema.safeParse(event.payload);
|
|
|
|
|
|
if (!parsed.success || parsed.data.slot !== PET_TARGET_SLOT) return;
|
|
|
|
|
|
if (completionTimerRef.current !== null) {
|
|
|
|
|
|
window.clearTimeout(completionTimerRef.current);
|
|
|
|
|
|
completionTimerRef.current = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (parsed.data.eventType === "message.delta") setState("working");
|
|
|
|
|
|
if (parsed.data.eventType === "message.proactive") setState("speaking");
|
|
|
|
|
|
if (parsed.data.eventType === "message.completed") {
|
|
|
|
|
|
setState("speaking");
|
|
|
|
|
|
completionTimerRef.current = window.setTimeout(() => {
|
|
|
|
|
|
completionTimerRef.current = null;
|
|
|
|
|
|
setState("idle");
|
|
|
|
|
|
}, 2200);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (parsed.data.eventType === "error") setState("error");
|
|
|
|
|
|
}).then((cleanup) => {
|
|
|
|
|
|
unlistenRuntime = cleanup;
|
|
|
|
|
|
});
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
unlisten?.();
|
|
|
|
|
|
unlistenRuntime?.();
|
|
|
|
|
|
if (completionTimerRef.current !== null) {
|
|
|
|
|
|
window.clearTimeout(completionTimerRef.current);
|
|
|
|
|
|
completionTimerRef.current = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2026-07-20 20:50:27 +08:00
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const image = new Image();
|
|
|
|
|
|
image.onload = () => {
|
|
|
|
|
|
spriteImageRef.current = image;
|
|
|
|
|
|
setSpriteError(null);
|
|
|
|
|
|
setSpriteReady(true);
|
|
|
|
|
|
};
|
|
|
|
|
|
image.onerror = () => {
|
|
|
|
|
|
setSpriteError("????????");
|
|
|
|
|
|
};
|
|
|
|
|
|
image.src = AEMEATH_SPRITESHEET;
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
image.onload = null;
|
|
|
|
|
|
};
|
2026-07-20 17:44:50 +08:00
|
|
|
|
}, []);
|
|
|
|
|
|
|
2026-07-20 16:28:42 +08:00
|
|
|
|
useEffect(() => {
|
2026-07-20 17:00:42 +08:00
|
|
|
|
let cancelled = false;
|
2026-07-21 14:43:14 +08:00
|
|
|
|
void invoke<unknown>("connection_runtime_status")
|
|
|
|
|
|
.then((value) => {
|
2026-07-20 17:00:42 +08:00
|
|
|
|
if (cancelled) return;
|
2026-07-21 14:43:14 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const result = connectionRuntimeStatusSchema.parse(value);
|
|
|
|
|
|
const state = result.companion.state;
|
|
|
|
|
|
if (
|
|
|
|
|
|
state === "authExpired" ||
|
|
|
|
|
|
state === "fatalError" ||
|
|
|
|
|
|
state === "incompatible"
|
|
|
|
|
|
) {
|
|
|
|
|
|
setState("error");
|
|
|
|
|
|
} else if (
|
|
|
|
|
|
state === "syncing" ||
|
|
|
|
|
|
state === "connecting" ||
|
|
|
|
|
|
state === "authenticating"
|
|
|
|
|
|
) {
|
|
|
|
|
|
setState("working");
|
|
|
|
|
|
} else if (state === "reconnecting") {
|
|
|
|
|
|
setState("speaking");
|
|
|
|
|
|
} else if (state === "disconnected" || state === "offline") {
|
|
|
|
|
|
setState("resting");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setState("idle");
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch {
|
2026-07-20 17:00:42 +08:00
|
|
|
|
setState("idle");
|
|
|
|
|
|
}
|
2026-07-21 14:43:14 +08:00
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {
|
2026-07-20 17:00:42 +08:00
|
|
|
|
if (!cancelled) setState("idle");
|
2026-07-21 14:43:14 +08:00
|
|
|
|
});
|
2026-07-20 17:00:42 +08:00
|
|
|
|
return () => {
|
|
|
|
|
|
cancelled = true;
|
|
|
|
|
|
};
|
2026-07-20 16:28:42 +08:00
|
|
|
|
}, []);
|
|
|
|
|
|
|
2026-07-21 14:43:14 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
void invoke("set_pet_window_preferences", {
|
|
|
|
|
|
preferences: {
|
|
|
|
|
|
positionMode: "edge",
|
|
|
|
|
|
monitorIndex: 0,
|
|
|
|
|
|
alwaysOnTop: true,
|
|
|
|
|
|
gameMode,
|
|
|
|
|
|
},
|
|
|
|
|
|
}).catch(() => undefined);
|
|
|
|
|
|
}, [gameMode]);
|
|
|
|
|
|
|
2026-07-20 17:20:43 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
setFrameIndex(0);
|
|
|
|
|
|
const frames = AEMEATH_FRAMES[state];
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const timer = window.setInterval(
|
|
|
|
|
|
() => {
|
|
|
|
|
|
setFrameIndex((current) => (current + 1) % frames.length);
|
|
|
|
|
|
},
|
|
|
|
|
|
state === "resting" ? 180 : 125,
|
|
|
|
|
|
);
|
2026-07-20 17:20:43 +08:00
|
|
|
|
return () => window.clearInterval(timer);
|
|
|
|
|
|
}, [state]);
|
|
|
|
|
|
|
2026-07-21 14:43:14 +08:00
|
|
|
|
const frame =
|
|
|
|
|
|
AEMEATH_FRAMES[state][frameIndex % AEMEATH_FRAMES[state].length];
|
2026-07-20 17:20:43 +08:00
|
|
|
|
const frameRow = Math.floor(frame / 8);
|
|
|
|
|
|
const frameColumn = frame % 8;
|
|
|
|
|
|
|
2026-07-20 20:50:27 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const canvas = spriteCanvasRef.current;
|
|
|
|
|
|
const image = spriteImageRef.current;
|
|
|
|
|
|
if (!canvas || !image || !spriteReady) return;
|
|
|
|
|
|
const context = canvas.getContext("2d");
|
|
|
|
|
|
if (!context) {
|
2026-07-21 14:43:14 +08:00
|
|
|
|
setSpriteError("???? Canvas ?????");
|
2026-07-20 20:50:27 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
context.clearRect(0, 0, 192, 208);
|
|
|
|
|
|
context.imageSmoothingEnabled = false;
|
2026-07-21 14:43:14 +08:00
|
|
|
|
context.drawImage(
|
|
|
|
|
|
image,
|
|
|
|
|
|
frameColumn * 192,
|
|
|
|
|
|
frameRow * 208,
|
|
|
|
|
|
192,
|
|
|
|
|
|
208,
|
|
|
|
|
|
0,
|
|
|
|
|
|
0,
|
|
|
|
|
|
192,
|
|
|
|
|
|
208,
|
|
|
|
|
|
);
|
2026-07-20 20:50:27 +08:00
|
|
|
|
} catch (reason) {
|
|
|
|
|
|
setSpriteError(reason instanceof Error ? reason.message : "??????");
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [frameColumn, frameRow, spriteReady]);
|
|
|
|
|
|
|
2026-07-20 16:28:42 +08:00
|
|
|
|
return (
|
2026-07-20 20:50:27 +08:00
|
|
|
|
<main
|
2026-07-21 14:43:14 +08:00
|
|
|
|
className={`pet-window pet-window-${state}${gameMode ? " pet-window-game" : ""}${embedded ? " pet-window-embedded" : ""}`}
|
2026-07-20 20:50:27 +08:00
|
|
|
|
aria-label="AstrBot ??"
|
2026-07-21 14:43:14 +08:00
|
|
|
|
data-tauri-drag-region={!embedded ? "true" : undefined}
|
|
|
|
|
|
onMouseDown={(event) => {
|
|
|
|
|
|
if (embedded || event.button !== 0) return;
|
|
|
|
|
|
void getCurrentWindow().startDragging();
|
|
|
|
|
|
}}
|
2026-07-20 20:50:27 +08:00
|
|
|
|
onContextMenu={(event) => {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
void invoke("show_pet_context_menu");
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2026-07-20 17:20:43 +08:00
|
|
|
|
<div
|
2026-07-20 17:44:50 +08:00
|
|
|
|
className={`aemeath-pet-frame aemeath-pet-${state}`}
|
2026-07-20 17:20:43 +08:00
|
|
|
|
role="img"
|
|
|
|
|
|
aria-label={`桌宠状态:${state}`}
|
2026-07-20 17:44:50 +08:00
|
|
|
|
>
|
2026-07-20 20:50:27 +08:00
|
|
|
|
<canvas
|
|
|
|
|
|
ref={spriteCanvasRef}
|
|
|
|
|
|
className="aemeath-pet-sprite"
|
|
|
|
|
|
width={192}
|
|
|
|
|
|
height={208}
|
|
|
|
|
|
role="img"
|
|
|
|
|
|
aria-label={`pet-${state}`}
|
|
|
|
|
|
/>
|
2026-07-20 17:44:50 +08:00
|
|
|
|
</div>
|
2026-07-21 14:43:14 +08:00
|
|
|
|
{spriteError ? (
|
|
|
|
|
|
<span className="pet-render-error">{spriteError}</span>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
{!spriteReady && !spriteError ? (
|
|
|
|
|
|
<span className="pet-render-loading">Loading pet...</span>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
<span className="pet-window-status">
|
|
|
|
|
|
{state === "working"
|
|
|
|
|
|
? "正在写写画画"
|
|
|
|
|
|
: state === "resting"
|
|
|
|
|
|
? "休息中"
|
|
|
|
|
|
: state === "speaking"
|
|
|
|
|
|
? "正在回应"
|
|
|
|
|
|
: state === "error"
|
|
|
|
|
|
? "需要重新登录或检查连接"
|
|
|
|
|
|
: "陪伴中"}
|
|
|
|
|
|
</span>
|
2026-07-20 16:28:42 +08:00
|
|
|
|
</main>
|
2026-07-20 12:58:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
2026-07-21 14:43:14 +08:00
|
|
|
|
function DiagnosticsTools() {
|
|
|
|
|
|
const [result, setResult] = useState("");
|
|
|
|
|
|
const [host, setHost] = useState("127.0.0.1");
|
|
|
|
|
|
const [port, setPort] = useState("80");
|
|
|
|
|
|
const [processId, setProcessId] = useState("0");
|
|
|
|
|
|
const run = async (command: string, request?: Record<string, unknown>) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const value = await invoke<unknown>(
|
|
|
|
|
|
command,
|
|
|
|
|
|
request ? { request } : undefined,
|
|
|
|
|
|
);
|
|
|
|
|
|
setResult(JSON.stringify(value, null, 2));
|
|
|
|
|
|
} catch (reason) {
|
|
|
|
|
|
setResult(reason instanceof Error ? reason.message : String(reason));
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<section className="settings-grid">
|
|
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="前台窗口"
|
|
|
|
|
|
description="读取当前前台窗口的标题、类名和进程身份。"
|
|
|
|
|
|
>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => void run("inspect_foreground_window")}
|
|
|
|
|
|
>
|
|
|
|
|
|
检查前台窗口
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</SettingCard>
|
|
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="网络连通性"
|
|
|
|
|
|
description="只检查一个明确的主机和端口,不执行扫描。"
|
|
|
|
|
|
>
|
|
|
|
|
|
<input
|
|
|
|
|
|
value={host}
|
|
|
|
|
|
onChange={(event) => setHost(event.target.value)}
|
|
|
|
|
|
aria-label="网络主机"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<input
|
|
|
|
|
|
value={port}
|
|
|
|
|
|
onChange={(event) => setPort(event.target.value)}
|
|
|
|
|
|
aria-label="网络端口"
|
|
|
|
|
|
inputMode="numeric"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() =>
|
|
|
|
|
|
void run("check_network_target", {
|
|
|
|
|
|
host,
|
|
|
|
|
|
port: Number(port),
|
|
|
|
|
|
timeoutSeconds: 3,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
检查端口
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</SettingCard>
|
|
|
|
|
|
<SettingCard
|
|
|
|
|
|
title="指定进程"
|
|
|
|
|
|
description="输入进程 ID 后读取有限的进程摘要,不枚举全部进程。"
|
|
|
|
|
|
>
|
|
|
|
|
|
<input
|
|
|
|
|
|
value={processId}
|
|
|
|
|
|
onChange={(event) => setProcessId(event.target.value)}
|
|
|
|
|
|
aria-label="进程 ID"
|
|
|
|
|
|
inputMode="numeric"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() =>
|
|
|
|
|
|
void run("inspect_process", { processId: Number(processId) })
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
检查进程
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</SettingCard>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
{result ? <pre className="diagnostic-result">{result}</pre> : null}
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-20 12:58:42 +08:00
|
|
|
|
function DiagnosticsPage({
|
|
|
|
|
|
status,
|
|
|
|
|
|
onRefresh,
|
|
|
|
|
|
}: {
|
|
|
|
|
|
status: BootstrapStatus;
|
|
|
|
|
|
onRefresh: () => void;
|
|
|
|
|
|
}) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="page-stack">
|
|
|
|
|
|
<section className="status-grid" aria-label="bootstrap status">
|
|
|
|
|
|
<StatusCard label="Rust Core" value={status.rustCore} />
|
|
|
|
|
|
<StatusCard label="Platform" value={status.platform} />
|
|
|
|
|
|
<StatusCard label="App Version" value={status.appVersion} />
|
|
|
|
|
|
<StatusCard label="Protocol" value={status.protocolVersion} />
|
|
|
|
|
|
<StatusCard
|
|
|
|
|
|
label="Database Schema"
|
|
|
|
|
|
value={String(status.databaseSchemaVersion)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</section>
|
2026-07-21 14:43:14 +08:00
|
|
|
|
<DiagnosticsTools />
|
2026-07-20 12:58:42 +08:00
|
|
|
|
<section className="boundaries">
|
|
|
|
|
|
<span className="section-kicker">Security boundary</span>
|
|
|
|
|
|
<h2>本机能力保持可审计</h2>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li>凭据只在 Rust 与 Windows 安全存储之间流动。</li>
|
|
|
|
|
|
<li>两个 REST/SSE 槽位保持独立状态、会话、消息与未读数。</li>
|
|
|
|
|
|
<li>本机操作必须经过白名单、角色、路径和用户授权。</li>
|
|
|
|
|
|
<li>文件事务默认保留源文件,不静默覆盖目标。</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
<button type="button" onClick={onRefresh}>
|
|
|
|
|
|
刷新 IPC 状态
|
2026-07-18 20:34:47 +08:00
|
|
|
|
</button>
|
2026-07-20 12:58:42 +08:00
|
|
|
|
</div>
|
2026-07-18 20:34:47 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-20 12:58:42 +08:00
|
|
|
|
function SettingCard({
|
|
|
|
|
|
title,
|
|
|
|
|
|
description,
|
|
|
|
|
|
children,
|
|
|
|
|
|
}: {
|
|
|
|
|
|
title: string;
|
|
|
|
|
|
description: string;
|
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
|
}) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<section className="setting-card">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<span className="section-kicker">Settings</span>
|
|
|
|
|
|
<h2>{title}</h2>
|
|
|
|
|
|
<p>{description}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="setting-card-controls">{children}</div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-18 20:34:47 +08:00
|
|
|
|
interface StatusCardProps {
|
|
|
|
|
|
label: string;
|
|
|
|
|
|
value: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
function StatusCard({ label, value }: StatusCardProps) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<article className="status-card">
|
|
|
|
|
|
<span>{label}</span>
|
|
|
|
|
|
<strong>{value}</strong>
|
|
|
|
|
|
</article>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|