Skip to content

Commit d9a21d5

Browse files
committed
fix the case where the adapter model or vendor is absent
1 parent bd62b25 commit d9a21d5

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/device.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ pub struct Device {
2525
pub struct Adapter {
2626
pub a: iwdAdapter,
2727
pub name: String,
28-
pub model: String,
29-
pub vendor: String,
28+
pub model: Option<String>,
29+
pub vendor: Option<String>,
3030
pub supported_modes: Vec<String>,
3131
}
3232

3333
impl Adapter {
3434
pub async fn new(a: iwdAdapter) -> Result<Self> {
3535
let name = a.name().await?;
36-
let model = a.model().await?;
37-
let vendor = a.vendor().await?;
36+
let model = a.model().await.ok();
37+
let vendor = a.vendor().await.ok();
3838
let supported_modes = a.supported_modes().await?;
3939
Ok(Self {
4040
a,
@@ -99,7 +99,7 @@ impl Device {
9999
)
100100
.split(popup_layout[1])[1];
101101

102-
let rows = vec![
102+
let mut rows = vec![
103103
Row::new(vec![
104104
Cell::from("name").style(Style::default().bold().yellow()),
105105
Cell::from(self.adapter.name.clone()),
@@ -108,20 +108,26 @@ impl Device {
108108
Cell::from("address").style(Style::default().bold().yellow()),
109109
Cell::from(self.address.clone()),
110110
]),
111-
Row::new(vec![
112-
Cell::from("model").style(Style::default().bold().yellow()),
113-
Cell::from(self.adapter.model.clone()),
114-
]),
115-
Row::new(vec![
116-
Cell::from("vendor").style(Style::default().bold().yellow()),
117-
Cell::from(self.adapter.vendor.clone()),
118-
]),
119111
Row::new(vec![
120112
Cell::from("Supported modes").style(Style::default().bold().yellow()),
121113
Cell::from(self.adapter.supported_modes.clone().join(" ")),
122114
]),
123115
];
124116

117+
if let Some(model) = &self.adapter.model {
118+
rows.push(Row::new(vec![
119+
Cell::from("model").style(Style::default().bold().yellow()),
120+
Cell::from(model.clone()),
121+
]))
122+
}
123+
124+
if let Some(vendor) = &self.adapter.vendor {
125+
rows.push(Row::new(vec![
126+
Cell::from("vendor").style(Style::default().bold().yellow()),
127+
Cell::from(vendor.clone()),
128+
]))
129+
}
130+
125131
let widths = [Constraint::Length(20), Constraint::Fill(1)];
126132

127133
let device_infos_table = Table::new(rows, widths)

0 commit comments

Comments
 (0)