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

@@ -99,6 +99,32 @@ pub fn default_location_file() -> Option<PathBuf> {
Some(base.join("jarvis-bot").join("location.json"))
}
/// Where the window's own browser data (WebView2) goes: `cache/webview` in the data folder once
/// there is one. Before the first-run wizard chose a folder it is a scratch folder in the system
/// temp folder (`JarvisBot-webview-<process id>`, `true`); WebView2 holds it until the app's process
/// has ended, so the app removes it on its next start (`remove_scratch_webview`).
pub fn webview_data_dir(location_file: &Path) -> (PathBuf, bool) {
match DataDir::locate(location_file) {
Some(d) => (d.path().join("cache").join("webview"), false),
None => (std::env::temp_dir().join(format!("{WEBVIEW_SCRATCH}{}", std::process::id())), true),
}
}
const WEBVIEW_SCRATCH: &str = "JarvisBot-webview-";
/// Remove the scratch browser data folders in `temp` (all of them, or only `only`); a folder still in
/// use stays and goes next time.
pub fn remove_scratch_webview(temp: &Path, only: Option<&Path>) {
let Ok(rd) = std::fs::read_dir(temp) else { return };
for e in rd.flatten() {
let p = e.path();
let ours = p.file_name().and_then(|n| n.to_str()).is_some_and(|n| n.starts_with(WEBVIEW_SCRATCH));
if ours && only.is_none_or(|o| o == p) {
let _ = std::fs::remove_dir_all(&p);
}
}
}
/// Free bytes on the disk that holds `path` (or its nearest existing parent).
pub fn free_bytes(path: &Path) -> Result<u64, DataDirError> {
let mut p = path;
@@ -145,6 +171,27 @@ mod tests {
assert_eq!(d.settings_file(), root.join("config").join("settings.json"));
}
#[test]
fn the_window_data_goes_in_the_data_folder_or_a_scratch_folder_that_is_removed() {
let root = temp_dir("wv");
let loc = root.join("cfg").join("location.json");
let (dir, scratch) = webview_data_dir(&loc);
assert!(scratch && dir.starts_with(std::env::temp_dir()), "no folder chosen yet: scratch in temp");
DataDir::choose(&root.join("data"), &loc).unwrap();
if std::env::var("JARVIS_DATA_DIR").is_err() {
assert_eq!(webview_data_dir(&loc), (root.join("data").join("cache").join("webview"), false));
}
// Scratch folders of earlier runs are removed; other folders stay.
let temp = root.join("tmp");
for n in ["JarvisBot-webview-1", "JarvisBot-webview-2", "other"] {
std::fs::create_dir_all(temp.join(n).join("EBWebView")).unwrap();
}
remove_scratch_webview(&temp, Some(&temp.join("JarvisBot-webview-2")));
assert!(temp.join("JarvisBot-webview-1").exists() && !temp.join("JarvisBot-webview-2").exists());
remove_scratch_webview(&temp, None);
assert!(!temp.join("JarvisBot-webview-1").exists() && temp.join("other").exists());
}
#[test]
fn a_relative_path_or_a_file_is_refused() {
assert!(DataDir::create(Path::new("relative/data")).unwrap_err().0.contains("absolute"));