Skip to content

Commit 706e3e1

Browse files
committed
Begin implementing. But we need mut ref...
1 parent 4138691 commit 706e3e1

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

src/app.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,16 @@ impl App {
392392
}
393393

394394
//Paired devices
395-
let rows: Vec<Row> = selected_controller
396-
.paired_devices
395+
let mut paired_devices_sorted = selected_controller.paired_devices.clone();
396+
paired_devices_sorted.sort_by(|a, b| {
397+
use std::cmp::Ordering;
398+
match (a.is_favorite, b.is_favorite) {
399+
(true, false) => Ordering::Less,
400+
(false, true) => Ordering::Greater,
401+
_ => Ordering::Equal,
402+
}
403+
});
404+
let rows: Vec<Row> = paired_devices_sorted
397405
.iter()
398406
.map(|d| {
399407
Row::new(vec![

src/bluetooth.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub struct Device {
3434
pub is_paired: bool,
3535
pub is_trusted: bool,
3636
pub is_connected: bool,
37+
pub is_favorite: bool,
3738
pub battery_percentage: Option<u8>,
3839
}
3940

@@ -43,6 +44,10 @@ impl Device {
4344
Ok(())
4445
}
4546

47+
pub fn toggle_favorite(&mut self) -> () {
48+
self.is_favorite = !self.is_favorite;
49+
}
50+
4651
// https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
4752
pub fn get_icon(name: &str) -> Option<String> {
4853
match name {

src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ pub struct PairedDevice {
4747

4848
#[serde(default = "default_set_new_name")]
4949
pub rename: char,
50+
51+
#[serde(default = "default_toggle_device_favorite")]
52+
pub toggle_favorite: char,
5053
}
5154

5255
impl Default for PairedDevice {
@@ -55,6 +58,7 @@ impl Default for PairedDevice {
5558
unpair: 'u',
5659
toggle_trust: 't',
5760
rename: 'e',
61+
toggle_favorite: 'f',
5862
}
5963
}
6064
}
@@ -87,6 +91,10 @@ fn default_toggle_device_trust() -> char {
8791
't'
8892
}
8993

94+
fn default_toggle_device_favorite() -> char {
95+
'f'
96+
}
97+
9098
impl Config {
9199
pub fn new() -> Self {
92100
let conf_path = dirs::config_dir()

src/handler.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,19 @@ pub async fn handle_key_events(
545545
app.focused_block = FocusedBlock::SetDeviceAliasBox;
546546
}
547547

548+
// Favorite / Unfavorite
549+
KeyCode::Char(c) if c == config.paired_device.toggle_favorite => {
550+
if let Some(selected_controller) =
551+
app.controller_state.selected()
552+
{
553+
let controller = &app.controllers[selected_controller];
554+
if let Some(index) = app.paired_devices_state.selected() {
555+
let device = &controller.paired_devices[index];
556+
device.toggle_favorite();
557+
}
558+
}
559+
}
560+
548561
_ => {}
549562
}
550563
}

0 commit comments

Comments
 (0)