Skip to content

Commit e972b64

Browse files
committed
Begin implementing. But we need mut ref...
1 parent cdeb48d commit e972b64

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
@@ -408,8 +408,16 @@ impl App {
408408
}
409409

410410
//Paired devices
411-
let rows: Vec<Row> = selected_controller
412-
.paired_devices
411+
let mut paired_devices_sorted = selected_controller.paired_devices.clone();
412+
paired_devices_sorted.sort_by(|a, b| {
413+
use std::cmp::Ordering;
414+
match (a.is_favorite, b.is_favorite) {
415+
(true, false) => Ordering::Less,
416+
(false, true) => Ordering::Greater,
417+
_ => Ordering::Equal,
418+
}
419+
});
420+
let rows: Vec<Row> = paired_devices_sorted
413421
.iter()
414422
.map(|d| {
415423
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
@@ -53,6 +53,9 @@ pub struct PairedDevice {
5353

5454
#[serde(default = "default_set_new_name")]
5555
pub rename: char,
56+
57+
#[serde(default = "default_toggle_device_favorite")]
58+
pub toggle_favorite: char,
5659
}
5760

5861
impl Default for PairedDevice {
@@ -62,6 +65,7 @@ impl Default for PairedDevice {
6265
toggle_connect: ' ',
6366
toggle_trust: 't',
6467
rename: 'e',
68+
toggle_favorite: 'f',
6569
}
6670
}
6771
}
@@ -114,6 +118,10 @@ fn default_pair_new_device() -> char {
114118
'p'
115119
}
116120

121+
fn default_toggle_device_favorite() -> char {
122+
'f'
123+
}
124+
117125
impl Config {
118126
pub fn new() -> Self {
119127
let conf_path = dirs::config_dir()

src/handler.rs

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

516+
// Favorite / Unfavorite
517+
KeyCode::Char(c) if c == config.paired_device.toggle_favorite => {
518+
if let Some(selected_controller) =
519+
app.controller_state.selected()
520+
{
521+
let controller = &app.controllers[selected_controller];
522+
if let Some(index) = app.paired_devices_state.selected() {
523+
let device = &controller.paired_devices[index];
524+
device.toggle_favorite();
525+
}
526+
}
527+
}
528+
516529
_ => {}
517530
}
518531
}

0 commit comments

Comments
 (0)