From 58b7afbbfca77f1219cb9da5bf50f6ae652d3905 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Sun, 16 Jun 2024 12:37:44 +0100 Subject: [PATCH 1/2] Add an InfoBar that indicates why a selected device is not usable. --- src/ui.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/ui.rs b/src/ui.rs index 0cf5d2c8..2c492e96 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -24,11 +24,14 @@ use gtk::{ ApplicationWindow, Button, DropDown, + InfoBar, Label, ListItem, ColumnView, ColumnViewColumn, + MessageType, ProgressBar, + ResponseType, ScrolledWindow, Separator, SignalListItemFactory, @@ -41,7 +44,6 @@ use gtk::{ use gtk::{ MessageDialog, DialogFlags, - MessageType, ButtonsType, }; @@ -159,6 +161,16 @@ impl DeviceSelector { } } + fn device_unusable(&self) -> Option<&str> { + match self.current_device() { + None => None, + Some(device) => match &device.usability { + Usable(..) => None, + Unusable(string) => Some(string), + } + } + } + fn set_sensitive(&mut self, sensitive: bool) { if sensitive { self.dev_dropdown.set_sensitive(!self.devices.is_empty()); @@ -251,6 +263,41 @@ impl DeviceSelector { } } +struct DeviceWarning { + info_bar: InfoBar, + label: Label, +} + +impl DeviceWarning { + fn new() -> DeviceWarning { + let info_bar = InfoBar::new(); + info_bar.set_show_close_button(true); + info_bar.connect_response(|info_bar, response| { + if response == ResponseType::Close { + info_bar.set_revealed(false); + } + }); + let label = Label::new(None); + label.set_wrap(true); + info_bar.add_child(&label); + DeviceWarning { + info_bar, + label, + } + } + + fn update(&self, warning: Option<&str>) { + if let Some(reason) = warning { + self.info_bar.set_message_type(MessageType::Warning); + self.label.set_text(&format!( + "This device is not usable because: {reason}")); + self.info_bar.set_revealed(true); + } else { + self.info_bar.set_revealed(false); + } + } +} + pub struct UserInterface { pub capture: CaptureReader, selector: DeviceSelector, @@ -272,6 +319,7 @@ pub struct UserInterface { capture_button: Button, stop_button: Button, status_label: Label, + warning: DeviceWarning, #[cfg(any(test, feature="record-ui-test"))] pub recording: Rc>, } @@ -336,6 +384,9 @@ pub fn activate(application: &Application) -> Result<(), Error> { action_bar.pack_start(&stop_button); action_bar.pack_start(&selector.container); + let warning = DeviceWarning::new(); + warning.update(selector.device_unusable()); + #[cfg(not(test))] window.show(); WINDOW.with(|win_opt| win_opt.replace(Some(window.clone()))); @@ -388,6 +439,8 @@ pub fn activate(application: &Application) -> Result<(), Error> { vbox.append(&action_bar); vbox.append(>k::Separator::new(Orientation::Horizontal)); + vbox.append(&warning.info_bar); + vbox.append(>k::Separator::new(Orientation::Horizontal)); vbox.append(&paned); vbox.append(>k::Separator::new(Orientation::Horizontal)); vbox.append(&status_label); @@ -426,6 +479,7 @@ pub fn activate(application: &Application) -> Result<(), Error> { capture_button, stop_button, status_label, + warning, } ) }); @@ -842,6 +896,7 @@ fn detect_hardware() -> Result<(), Error> { with_ui(|ui| { ui.selector.scan()?; ui.capture_button.set_sensitive(ui.selector.device_available()); + ui.warning.update(ui.selector.device_unusable()); Ok(()) }) } @@ -849,6 +904,7 @@ fn detect_hardware() -> Result<(), Error> { fn device_selection_changed() -> Result<(), Error> { with_ui(|ui| { ui.capture_button.set_sensitive(ui.selector.device_available()); + ui.warning.update(ui.selector.device_unusable()); ui.selector.update_speeds(); Ok(()) }) From e9858538cc0f1546b411c8134bdfa789c5191533 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Sun, 16 Jun 2024 12:58:08 +0100 Subject: [PATCH 2/2] Report clearer messages for protocol mismatches. --- src/backend/cynthion.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/cynthion.rs b/src/backend/cynthion.rs index 785a333b..308a678a 100644 --- a/src/backend/cynthion.rs +++ b/src/backend/cynthion.rs @@ -1,3 +1,4 @@ +use std::cmp::Ordering; use std::collections::VecDeque; use std::thread::{spawn, sleep, JoinHandle}; use std::time::Duration; @@ -179,9 +180,13 @@ fn check_device(device_info: &DeviceInfo) // Check protocol version. let protocol = alt_setting.protocol(); - if protocol != PROTOCOL { - bail!("Wrong protocol version: {} supported, {} found", - PROTOCOL, protocol); + #[allow(clippy::absurd_extreme_comparisons)] + match PROTOCOL.cmp(&protocol) { + Ordering::Less => + bail!("Analyzer gateware is newer (v{}) than supported by this version of Packetry (v{}). Please update Packetry.", protocol, PROTOCOL), + Ordering::Greater => + bail!("Analyzer gateware is older (v{}) than supported by this version of Packetry (v{}). Please update gateware.", protocol, PROTOCOL), + Ordering::Equal => {} } // Try to claim the interface.