linux-rust: log device status in headless mode#641
Open
cristianrubioa wants to merge 1 commit into
Open
Conversation
In --no-tray mode the BluetoothUIMessage channel (connection, battery, noise control mode) was produced but never consumed, leaving headless users with no visibility into device state. Add a small console consumer that logs each field only when it changes. Also moves logger setup into an explicit env_logger::Builder instead of mutating RUST_LOG via an unsafe env::set_var call.
There was a problem hiding this comment.
Pull request overview
Adds a headless-mode (--no-tray) consumer for BluetoothUIMessage so device state changes (connection, battery, noise control mode) become visible via standard log output, and refactors logger initialization to avoid mutating RUST_LOG.
Changes:
- Introduce
linux-rust/src/headless.rsto log device connection/battery/noise-control changes only when they differ from the last observed values. - Wire the headless console consumer into the
--no-trayexecution path inmain.rs. - Replace
unsafe env::set_var("RUST_LOG", ...) + env_logger::init()with an explicitenv_logger::Builder-based initialization.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| linux-rust/src/main.rs | Adds headless module wiring and refactors logging initialization/default filter logic. |
| linux-rust/src/headless.rs | Implements the headless console consumer that logs state changes from BluetoothUIMessage. |
Comment on lines
+52
to
+54
| /// Default log filter: app modules at `app_level`, known-noisy external crates kept quiet | ||
| /// unless the user already set `RUST_LOG` themselves, in which case that takes precedence. | ||
| fn default_log_filter(debug: bool, le_debug: bool) -> String { |
Comment on lines
+62
to
+69
| fn init_logging(debug: bool, le_debug: bool) { | ||
| let mut builder = env_logger::Builder::new(); | ||
| match env::var("RUST_LOG") { | ||
| Ok(filter) => builder.parse_filters(&filter), | ||
| Err(_) => builder.parse_filters(&default_log_filter(debug, le_debug)), | ||
| }; | ||
| builder.format_timestamp_secs().init(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--no-tray(headless) mode, theBluetoothUIMessagechannel (connection, battery, noise control mode) was produced but never consumed — headless users had no visibility into device state.linux-rust/src/headless.rs: a small console consumer that logs each field (connection, battery per component, noise control mode) only when it changes since the last observation, reusing the existingAirPodsNoiseControlModedecoding already used by the GUI.main.rsinto an explicitenv_logger::Buildercall instead of mutatingRUST_LOGvia anunsafeenv::set_var, while still respecting a user-providedRUST_LOG.log-crate lines, consistent with the rest of the app.Test plan
cargo build/cargo checkpass cleanly, no new warnings--no-tray --debug: connect, battery (incl. disconnected case), and noise control mode changes each logged exactly once, decoded to human-readable names--no-tray) is unaffected — window/tray opens normally, noheadlessmodule output in that path