feat/p02-dual-connections #3
共有 4 个文件被更改,包括 123 次插入 和 6 次删除
|
|
@ -58,7 +58,10 @@ fn open_status_bubble_window(app: AppHandle) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn open_quick_chat_window(app: AppHandle) -> Result<(), String> {
|
fn open_quick_chat_window(
|
||||||
|
app: AppHandle,
|
||||||
|
slot: Option<desktop_protocol::ActiveSlotKind>,
|
||||||
|
) -> Result<(), String> {
|
||||||
if let Some(window) = app.get_webview_window("quick-chat") {
|
if let Some(window) = app.get_webview_window("quick-chat") {
|
||||||
window.show().map_err(|error| error.to_string())?;
|
window.show().map_err(|error| error.to_string())?;
|
||||||
window.set_focus().map_err(|error| error.to_string())?;
|
window.set_focus().map_err(|error| error.to_string())?;
|
||||||
|
|
@ -67,7 +70,15 @@ fn open_quick_chat_window(app: AppHandle) -> Result<(), String> {
|
||||||
WebviewWindowBuilder::new(
|
WebviewWindowBuilder::new(
|
||||||
&app,
|
&app,
|
||||||
"quick-chat",
|
"quick-chat",
|
||||||
WebviewUrl::App("index.html?view=quick".into()),
|
WebviewUrl::App(match slot {
|
||||||
|
Some(desktop_protocol::ActiveSlotKind::Companion) => {
|
||||||
|
"index.html?view=quick&slot=companion".into()
|
||||||
|
}
|
||||||
|
Some(desktop_protocol::ActiveSlotKind::Operations) => {
|
||||||
|
"index.html?view=quick&slot=operations".into()
|
||||||
|
}
|
||||||
|
None => "index.html?view=quick".into(),
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.title("AstrBot Quick Chat")
|
.title("AstrBot Quick Chat")
|
||||||
.inner_size(420.0, 620.0)
|
.inner_size(420.0, 620.0)
|
||||||
|
|
@ -78,6 +89,15 @@ fn open_quick_chat_window(app: AppHandle) -> Result<(), String> {
|
||||||
.map_err(|error| error.to_string())
|
.map_err(|error| error.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn open_main_window(app: AppHandle) -> Result<(), String> {
|
||||||
|
let window = app
|
||||||
|
.get_webview_window("main")
|
||||||
|
.ok_or_else(|| "main window is unavailable".to_owned())?;
|
||||||
|
window.show().map_err(|error| error.to_string())?;
|
||||||
|
window.set_focus().map_err(|error| error.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn bootstrap_status(
|
fn bootstrap_status(
|
||||||
database: tauri::State<'_, ApplicationDatabase>,
|
database: tauri::State<'_, ApplicationDatabase>,
|
||||||
|
|
@ -167,6 +187,7 @@ pub fn run() {
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
bootstrap_status,
|
bootstrap_status,
|
||||||
open_quick_chat_window,
|
open_quick_chat_window,
|
||||||
|
open_main_window,
|
||||||
open_status_bubble_window,
|
open_status_bubble_window,
|
||||||
connection_policy_status,
|
connection_policy_status,
|
||||||
profiles::list_connection_profiles,
|
profiles::list_connection_profiles,
|
||||||
|
|
|
||||||
60
src/App.tsx
60
src/App.tsx
|
|
@ -1,4 +1,4 @@
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
|
||||||
import { ChatPanel } from "./features/chat/ChatPanel";
|
import { ChatPanel } from "./features/chat/ChatPanel";
|
||||||
|
|
@ -18,11 +18,21 @@ export function App() {
|
||||||
const view = new URLSearchParams(window.location.search).get("view");
|
const view = new URLSearchParams(window.location.search).get("view");
|
||||||
const isQuickView = view === "quick";
|
const isQuickView = view === "quick";
|
||||||
const isBubbleView = view === "bubble";
|
const isBubbleView = view === "bubble";
|
||||||
|
const quickSlot = new URLSearchParams(window.location.search).get("slot");
|
||||||
const [status, setStatus] = useState(initialStatus);
|
const [status, setStatus] = useState(initialStatus);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [chatLayout, setChatLayout] = useState<
|
const [chatLayout, setChatLayout] = useState<
|
||||||
"single" | "focus-companion" | "focus-operations"
|
"single" | "focus-companion" | "focus-operations"
|
||||||
>("single");
|
>("single");
|
||||||
|
const [quickTarget, setQuickTarget] = useState<"companion" | "operations">(
|
||||||
|
() =>
|
||||||
|
localStorage.getItem("astrbot.quickTarget") === "operations"
|
||||||
|
? "operations"
|
||||||
|
: "companion",
|
||||||
|
);
|
||||||
|
const [bubbleTarget, setBubbleTarget] = useState<"main" | "quick">(() =>
|
||||||
|
localStorage.getItem("astrbot.bubbleTarget") === "quick" ? "quick" : "main",
|
||||||
|
);
|
||||||
|
|
||||||
const refreshStatus = useCallback(async () => {
|
const refreshStatus = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -42,7 +52,15 @@ export function App() {
|
||||||
if (isQuickView)
|
if (isQuickView)
|
||||||
return (
|
return (
|
||||||
<main className="quick-app-shell">
|
<main className="quick-app-shell">
|
||||||
<ChatPanel />
|
<ChatPanel
|
||||||
|
fixedSlot={
|
||||||
|
quickSlot === "operations"
|
||||||
|
? "operations"
|
||||||
|
: quickSlot === "companion"
|
||||||
|
? "companion"
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -82,11 +100,47 @@ export function App() {
|
||||||
<div className="chat-actions">
|
<div className="chat-actions">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => void invoke("open_quick_chat_window")}
|
onClick={() =>
|
||||||
|
void invoke("open_quick_chat_window", { slot: quickTarget })
|
||||||
|
}
|
||||||
>
|
>
|
||||||
打开快速聊天
|
打开快速聊天
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<section className="desktop-behavior-settings" aria-label="??????">
|
||||||
|
<label>
|
||||||
|
<span>????????</span>
|
||||||
|
<select
|
||||||
|
value={quickTarget}
|
||||||
|
onChange={(event) => {
|
||||||
|
const value =
|
||||||
|
event.target.value === "operations"
|
||||||
|
? "operations"
|
||||||
|
: "companion";
|
||||||
|
setQuickTarget(value);
|
||||||
|
localStorage.setItem("astrbot.quickTarget", value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="companion">Companion / ??</option>
|
||||||
|
<option value="operations">Operations / ??</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>??????</span>
|
||||||
|
<select
|
||||||
|
value={bubbleTarget}
|
||||||
|
onChange={(event) => {
|
||||||
|
const value = event.target.value === "quick" ? "quick" : "main";
|
||||||
|
setBubbleTarget(value);
|
||||||
|
localStorage.setItem("astrbot.bubbleTarget", value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="main">?????</option>
|
||||||
|
<option value="quick">??????</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section className="chat-workspace" aria-label="???????">
|
<section className="chat-workspace" aria-label="???????">
|
||||||
<div className="chat-workspace-toolbar">
|
<div className="chat-workspace-toolbar">
|
||||||
<strong>????</strong>
|
<strong>????</strong>
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,21 @@ export function StatusBubble() {
|
||||||
<button
|
<button
|
||||||
className={active ? "status-bubble connected" : "status-bubble"}
|
className={active ? "status-bubble connected" : "status-bubble"}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => void invoke("open_quick_chat_window")}
|
onClick={() => {
|
||||||
|
const target =
|
||||||
|
localStorage.getItem("astrbot.bubbleTarget") === "quick"
|
||||||
|
? "quick"
|
||||||
|
: "main";
|
||||||
|
if (target === "quick") {
|
||||||
|
const slot =
|
||||||
|
localStorage.getItem("astrbot.quickTarget") === "operations"
|
||||||
|
? "operations"
|
||||||
|
: "companion";
|
||||||
|
void invoke("open_quick_chat_window", { slot });
|
||||||
|
} else {
|
||||||
|
void invoke("open_main_window");
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<span className="status-bubble-orb" />
|
<span className="status-bubble-orb" />
|
||||||
<span className="status-bubble-label">{visibleState}</span>
|
<span className="status-bubble-label">{visibleState}</span>
|
||||||
|
|
|
||||||
|
|
@ -663,3 +663,31 @@ select:focus {
|
||||||
border-color: #8db9ff;
|
border-color: #8db9ff;
|
||||||
box-shadow: 0 0 0 2px rgb(141 185 255 / 22%);
|
box-shadow: 0 0 0 2px rgb(141 185 255 / 22%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.desktop-behavior-settings {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(220px, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
margin: 1rem 0;
|
||||||
|
padding: 1rem;
|
||||||
|
border: 1px solid rgb(137 175 232 / 24%);
|
||||||
|
border-radius: 0.9rem;
|
||||||
|
background: rgb(13 29 52 / 60%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-behavior-settings label {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.45rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-behavior-settings span {
|
||||||
|
color: #c7d4e9;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 760px) {
|
||||||
|
.desktop-behavior-settings {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
正在加载…
添加表格
在新工单中引用