Skip to content

Commit b3ec3a3

Browse files
committed
add default icon for the devices
1 parent c001b3f commit b3ec3a3

2 files changed

Lines changed: 26 additions & 39 deletions

File tree

β€Žsrc/app.rsβ€Ž

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,7 @@ impl App {
416416
.iter()
417417
.map(|d| {
418418
Row::new(vec![
419-
{
420-
if let Some(icon) = &d.icon {
421-
format!("{} {}", icon, &d.alias)
422-
} else {
423-
d.alias.to_owned()
424-
}
425-
},
419+
format!("{} {}", &d.icon, &d.alias),
426420
d.is_trusted.to_string(),
427421
d.is_connected.to_string(),
428422
{
@@ -586,43 +580,36 @@ impl App {
586580

587581
//New devices
588582

589-
let mut max_name_width = 20;
590583
if render_new_devices {
591584
let rows: Vec<Row> = selected_controller
592585
.new_devices
593586
.iter()
594587
.map(|d| {
595-
Row::new(vec![d.addr.to_string(), {
596-
if let Some(icon) = &d.icon {
597-
format!("{} {}", icon, &d.alias)
598-
} else {
599-
if d.alias.len() > max_name_width {
600-
max_name_width = d.alias.len();
601-
}
602-
d.alias.to_owned()
603-
}
604-
}])
588+
Row::new(vec![
589+
d.addr.to_string(),
590+
format!("{} {}", &d.icon, &d.alias),
591+
])
605592
})
606593
.collect();
607594
let rows_len = rows.len();
608595

609-
let widths = [
610-
Constraint::Length(20),
611-
Constraint::Length(max_name_width.try_into().unwrap()),
612-
];
596+
let widths = [Constraint::Length(20), Constraint::Length(20)];
613597

614598
let new_devices_table = Table::new(rows, widths)
615599
.header({
616600
if self.focused_block == FocusedBlock::NewDevices {
617601
Row::new(vec![
618-
Cell::from("Address").style(Style::default().fg(Color::Yellow)),
619-
Cell::from("Name").style(Style::default().fg(Color::Yellow)),
602+
Cell::from(Line::from("Address").fg(Color::Yellow).centered()),
603+
Cell::from(Line::from("Name").fg(Color::Yellow).centered()),
620604
])
621605
.style(Style::new().bold())
622606
.bottom_margin(1)
623607
} else {
624-
Row::new(vec![Cell::from("Address"), Cell::from("Name")])
625-
.bottom_margin(1)
608+
Row::new(vec![
609+
Cell::from(Line::from("Address").centered()),
610+
Cell::from(Line::from("Name").centered()),
611+
])
612+
.bottom_margin(1)
626613
}
627614
})
628615
.block(

β€Žsrc/bluetooth.rsβ€Ž

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct Controller {
2323
pub struct Device {
2424
device: BTDevice,
2525
pub addr: Address,
26-
pub icon: Option<String>,
26+
pub icon: String,
2727
pub alias: String,
2828
pub is_paired: bool,
2929
pub is_trusted: bool,
@@ -38,19 +38,19 @@ impl Device {
3838
}
3939

4040
// https://specifications.freedesktop.org/icon-naming/latest/
41-
pub fn get_icon(name: &str) -> Option<String> {
41+
pub fn get_icon(name: &str) -> String {
4242
match name {
43-
"audio-card" => Some(String::from("󰓃")),
44-
"audio-input-microphone" => Some(String::from("ο„°")),
45-
"audio-headphones" | "audio-headset" => Some(String::from("σ°‹‹")),
46-
"battery" => Some(String::from("σ°‚€")),
47-
"camera-photo" => Some(String::from("σ°»›")),
48-
"computer" => Some(String::from("")),
49-
"input-keyboard" => Some(String::from("󰌌")),
50-
"input-mouse" => Some(String::from("󰍽")),
51-
"input-gaming" => Some(String::from("󰊴")),
52-
"phone" => Some(String::from("󰏲")),
53-
_ => Some(String::from(" ")),
43+
"audio-card" => String::from("󰓃 "),
44+
"audio-input-microphone" => String::from("ο„° "),
45+
"audio-headphones" | "audio-headset" => String::from("σ°‹‹ "),
46+
"battery" => String::from("σ°‚€ "),
47+
"camera-photo" => String::from("σ°»› "),
48+
"computer" => String::from(" "),
49+
"input-keyboard" => String::from("󰌌 "),
50+
"input-mouse" => String::from("󰍽 "),
51+
"input-gaming" => String::from("󰊴 "),
52+
"phone" => String::from("󰏲 "),
53+
_ => String::from("σ°Ύ° "),
5454
}
5555
}
5656
}

0 commit comments

Comments
Β (0)