budctlfeb7482
The worker reports the idle close once
With debug on, the Android app showed "session closed after 10 s" twice: the worker sent it as a debug note and as a log line, and on Android both go to the same log. The worker now only logs it. The desktop app keeps the line on stderr with --debug: its Report echoes the worker's lines there when debug is on, so the commands, connects and failures also show between the frames, as on the phone.
+7 −4
2 files changed
- M crates/budctl-core/src/worker.rs +2 −3
- M crates/budctl-gui/src/worker.rs +5 −1
| @@ -10,7 +10,6 @@ use std::sync::mpsc::{self, Receiver, RecvTimeoutError, Sender}; | |||
| 10 | 10 | use std::thread; | |
| 11 | 11 | use std::time::{Duration, Instant}; | |
| 12 | 12 | ||
| 13 | − | use crate::debug; | |
| 14 | 13 | use crate::devices::Session; | |
| 15 | 14 | use crate::error::{Error, Kind, Result}; | |
| 16 | 15 | use crate::status::{ | |
| @@ -108,7 +107,8 @@ pub trait Report: Send { | |||
| 108 | 107 | /// An answer to a command, or [`Event::Found`] or [`Event::Lost`]. | |
| 109 | 108 | fn event(&self, event: Event); | |
| 110 | 109 | ||
| 111 | − | /// A line for the front end's log: each command, sessions opening and closing, failures. | |
| 110 | + | /// A line for the front end's log: each command, sessions opening and closing, failures. A | |
| 111 | + | /// front end that prints debug output elsewhere shows these there too, as context. | |
| 112 | 112 | fn log(&self, line: &str); | |
| 113 | 113 | } | |
| 114 | 114 | ||
| @@ -176,7 +176,6 @@ impl Worker { | |||
| 176 | 176 | if self.last_command.elapsed() >= self.idle { | |
| 177 | 177 | self.session = None; | |
| 178 | 178 | let message = format!("session closed after {} s without a command", self.idle.as_secs()); | |
| 179 | − | debug::note(|| message.clone()); | |
| 180 | 179 | self.report.log(&message); | |
| 181 | 180 | } else if let Err(error) = session.serve() { | |
| 182 | 181 | self.session = None; | |
| @@ -36,7 +36,8 @@ pub fn run(&(device, idle): &(Option<BdAddr>, Duration)) -> impl Stream<Item = M | |||
| 36 | 36 | }) | |
| 37 | 37 | } | |
| 38 | 38 | ||
| 39 | − | /// The window's side of the worker: events go to the subscription, lines to the GUI's log. | |
| 39 | + | /// The window's side of the worker: events go to the subscription, lines to the GUI's log and, | |
| 40 | + | /// with `--debug`, between the frames on stderr. | |
| 40 | 41 | struct Window(channel::UnboundedSender<Event>); | |
| 41 | 42 | ||
| 42 | 43 | impl Report for Window { | |
| @@ -46,6 +47,9 @@ impl Report for Window { | |||
| 46 | 47 | } | |
| 47 | 48 | ||
| 48 | 49 | fn log(&self, line: &str) { | |
| 50 | + | if budctl_core::debug::enabled() { | |
| 51 | + | eprintln!("# {line}"); | |
| 52 | + | } | |
| 49 | 53 | log::line(line); | |
| 50 | 54 | } | |
| 51 | 55 | } | |