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:
@@ -209,9 +209,15 @@ impl Ctx {
|
||||
let pump = |r: Box<dyn tokio::io::AsyncRead + Unpin + Send>| {
|
||||
let (last, status, index, tab) = (last.clone(), self.status.clone(), self.index, self.tab);
|
||||
tokio::spawn(async move {
|
||||
let mut lines = BufReader::new(r).lines();
|
||||
while let Ok(Some(l)) = lines.next_line().await {
|
||||
let l = l.trim().to_owned();
|
||||
let mut reader = BufReader::new(r);
|
||||
let mut buf = Vec::new();
|
||||
loop {
|
||||
buf.clear();
|
||||
match reader.read_until(b'\n', &mut buf).await {
|
||||
Ok(0) | Err(_) => break,
|
||||
Ok(_) => {}
|
||||
}
|
||||
let l = decode_line(&buf).trim().to_owned();
|
||||
if l.is_empty() {
|
||||
continue;
|
||||
}
|
||||
@@ -246,6 +252,31 @@ impl Ctx {
|
||||
}
|
||||
}
|
||||
|
||||
/// One output line as text: UTF-8 when it is, else (Windows without the UTF-8 option) the PC's OEM
|
||||
/// code page, which console programs print in; never an error, so the reading goes on.
|
||||
pub fn decode_line(bytes: &[u8]) -> String {
|
||||
if let Ok(s) = std::str::from_utf8(bytes) {
|
||||
return s.to_owned();
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use windows_sys::Win32::Globalization::{MultiByteToWideChar, CP_OEMCP};
|
||||
let len = i32::try_from(bytes.len()).unwrap_or(i32::MAX);
|
||||
// SAFETY: the input pointer and length describe `bytes`; the first call only measures, the
|
||||
// second writes at most `n` UTF-16 units into a buffer of that size.
|
||||
unsafe {
|
||||
let n = MultiByteToWideChar(CP_OEMCP, 0, bytes.as_ptr(), len, std::ptr::null_mut(), 0);
|
||||
if n > 0 {
|
||||
let mut wide = vec![0u16; n as usize];
|
||||
if MultiByteToWideChar(CP_OEMCP, 0, bytes.as_ptr(), len, wide.as_mut_ptr(), n) == n {
|
||||
return String::from_utf16_lossy(&wide);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
String::from_utf8_lossy(bytes).into_owned()
|
||||
}
|
||||
|
||||
/// End `child` and every process it started, and wait for it.
|
||||
async fn kill_tree(child: &mut tokio::process::Child) {
|
||||
if let Some(pid) = child.id() {
|
||||
@@ -385,6 +416,10 @@ impl Installer {
|
||||
pub fn cancel(&self) {
|
||||
self.cancel.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
pub fn running(&self) -> bool {
|
||||
self.running.load(Ordering::SeqCst)
|
||||
}
|
||||
}
|
||||
|
||||
// ---- the real steps -------------------------------------------------------------------------------
|
||||
@@ -693,6 +728,21 @@ mod tests {
|
||||
assert!(t.elapsed() < std::time::Duration::from_secs(5));
|
||||
}
|
||||
|
||||
/// A Windows PC without the UTF-8 option prints in its code page (CP949 for Korean): such a line
|
||||
/// must not end the reading, or every later line and the error are lost.
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn output_that_is_not_utf8_does_not_stop_the_reading() {
|
||||
let l = layout("inst9");
|
||||
let status = Arc::new(Mutex::new(vec![StepStatus { id: "x".into(), label: "".into(), size_hint: "".into(),
|
||||
state: StepState::Running, bytes: None, note: None }]));
|
||||
let ctx = Ctx { layout: l, status: status.clone(), index: 0, cancel: Arc::new(AtomicBool::new(false)), tab: "install" };
|
||||
// "설치 중" in CP949, then two plain lines and a failure.
|
||||
let script = r"printf '\274\263\304\241 \301\337\\n'; echo 'step two'; echo 'last words'; exit 2";
|
||||
let err = ctx.run(Path::new("sh"), &["-c", script]).await.unwrap_err();
|
||||
assert!(err.contains("last words"), "{err}");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn a_cancel_ends_the_command_and_everything_it_started() {
|
||||
|
||||
Reference in New Issue
Block a user