diff --git a/README.md b/README.md index 5221e76..56e7896 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ or `cargo run --release`. On start you are prompted for a store passphrase (echo off, like other CLI passwords) or set `ONIONWIRE_STORE_PASSPHRASE`. Empty passphrase is rejected; a wrong passphrase does not open chat. Then you should see `onionwire: bootstrapping Arti…` on stderr. Directory bootstrap is usually under a minute; the onion is ready once a probe connect works (combined Arti status may still say Bootstrapping). Fail closed at 360s. Data lives in `ONIONWIRE_HOME` if set, otherwise `~/.local/share/onionwire/` (`onionwire.db` + Arti state, mode 0700). First open creates an ed25519 identity key. That key **is** you. -Then `F2` to share your invite, `F3` to paste a friend’s. Mouse-select the `onionwire:v1:…` line to copy. Highlight them in the roster, type in the composer, Enter to send. Footer shows `sending`, then `sent` or `send failed` — the TUI stays usable while Tor retries (up to 180s). Fail closed: if their onion is down, send fails — no outbox. +Then `F2` to share your invite, `F3` to paste a friend’s. Mouse-select the `onionwire:v1:…` line to copy. Highlight them in the roster, type in the composer, Enter to send. Fail closed: if their onion is down, send fails — no outbox. ## Friends are keys diff --git a/src/tui.rs b/src/tui.rs index a52e8e2..dda019d 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -1,6 +1,5 @@ use std::io; -use std::sync::{mpsc, Arc}; -use std::time::Duration; +use std::sync::Arc; use ratatui::crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; use ratatui::layout::{Constraint, Layout, Rect}; @@ -20,18 +19,6 @@ const C_STALE: Color = Color::Rgb(210, 180, 80); const C_HL_BG: Color = Color::Rgb(48, 42, 28); const C_BORDER: Color = Color::Rgb(72, 84, 64); -/// How long the TUI waits for a key before redrawing (so background send can update status). -pub const TUI_POLL: Duration = Duration::from_millis(100); - -/// Non-blocking read of a background send/job status. Never waits on Tor. -pub fn take_job_result(rx: &mpsc::Receiver) -> Option { - match rx.try_recv() { - Ok(s) => Some(s), - Err(mpsc::TryRecvError::Empty) => None, - Err(mpsc::TryRecvError::Disconnected) => Some("send failed".into()), - } -} - pub fn fingerprint_mismatch_banner() -> &'static str { "fingerprint mismatch" } @@ -621,7 +608,6 @@ struct App { help_open: bool, who_open: bool, chat_scroll: u16, - job_rx: Option>, } enum Screen { @@ -680,17 +666,12 @@ impl App { help_open: false, who_open: false, chat_scroll: 0, - job_rx: None, }) } fn run(&mut self, terminal: &mut DefaultTerminal) -> Result { loop { - self.drain_job(); terminal.draw(|f| self.draw(f)).map_err(|e| e.to_string())?; - if !event::poll(TUI_POLL).map_err(io_err)? { - continue; - } let Event::Key(key) = event::read().map_err(io_err)? else { continue; }; @@ -1253,34 +1234,14 @@ impl App { self.status_note = Some("no friend selected".into()); return Ok(()); }; - if self.job_rx.is_some() { - self.status_note = Some("already sending".into()); - return Ok(()); - } let pk = friend.pubkey.clone(); - let body = text.as_bytes().to_vec(); - let node = Arc::clone(&self.node); - let (tx, rx) = mpsc::channel(); - self.status_note = Some("sending".into()); - std::mem::drop(self.rt.spawn(async move { - let note = match node.send(&pk, &body).await { - Ok(()) => "sent".to_string(), - Err(e) => format!("send failed: {e}"), - }; - let _ = tx.send(note); - })); - self.job_rx = Some(rx); + match self.rt.block_on(self.node.send(&pk, text.as_bytes())) { + Ok(()) => self.status_note = Some("sent".into()), + Err(e) => self.status_note = Some(format!("send failed: {e}")), + } Ok(()) } - fn drain_job(&mut self) { - let Some(note) = self.job_rx.as_ref().and_then(take_job_result) else { - return; - }; - self.status_note = Some(note); - self.job_rx = None; - } - fn who_body(&self) -> String { let Some(friend) = self.friends.get(self.selected) else { return "no friend selected\n\nEsc closes".into(); diff --git a/tests/send.rs b/tests/send.rs index ce5341a..8aedab5 100644 --- a/tests/send.rs +++ b/tests/send.rs @@ -1,10 +1,6 @@ //! Composer Enter must send chat to the selected friend, not only slash commands. -use onionwire::tui::{ - composer_enter, take_job_result, ComposerAction, SlashCmd, WipeKind, TUI_POLL, -}; -use std::sync::mpsc; -use std::time::{Duration, Instant}; +use onionwire::tui::{composer_enter, ComposerAction, SlashCmd, WipeKind}; #[test] fn enter_plain_text_is_send() { @@ -47,28 +43,3 @@ fn enter_unknown_slash_is_not_chat() { Some(ComposerAction::UnknownSlash("/nope".into())) ); } - -#[test] -fn take_job_result_is_nonblocking_when_empty() { - let (tx, rx) = mpsc::channel::(); - let start = Instant::now(); - assert_eq!(take_job_result(&rx), None); - assert!( - start.elapsed() < Duration::from_millis(50), - "empty job rx must not wait on the 180s send retry" - ); - drop(tx); -} - -#[test] -fn take_job_result_reads_status_without_blocking() { - let (tx, rx) = mpsc::channel(); - tx.send("sent".into()).unwrap(); - assert_eq!(take_job_result(&rx).as_deref(), Some("sent")); -} - -#[test] -fn tui_poll_is_short_so_keys_keep_working() { - assert!(TUI_POLL <= Duration::from_millis(200)); - assert!(TUI_POLL > Duration::ZERO); -}