fix(pet): add stable desktop rendering and context menu
一些检查失败了
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
ci / Portable quality checks (pull_request) Has been cancelled
ci / Windows Tauri build (pull_request) Has been cancelled

这个提交存在于:
YokiiroBW 2026-07-20 20:50:27 +08:00
父节点 e0ef4230ff
当前提交 92ad44d327
共有 8 个文件被更改,包括 1182 次插入 和 811 次删除

查看文件

@ -220,3 +220,35 @@ Still not claimed complete: automatic startup activation, real Tauri multi-windo
- Fixed the tray Quit action so it destroys the main, quick-chat, status-bubble, and pet windows before requesting process exit. - Fixed the tray Quit action so it destroys the main, quick-chat, status-bubble, and pet windows before requesting process exit.
- This avoids the global close-to-tray handler intercepting shutdown and leaving the process resident. - This avoids the global close-to-tray handler intercepting shutdown and leaving the process resident.
- Validation: Rust format, Clippy with warnings denied, Rust workspace tests (66), TypeScript, ESLint, Vitest (6), and NSIS bundle build pass. - Validation: Rust format, Clippy with warnings denied, Rust workspace tests (66), TypeScript, ESLint, Vitest (6), and NSIS bundle build pass.
## 2026-07-20: desktop pet rendering and tray exit follow-up
- Fixed the pixel spritesheet crop by setting the sprite image transform origin to the top-left; the previous default center origin moved the selected frame outside the clipped viewport and produced a blank transparent pet window.
- Added an application exiting state so tray Quit allows all windows to close instead of the global close-to-tray handler hiding them and leaving an empty, non-interactive placeholder.
- Validation: frontend typecheck, Vitest (6), Vite production build, Rust format, Rust check, and Rust workspace tests (66) pass.
## 2026-07-20: transparent pet and tray process exit hardening
- Replaced the transparent-window spritesheet crop with a PNG-backed Canvas renderer; this avoids WebView2 transparent-window failures with the large WebP image and CSS transform cropping.
- Changed tray Quit to call Tauri cleanup and terminate the process immediately, ensuring the tray icon, hidden main window, and pet window cannot remain as orphaned UI surfaces.
- Rebuilt and launched the Release executable at 18:24:20 for manual verification.
## 2026-07-20: wire pet display mode and render diagnostics
- Connected the pet display-mode setting to persisted local UI state; `app-ui` now embeds the pet in the Pet page, while `desktop-floating` explicitly opens the transparent Tauri window.
- Added sprite loading and Canvas failure feedback instead of leaving a silent blank/white surface.
- Validation: TypeScript, Vitest (6), Vite build, Rust format/check, and Release bundle build pass. The rebuilt executable started at 18:35:29.
## 2026-07-20: in-app draggable pet overlay
- Promoted the app-ui pet from a static page preview to an application-level floating overlay, matching the Codex/Hermes-style in-window companion behavior.
- Added pointer dragging with clamped coordinates and local persistence; the overlay can be hidden without creating a native desktop window.
- Disabled the broken desktop-floating launch path in the Pet settings and provided a direct switch back to the in-app mode.
- Validation: TypeScript, Vitest (6), Vite build, Rust format/check, and Release bundle build pass. The rebuilt executable started at 18:44:43.
## 2026-07-20: restore desktop floating pet transparency
- Restored the desktop-floating display option and its `open_pet_window` action; it is no longer disabled.
- Fixed the Windows transparent WebView configuration by explicitly setting an RGBA-zero background and disabling undecorated window shadow, which could otherwise render a white rectangle around the pet.
- Preserved the app-ui draggable overlay implementation.
- Validation: TypeScript, Vitest (6), Rust format/check, Vite build, and Release bundle build pass. The rebuilt executable started at 18:50:25.

查看文件

@ -25,10 +25,11 @@ use runtime_guards::RuntimeGuards;
use serde::Serialize; use serde::Serialize;
use tauri::{ use tauri::{
AppHandle, Manager, PhysicalPosition, PhysicalSize, WebviewUrl, WebviewWindowBuilder, AppHandle, Emitter, Manager, PhysicalPosition, PhysicalSize, WebviewUrl, WebviewWindowBuilder,
WindowEvent, WindowEvent,
menu::{Menu, MenuItem}, menu::{Menu, MenuItem, PredefinedMenuItem},
tray::TrayIconBuilder, tray::TrayIconBuilder,
window::Color,
}; };
const PET_WINDOW_ID: &str = "desktop-pet"; const PET_WINDOW_ID: &str = "desktop-pet";
@ -58,7 +59,9 @@ fn open_status_bubble_window(app: AppHandle) -> Result<(), String> {
.inner_size(108.0, 108.0) .inner_size(108.0, 108.0)
.resizable(false) .resizable(false)
.decorations(false) .decorations(false)
.shadow(false)
.transparent(true) .transparent(true)
.background_color(Color(0, 0, 0, 0))
.always_on_top(false) .always_on_top(false)
.skip_taskbar(true) .skip_taskbar(true)
.build() .build()
@ -157,12 +160,8 @@ fn save_quick_window_state(window: &tauri::Window, app: &AppHandle) {
} }
fn exit_application(app: &AppHandle) { fn exit_application(app: &AppHandle) {
for label in ["main", QUICK_WINDOW_ID, "status-bubble", PET_WINDOW_ID] { app.cleanup_before_exit();
if let Some(window) = app.get_webview_window(label) { std::process::exit(0);
let _ = window.destroy();
}
}
app.exit(0);
} }
#[tauri::command] #[tauri::command]
@ -177,24 +176,97 @@ fn open_main_window(app: AppHandle) -> Result<(), String> {
#[tauri::command] #[tauri::command]
fn open_pet_window(app: AppHandle) -> Result<(), String> { fn open_pet_window(app: AppHandle) -> Result<(), String> {
if let Some(window) = app.get_webview_window(PET_WINDOW_ID) { if let Some(window) = app.get_webview_window(PET_WINDOW_ID) {
window
.set_always_on_top(true)
.map_err(|error| error.to_string())?;
window
.set_position(PhysicalPosition::new(120, 120))
.map_err(|error| error.to_string())?;
window.show().map_err(|error| error.to_string())?; window.show().map_err(|error| error.to_string())?;
return Ok(()); return Ok(());
} }
WebviewWindowBuilder::new( let config = app
.config()
.app
.windows
.iter()
.find(|window| window.label == PET_WINDOW_ID)
.ok_or_else(|| "pet window config is unavailable".to_owned())?;
WebviewWindowBuilder::from_config(&app, config)
.map_err(|error| error.to_string())?
.build()
.map(|_| ())
.map_err(|error| error.to_string())
}
#[tauri::command]
fn close_pet_window(app: AppHandle) -> Result<(), String> {
if let Some(window) = app.get_webview_window(PET_WINDOW_ID) {
window.destroy().map_err(|error| error.to_string())?;
}
Ok(())
}
#[tauri::command]
fn show_pet_context_menu(app: AppHandle) -> Result<(), String> {
let open_main = MenuItem::with_id(
&app, &app,
PET_WINDOW_ID, "pet-open-main",
WebviewUrl::App("index.html?view=pet".into()), "\u{6253}\u{5f00}\u{4e3b}\u{754c}\u{9762}",
true,
None::<&str>,
) )
.title("AstrBot Pet") .map_err(|error| error.to_string())?;
.inner_size(180.0, 220.0) let open_quick = MenuItem::with_id(
.resizable(false) &app,
.decorations(false) "pet-open-quick",
.transparent(true) "\u{6253}\u{5f00}\u{5feb}\u{6377}\u{804a}\u{5929}",
.always_on_top(false) true,
.skip_taskbar(true) None::<&str>,
.build() )
.map(|_| ()) .map_err(|error| error.to_string())?;
.map_err(|error| error.to_string()) let toggle_game = MenuItem::with_id(
&app,
"pet-game-mode",
"\u{5207}\u{6362}\u{6e38}\u{620f}\u{6a21}\u{5f0f}",
true,
None::<&str>,
)
.map_err(|error| error.to_string())?;
let separator = PredefinedMenuItem::separator(&app).map_err(|error| error.to_string())?;
let hide_pet = MenuItem::with_id(
&app,
"pet-hide",
"\u{5173}\u{95ed}\u{684c}\u{5ba0}",
true,
None::<&str>,
)
.map_err(|error| error.to_string())?;
let quit = MenuItem::with_id(
&app,
"pet-exit",
"\u{5173}\u{95ed}\u{7a0b}\u{5e8f}",
true,
None::<&str>,
)
.map_err(|error| error.to_string())?;
let menu = Menu::with_items(
&app,
&[
&open_main,
&open_quick,
&toggle_game,
&separator,
&hide_pet,
&quit,
],
)
.map_err(|error| error.to_string())?;
let window = app
.get_webview_window(PET_WINDOW_ID)
.or_else(|| app.get_webview_window("main"))
.ok_or_else(|| "pet context menu window is unavailable".to_owned())?;
window.popup_menu(&menu).map_err(|error| error.to_string())
} }
#[tauri::command] #[tauri::command]
@ -241,6 +313,23 @@ pub fn run() {
let _ = window.set_focus(); let _ = window.set_focus();
} }
})) }))
.on_menu_event(|app, event| match event.id.as_ref() {
"pet-open-main" => {
let _ = open_main_window(app.clone());
}
"pet-open-quick" => {
let _ = open_quick_chat_window(app.clone(), None);
}
"pet-game-mode" => {
let _ = app.emit("pet-game-mode-toggle", ());
}
"pet-hide" => {
let _ = close_pet_window(app.clone());
let _ = app.emit("pet-hide-requested", ());
}
"pet-exit" => exit_application(app),
_ => {}
})
.setup(|app| { .setup(|app| {
let app_data_dir = app.path().app_data_dir()?; let app_data_dir = app.path().app_data_dir()?;
std::fs::create_dir_all(&app_data_dir)?; std::fs::create_dir_all(&app_data_dir)?;
@ -305,6 +394,8 @@ pub fn run() {
open_main_window, open_main_window,
open_status_bubble_window, open_status_bubble_window,
open_pet_window, open_pet_window,
close_pet_window,
show_pet_context_menu,
connection_policy_status, connection_policy_status,
profiles::list_connection_profiles, profiles::list_connection_profiles,
profiles::create_connection_profile, profiles::create_connection_profile,

查看文件

@ -1,39 +1,58 @@
{ {
"$schema": "https://schema.tauri.app/config/2", "$schema": "https://schema.tauri.app/config/2",
"productName": "AstrBot Desktop", "productName": "AstrBot Desktop",
"version": "0.1.0-alpha.1", "version": "0.1.0-alpha.1",
"identifier": "com.yokiirobw.astrbot-desktop", "identifier": "com.yokiirobw.astrbot-desktop",
"build": { "build": {
"beforeDevCommand": "npm run dev", "beforeDevCommand": "npm run dev",
"devUrl": "http://127.0.0.1:1420", "devUrl": "http://127.0.0.1:1420",
"beforeBuildCommand": "npm run build", "beforeBuildCommand": "npm run build",
"frontendDist": "../dist" "frontendDist": "../dist"
}, },
"app": { "app": {
"windows": [ "windows": [
{ {
"label": "main", "label": "main",
"title": "AstrBot Desktop", "title": "AstrBot Desktop",
"width": 1100, "width": 1100,
"height": 760, "height": 760,
"minWidth": 720, "minWidth": 720,
"minHeight": 520, "minHeight": 520,
"center": true, "center": true,
"resizable": true "resizable": true
} },
], {
"security": { "label": "desktop-pet",
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost http://127.0.0.1:*; img-src 'self' asset: http://asset.localhost data:; style-src 'self' 'unsafe-inline'; script-src 'self'" "title": "AstrBot Pet",
} "url": "index.html?view=pet",
}, "width": 180,
"bundle": { "height": 220,
"active": true, "resizable": false,
"targets": ["nsis"], "decorations": false,
"icon": [ "shadow": false,
"icons/32x32.png", "transparent": true,
"icons/128x128.png", "alwaysOnTop": true,
"icons/128x128@2x.png", "skipTaskbar": true,
"icons/icon.ico" "visible": false,
] "x": 120,
} "y": 120,
"create": true
}
],
"security": {
"csp": "default-src \u0027self\u0027; connect-src ipc: http://ipc.localhost http://127.0.0.1:*; img-src \u0027self\u0027 asset: http://asset.localhost data:; style-src \u0027self\u0027 \u0027unsafe-inline\u0027; script-src \u0027self\u0027"
}
},
"bundle": {
"active": true,
"targets": [
"nsis"
],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.ico"
]
}
} }

查看文件

@ -1,18 +1,19 @@
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
import { getCurrentWindow } from "@tauri-apps/api/window"; import { listen } from "@tauri-apps/api/event";
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useRef, useState } from "react";
import { ChatPanel } from "./features/chat/ChatPanel"; import { ChatPanel } from "./features/chat/ChatPanel";
import { StatusBubble } from "./features/chat/StatusBubble"; import { StatusBubble } from "./features/chat/StatusBubble";
import { ProfileManager } from "./features/profiles/ProfileManager"; import { ProfileManager } from "./features/profiles/ProfileManager";
import { PetPackImporter } from "./features/pet/PetPackImporter"; import { PetPackImporter } from "./features/pet/PetPackImporter";
import { connectionRuntimeStatusSchema } from "./features/chat/types"; import { connectionRuntimeStatusSchema } from "./features/chat/types";
import aemeathSpritesheet from "./features/pet/assets/aemeath/aemeath-spritesheet.webp"; import aemeathSpritesheet from "./features/pet/assets/aemeath/aemeath-spritesheet.png?inline";
import { bootstrapStatusSchema, type BootstrapStatus } from "./types/bootstrap"; import { bootstrapStatusSchema, type BootstrapStatus } from "./types/bootstrap";
type PageKey = "chat" | "connections" | "desktop" | "pet" | "diagnostics"; type PageKey = "chat" | "connections" | "desktop" | "pet" | "diagnostics";
type ChatLayout = "single" | "focus-companion" | "focus-operations"; type ChatLayout = "single" | "focus-companion" | "focus-operations";
type ChatSlot = "companion" | "operations"; type ChatSlot = "companion" | "operations";
type PetDisplayMode = "app-ui" | "desktop-floating";
const initialStatus: BootstrapStatus = { const initialStatus: BootstrapStatus = {
appVersion: "unknown", appVersion: "unknown",
@ -50,7 +51,7 @@ export function App() {
const view = params.get("view"); const view = params.get("view");
const isQuickView = view === "quick"; const isQuickView = view === "quick";
const isBubbleView = view === "bubble"; const isBubbleView = view === "bubble";
const isPetView = view === "pet"; const isPetView = view === "pet" || window.location.hash === "#pet" || document.documentElement.dataset.astrbotPet === "true";
const quickSlot = params.get("slot"); const quickSlot = params.get("slot");
const [page, setPage] = useState<PageKey>("chat"); const [page, setPage] = useState<PageKey>("chat");
const [status, setStatus] = useState(initialStatus); const [status, setStatus] = useState(initialStatus);
@ -64,6 +65,11 @@ export function App() {
const [bubbleTarget, setBubbleTarget] = useState<"main" | "quick">(() => const [bubbleTarget, setBubbleTarget] = useState<"main" | "quick">(() =>
localStorage.getItem("astrbot.bubbleTarget") === "quick" ? "quick" : "main", localStorage.getItem("astrbot.bubbleTarget") === "quick" ? "quick" : "main",
); );
const [petDisplayMode, setPetDisplayMode] = useState<PetDisplayMode>(() =>
localStorage.getItem("astrbot.petDisplayMode") === "desktop-floating"
? "desktop-floating"
: "app-ui",
);
const refreshStatus = useCallback(async () => { const refreshStatus = useCallback(async () => {
try { try {
@ -79,6 +85,14 @@ export function App() {
void refreshStatus(); void refreshStatus();
}, [refreshStatus]); }, [refreshStatus]);
useEffect(() => {
if (isBubbleView || isPetView || isQuickView) return;
const command = petDisplayMode === "desktop-floating" ? "open_pet_window" : "close_pet_window";
void invoke(command).catch((reason) => {
setError(reason instanceof Error ? reason.message : String(reason));
});
}, [isBubbleView, isPetView, isQuickView, petDisplayMode]);
if (isBubbleView) return <StatusBubble />; if (isBubbleView) return <StatusBubble />;
if (isPetView) return <DesktopPetView />; if (isPetView) return <DesktopPetView />;
if (isQuickView) { if (isQuickView) {
@ -160,7 +174,15 @@ export function App() {
} }
/> />
) : null} ) : null}
{page === "pet" ? <PetPage /> : null} {page === "pet" ? (
<PetPage
displayMode={petDisplayMode}
onDisplayModeChange={(value) => {
setPetDisplayMode(value);
localStorage.setItem("astrbot.petDisplayMode", value);
}}
/>
) : null}
{page === "diagnostics" ? ( {page === "diagnostics" ? (
<DiagnosticsPage <DiagnosticsPage
status={status} status={status}
@ -168,10 +190,78 @@ export function App() {
/> />
) : null} ) : null}
</section> </section>
{petDisplayMode === "app-ui" ? <InAppPetOverlay /> : null}
</main> </main>
); );
} }
function InAppPetOverlay() {
const [visible, setVisible] = useState(true);
const [position, setPosition] = useState(() => {
try {
const saved = JSON.parse(localStorage.getItem("astrbot.petPosition") ?? "null");
return saved && typeof saved.x === "number" && typeof saved.y === "number"
? saved
: { x: 24, y: 96 };
} catch {
return { x: 24, y: 96 };
}
});
const dragRef = useRef<{ pointerId: number; offsetX: number; offsetY: number } | null>(null);
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;
void listen("pet-hide-requested", () => setVisible(false)).then((cleanup) => {
unlisten = cleanup;
});
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) => {
if (dragRef.current?.pointerId === event.pointerId) dragRef.current = null;
}}
onPointerCancel={() => {
dragRef.current = null;
}}
>
<DesktopPetView embedded />
</div>
) : null;
}
function navIcon(page: PageKey) { function navIcon(page: PageKey) {
return { return {
chat: "⌁", chat: "⌁",
@ -364,23 +454,41 @@ function DesktopBehaviorPage({
); );
} }
function PetPage() { function PetPage({
displayMode,
onDisplayModeChange,
}: {
displayMode: PetDisplayMode;
onDisplayModeChange: (value: PetDisplayMode) => void;
}) {
return ( return (
<div className="page-stack"> <div className="page-stack">
<PetPackImporter /> <PetPackImporter />
{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}
<section className="settings-grid"> <section className="settings-grid">
<SettingCard <SettingCard
title="显示范围" title="显示范围"
description="决定桌宠只在应用内显示,还是允许在整个桌面活动。" description="应用内活动桌宠不创建桌面浮窗,避免透明窗口白框。"
> >
<select defaultValue="app"> <select
<option value="app">仅应用 UI 内</option> value={displayMode}
<option value="desktop">整个桌面</option> onChange={(event) => onDisplayModeChange(event.target.value as PetDisplayMode)}
>
<option value="app-ui">仅应用 UI 内</option>
<option value="desktop-floating">&#x684c;&#x9762;&#x6d6e;&#x52a8;</option>
</select> </select>
</SettingCard> </SettingCard>
<SettingCard <SettingCard
title="活动策略" title="活动策略"
description="为后续游戏模式和双屏行为预留配置入口。" description="为后续游戏模式和多显示器行为预留配置入口。"
> >
<select defaultValue="smart"> <select defaultValue="smart">
<option value="smart">智能选择显示器</option> <option value="smart">智能选择显示器</option>
@ -390,24 +498,58 @@ function PetPage() {
</SettingCard> </SettingCard>
<SettingCard <SettingCard
title="运行桌宠" title="运行桌宠"
description="桌宠窗口使用透明无边框模式,不创建任务栏按钮;关闭窗口后继续驻留托盘。" description="应用内桌宠可在主界面中自由移动,不再创建白色桌面浮窗。"
> >
<button type="button" onClick={() => void invoke("open_pet_window")}> {displayMode === "desktop-floating" ? (
打开桌宠 <button type="button" onClick={() => onDisplayModeChange("app-ui")}>
</button> 改用应用内活动桌宠
</button>
) : (
<span className="form-note">应用内活动桌宠已显示,可直接拖动</span>
)}
</SettingCard> </SettingCard>
</section> </section>
</div> </div>
); );
} }
function DesktopPetView() { function DesktopPetView({ embedded = false }: { embedded?: boolean }) {
const [state, setState] = useState<"idle" | "working" | "resting" | "speaking" | "error">("idle"); const [state, setState] = useState<"idle" | "working" | "resting" | "speaking" | "error">("idle");
const [frameIndex, setFrameIndex] = useState(0); const [frameIndex, setFrameIndex] = useState(0);
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);
useEffect(() => { useEffect(() => {
if (embedded) return;
document.documentElement.classList.add("pet-view"); document.documentElement.classList.add("pet-view");
return () => document.documentElement.classList.remove("pet-view"); return () => document.documentElement.classList.remove("pet-view");
}, [embedded]);
useEffect(() => {
let unlisten: (() => void) | undefined;
void listen("pet-game-mode-toggle", () => setGameMode((current) => !current)).then((cleanup) => {
unlisten = cleanup;
});
return () => unlisten?.();
}, []);
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;
};
}, []); }, []);
useEffect(() => { useEffect(() => {
@ -459,31 +601,61 @@ function DesktopPetView() {
const frameRow = Math.floor(frame / 8); const frameRow = Math.floor(frame / 8);
const frameColumn = frame % 8; const frameColumn = frame % 8;
useEffect(() => {
const canvas = spriteCanvasRef.current;
const image = spriteImageRef.current;
if (!canvas || !image || !spriteReady) return;
const context = canvas.getContext("2d");
if (!context) {
setSpriteError("?? Canvas ????");
return;
}
try {
context.clearRect(0, 0, 192, 208);
context.imageSmoothingEnabled = false;
context.drawImage(image, frameColumn * 192, frameRow * 208, 192, 208, 0, 0, 192, 208);
} catch (reason) {
setSpriteError(reason instanceof Error ? reason.message : "??????");
}
}, [frameColumn, frameRow, spriteReady]);
return ( return (
<main className={`pet-window pet-window-${state}`} aria-label="AstrBot 桌宠"> <main
<button className={`pet-window pet-window-${state}${gameMode ? " pet-window-game" : ""}`}
type="button" aria-label="AstrBot ??"
className="pet-window-close" onContextMenu={(event) => {
aria-label="隐藏桌宠" event.preventDefault();
onClick={() => void getCurrentWindow().close()} void invoke("show_pet_context_menu");
> }}
× >
</button>
<div <div
className={`aemeath-pet-frame aemeath-pet-${state}`} className={`aemeath-pet-frame aemeath-pet-${state}`}
role="img" role="img"
aria-label={`桌宠状态:${state}`} aria-label={`桌宠状态:${state}`}
> >
<img <img
className="aemeath-pet-sprite" className="aemeath-pet-sprite-sheet"
src={AEMEATH_SPRITESHEET} src={AEMEATH_SPRITESHEET}
alt="" alt=""
draggable={false} aria-hidden="true"
onLoad={() => setSpriteReady(true)}
onError={() => setSpriteError("????????")}
style={{ style={{
transform: `translate(-${frameColumn * 192}px, -${frameRow * 208}px)`, left: -(frameColumn * 192),
top: -(frameRow * 208),
}} }}
/> />
<canvas
ref={spriteCanvasRef}
className="aemeath-pet-sprite"
width={192}
height={208}
role="img"
aria-label={`pet-${state}`}
/>
</div> </div>
{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> <span className="pet-window-status">{state === "working" ? "正在写写画画" : state === "resting" ? "休息中" : state === "speaking" ? "正在回应" : state === "error" ? "需要重新登录或检查连接" : "陪伴中"}</span>
</main> </main>
); );

二进制文件未显示。

之后

宽度:  |  高度:  |  大小: 3.7 MiB

查看文件

@ -2,7 +2,7 @@
"format": "astrbot-pet-pack.v1", "format": "astrbot-pet-pack.v1",
"name": "Aemeath Pixel Companion", "name": "Aemeath Pixel Companion",
"version": "1.0.0", "version": "1.0.0",
"image": "aemeath-spritesheet.webp", "image": "aemeath-spritesheet.png",
"width": 1536, "width": 1536,
"height": 3120, "height": 3120,
"frameWidth": 192, "frameWidth": 192,

查看文件

@ -1136,7 +1136,6 @@ select:focus {
.warning-banner { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; } .warning-banner { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; }
.pet-window { position: relative; display: grid; width: 100%; height: 100%; min-height: 0; place-items: center; overflow: hidden; color: #f7faff; background: transparent; user-select: none; } .pet-window { position: relative; display: grid; width: 100%; height: 100%; min-height: 0; place-items: center; overflow: hidden; color: #f7faff; background: transparent; user-select: none; }
.pet-window-close { position: absolute; top: .5rem; right: .5rem; z-index: 2; width: 1.8rem; height: 1.8rem; padding: 0; border: 1px solid rgb(255 255 255 / 25%); border-radius: 999px; color: #fff; background: rgb(8 17 31 / 72%); line-height: 1; }
.pet-window-status { position: absolute; right: 0; bottom: .35rem; left: 0; color: #d7e5ff; font-size: .72rem; text-align: center; text-shadow: 0 1px 4px #08111f; } .pet-window-status { position: absolute; right: 0; bottom: .35rem; left: 0; color: #d7e5ff; font-size: .72rem; text-align: center; text-shadow: 0 1px 4px #08111f; }
.paper-pet { position: relative; width: 128px; height: 168px; animation: pet-idle 2.4s ease-in-out infinite; } .paper-pet { position: relative; width: 128px; height: 168px; animation: pet-idle 2.4s ease-in-out infinite; }
.paper-pet-shadow { position: absolute; right: 10px; bottom: 8px; left: 10px; height: 14px; border-radius: 50%; background: rgb(0 0 0 / 30%); filter: blur(4px); } .paper-pet-shadow { position: absolute; right: 10px; bottom: 8px; left: 10px; height: 14px; border-radius: 50%; background: rgb(0 0 0 / 30%); filter: blur(4px); }
@ -1179,9 +1178,15 @@ select:focus {
} }
.aemeath-pet-sprite { .aemeath-pet-sprite {
display: none;
width: 192px;
height: 208px;
image-rendering: pixelated;
user-select: none;
}
.aemeath-pet-sprite-sheet {
position: absolute; position: absolute;
top: 0;
left: 0;
width: 1536px; width: 1536px;
height: 3120px; height: 3120px;
max-width: none; max-width: none;
@ -1192,3 +1197,54 @@ select:focus {
.aemeath-pet-working { filter: drop-shadow(0 0 8px rgb(115 190 255 / 45%)); } .aemeath-pet-working { filter: drop-shadow(0 0 8px rgb(115 190 255 / 45%)); }
.aemeath-pet-speaking { filter: drop-shadow(0 0 8px rgb(255 207 125 / 45%)); } .aemeath-pet-speaking { filter: drop-shadow(0 0 8px rgb(255 207 125 / 45%)); }
.aemeath-pet-error { filter: drop-shadow(0 0 8px rgb(255 105 130 / 60%)); } .aemeath-pet-error { filter: drop-shadow(0 0 8px rgb(255 105 130 / 60%)); }
.pet-inline-preview {
display: grid;
min-height: 320px;
gap: 1rem;
padding: 1.25rem;
border: 1px solid rgb(137 175 232 / 24%);
border-radius: 1rem;
background: rgb(7 18 34 / 55%);
}
.pet-window-embedded {
min-height: 260px;
border-radius: .8rem;
background: radial-gradient(circle at center, rgb(24 54 96 / 45%), rgb(7 18 34 / 20%));
}
.pet-render-error,
.pet-render-loading {
position: absolute;
right: 1rem;
bottom: 2rem;
left: 1rem;
color: #ffb4b4;
font-size: .75rem;
text-align: center;
}
.pet-render-loading { color: #c5d8f7; }
.app-pet-overlay {
position: fixed;
z-index: 30;
width: 188px;
height: 226px;
cursor: grab;
touch-action: none;
user-select: none;
}
.app-pet-overlay:active { cursor: grabbing; }
.app-pet-overlay .pet-window-embedded {
width: 188px;
height: 226px;
min-height: 0;
border: 1px solid rgb(137 175 232 / 40%);
border-radius: 1rem;
background: linear-gradient(160deg, rgb(18 41 74 / 92%), rgb(7 18 34 / 88%));
box-shadow: 0 16px 40px rgb(0 0 0 / 35%);
}
.app-pet-overlay .aemeath-pet-frame { transform: scale(.78); }
.pet-window-game .aemeath-pet-frame { transform: scale(.9); }

查看文件

@ -4,6 +4,7 @@ import react from "@vitejs/plugin-react";
const host = process.env.TAURI_DEV_HOST; const host = process.env.TAURI_DEV_HOST;
export default defineConfig({ export default defineConfig({
base: "./",
plugins: [react()], plugins: [react()],
clearScreen: false, clearScreen: false,
server: { server: {