feat(app): chat channel name/topic sync, TTS speed, safe window close

Review follow-ups to M5.

- Chat channel names and topics (app/src/channel_sync.rs): a channel with
  syncDiscord (default on) gets its name and description as its Discord
  name and topic when saved; registering fills them from Discord;
  Discord's form of the name is written back; a topic over 1,024
  characters is refused before saving; a rate-limited edit is pending and
  retried once by itself with the latest text; a missing permission fails
  with the reason and the app keeps the text. Commands
  discord_channel_info and channel_sync_status. Checked on real Discord
  with a temporary channel (fill, edit, rate limit, automatic retry).
- voice.tts.speed (0.5-2.0) on the model screen, passed to the worker as
  --melo-speed. MeloTTS's Korean model has one voice, so no voice choice.
- Closing the window runs AdminApi::shutdown first: an install in
  progress is cancelled and waited for, the services stop, a failed run's
  leftovers (Strata) are cleared (Controller::shutdown). If that fails the
  window stays open with the reason; closing again quits.
- WebView2 data goes in the data folder (cache/webview), or a temp scratch
  folder before one is chosen, removed at the next start: %APPDATA%\JarvisBot
  holds only the location file.
- Command output that is not UTF-8 (CP949 on a PC without the UTF-8
  option) is decoded in the OEM code page instead of ending the reading.

Verified on the win-ci VM: closing during the install leaves no process,
no --location keeps only location.json under %APPDATA%, the unit tests on
Windows 168/168.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-12 19:23:26 +09:00
parent 76144fb19b
commit 91d0109139
18 changed files with 895 additions and 65 deletions

View File

@@ -1,23 +1,33 @@
//! Jarvis management app: one Tauri 2 window over the app core (`app/src/admin.spec.md`, "Screens").
//! The screens (`app/ui`) call `invoke("admin", {command, args})`, passed to the same `AdminApi` the
//! development server uses. Closing the window stops the services the app started.
//! Jarvis management app: one Tauri 2 window over the app core (`app/src/admin.spec.md`, "Window
//! and Windows build"). The screens (`app/ui`) call `invoke("admin", {command, args})`, passed to the
//! same `AdminApi` the development server uses. Closing the window first stops what the app started;
//! if that cannot be confirmed the window stays open and says so, and closing it again quits.
//!
//! jarvis [--location FILE]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::path::PathBuf;
use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::Arc;
use jarvis_app::admin_api::AdminApi;
use serde_json::Value;
use tauri::{Manager, RunEvent, WebviewUrl, WebviewWindowBuilder};
use tauri::{Emitter, Manager, RunEvent, WebviewUrl, WebviewWindowBuilder, WindowEvent};
struct Api(Arc<AdminApi>);
/// Where closing stands: open, closing (stopping what runs), or the stop could not be confirmed.
const OPEN: u8 = 0;
const CLOSING: u8 = 1;
const CLOSE_FAILED: u8 = 2;
struct Api {
api: Arc<AdminApi>,
phase: AtomicU8,
}
#[tauri::command]
async fn admin(api: tauri::State<'_, Api>, command: String, args: Option<Value>) -> Result<Value, String> {
api.0.call(&command, args.unwrap_or(Value::Null)).await
async fn admin(state: tauri::State<'_, Api>, command: String, args: Option<Value>) -> Result<Value, String> {
state.api.call(&command, args.unwrap_or(Value::Null)).await
}
fn arg(name: &str) -> Option<String> {
@@ -33,30 +43,62 @@ fn main() {
let hub = jarvis_app::logs::LogHub::new(logs.as_deref());
jarvis_app::logs::install(hub.clone());
let api = Arc::new(AdminApi::new(&location, hub));
// The window's own browser data sits next to the location file, not in a folder of its own.
let webview_data = location.parent().map(|p| p.join("webview"));
// The window's browser data: in the data folder, or a scratch folder in the system temp folder
// before there is one. WebView2 holds that folder until this process has ended, so scratch
// folders of earlier runs are removed here, at the next start.
jarvis_app::datadir::remove_scratch_webview(&std::env::temp_dir(), None);
let (webview_data, _) = jarvis_app::datadir::webview_data_dir(&location);
let app = tauri::Builder::default()
.manage(Api(api.clone()))
.manage(Api { api, phase: AtomicU8::new(OPEN) })
.invoke_handler(tauri::generate_handler![admin])
.setup(move |app| {
let mut w = WebviewWindowBuilder::new(app, "main", WebviewUrl::App("index.html".into()))
.title("Jarvis 관리")
.inner_size(1200.0, 820.0)
.min_inner_size(900.0, 600.0);
if let Some(dir) = webview_data.clone() {
w = w.data_directory(dir);
.setup({
move |app| {
WebviewWindowBuilder::new(app, "main", WebviewUrl::App("index.html".into()))
.title("Jarvis 관리")
.inner_size(1200.0, 820.0)
.min_inner_size(900.0, 600.0)
.data_directory(webview_data)
.build()?;
Ok(())
}
})
.on_window_event(|window, event| {
let WindowEvent::CloseRequested { api: close, .. } = event else { return };
let state = window.state::<Api>();
match state.phase.load(Ordering::SeqCst) {
CLOSE_FAILED => {
jarvis_app::warn_log!("app", "window closed again: quitting although the stop was not confirmed");
}
CLOSING => close.prevent_close(),
_ => {
close.prevent_close();
state.phase.store(CLOSING, Ordering::SeqCst);
let _ = window.emit("closing", ());
let (handle, api) = (window.app_handle().clone(), state.api.clone());
tauri::async_runtime::spawn(async move {
jarvis_app::info_log!("app", "window closing: stopping what the app started");
match api.shutdown().await {
Ok(()) => handle.exit(0),
Err(e) => {
handle.state::<Api>().phase.store(CLOSE_FAILED, Ordering::SeqCst);
let _ = handle.emit("close-failed", e);
}
}
});
}
}
w.build()?;
Ok(())
})
.build(tauri::generate_context!())
.expect("the window did not start");
app.run(move |handle, event| {
if let RunEvent::ExitRequested { .. } = event {
jarvis_app::info_log!("app", "window closed: stopping the services");
let api = handle.state::<Api>().0.clone();
tauri::async_runtime::block_on(api.shutdown());
match event {
// Quitting another way (the system shutting down) still stops what runs.
RunEvent::ExitRequested { .. } if handle.state::<Api>().phase.load(Ordering::SeqCst) == OPEN => {
let api = handle.state::<Api>().api.clone();
let _ = tauri::async_runtime::block_on(api.shutdown());
}
_ => {}
}
});
}