Skip to content

Commit fdf8812

Browse files
Merge pull request #382 from swetar-mecha/pre-r/settings-drawer
Fix(settings drawer): Wifi and Bluetooth status; Add swipe to open settings drawer
2 parents df7ebdd + a55dfbe commit fdf8812

File tree

10 files changed

+252
-28
lines changed

10 files changed

+252
-28
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ rust-embed = "8.8.0"
4646
networkmanager = { path = "dbus/freedesktop/networkmanager" }
4747
bluez = { path = "dbus/freedesktop/bluez" }
4848
upower = { path = "dbus/freedesktop/upower" }
49+
pulseaudio = { path = "dbus/freedesktop/pulseaudio" }

shell/crates/running_apps/src/ui/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,4 +815,4 @@ impl RunningApps {
815815
btn
816816
}))
817817
}
818-
}
818+
}

shell/crates/settings_drawer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ keywords.workspace = true
1313
[dependencies]
1414
networkmanager = { workspace = true }
1515
bluez = { workspace = true }
16+
pulseaudio = { workspace = true }
1617
commons = { path = "../commons" }
1718
gpui = { workspace = true }
1819
rust-embed = { workspace = true }
Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
use networkmanager::interfaces::wireless::WirelessNetworkInfo;
2+
use pulseaudio::service::DeviceInfo;
23

34
#[derive(Debug)]
45
pub enum AppEvents {
5-
WirelessStatusChanged { enabled: bool },
6-
WirelessStrength { strength: u8 },
7-
ConnectedNetwork { network: Option<WirelessNetworkInfo> },
8-
BluetoothEnabled { enabled: bool },
9-
BluetoothDevices { count: u8 },
10-
6+
WirelessStatusChanged {
7+
enabled: bool,
8+
},
9+
WirelessStrength {
10+
strength: u8,
11+
},
12+
ConnectedNetwork {
13+
network: Option<WirelessNetworkInfo>,
14+
},
15+
BluetoothEnabled {
16+
enabled: bool,
17+
},
18+
BluetoothDevices {
19+
count: u8,
20+
},
21+
OutputSoundDevice {
22+
device_info: DeviceInfo,
23+
},
1124
}
1225

1326
#[derive(Debug)]
@@ -18,4 +31,4 @@ pub enum NmEvents {
1831
#[derive(Debug)]
1932
pub enum BtEvents {
2033
BluetoothToggle { enabled: bool },
21-
}
34+
}

shell/crates/settings_drawer/src/main.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use gpui::*;
55
use settings_drawer::prelude::*;
66
use settings_drawer::services::*;
77

8-
98
fn main() {
109
let application = gpui::Application::new().with_assets(Assets {});
1110
application.run(|cx| {
@@ -30,21 +29,25 @@ fn main() {
3029
.spawn(sync_network_strength(app_channel_tx.clone()))
3130
.detach();
3231
executor
33-
.spawn(sync_connected_network(app_channel_tx.clone()))
32+
.spawn(stream_network_device_events(app_channel_tx.clone()))
3433
.detach();
35-
executor
36-
.spawn(handle_wireless_toggle(nm_rx))
34+
35+
executor
36+
.spawn(sync_connected_network(app_channel_tx.clone()))
3737
.detach();
38+
executor.spawn(handle_wireless_toggle(nm_rx)).detach();
3839

3940
executor
4041
.spawn(sync_bluetooth_status(app_channel_tx.clone()))
4142
.detach();
43+
executor.spawn(stream_bluetooth_device_status(app_channel_tx.clone())).detach();
4244
executor
4345
.spawn(sync_bluetooth_connected_status(app_channel_tx.clone()))
4446
.detach();
45-
executor
46-
.spawn(handle_bluetooth_toggle(bt_rx))
47-
.detach();
47+
// executor
48+
// .spawn(get_sound_device(app_channel_tx.clone()))
49+
// .detach();
50+
executor.spawn(handle_bluetooth_toggle(bt_rx)).detach();
4851

4952
cx.new(|cx| {
5053
cx.spawn(async move |app, cx| {
@@ -80,6 +83,12 @@ fn main() {
8083
cx.notify();
8184
});
8285
}
86+
AppEvents::OutputSoundDevice { device_info } => {
87+
let _ = app.update(cx, |this: &mut SettingsDrawer, cx| {
88+
this.sound_device = Some(device_info);
89+
cx.notify();
90+
});
91+
}
8392
}
8493
}
8594
})

shell/crates/settings_drawer/src/services/bluetooth_sync.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ pub async fn sync_bluetooth_status(mut tx: mpsc::Sender<AppEvents>) {
1818
}
1919
}
2020

21+
pub async fn stream_bluetooth_device_status(tx: mpsc::Sender<AppEvents>) {
22+
let bluetooth_manager = match BluetoothService::new().await {
23+
Ok(bluetooth_manager) => bluetooth_manager,
24+
Err(e) => {
25+
eprintln!("Failed to create BluetoothService: {}", e);
26+
return;
27+
}
28+
};
29+
30+
let status_receiver = bluetooth_manager.stream_bluetooth_device_status().await;
31+
32+
while let Ok(_) = status_receiver.recv() {
33+
sync_bluetooth_connected_status(tx.clone()).await;
34+
}
35+
}
36+
2137
pub async fn sync_bluetooth_connected_status(mut tx: mpsc::Sender<AppEvents>) {
2238
let bluetooth_manager = match BluetoothService::new().await {
2339
Ok(bluetooth_manager) => bluetooth_manager,
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
pub mod bluetooth_sync;
22
pub mod network_sync;
3+
pub mod sound;
34

45
pub use bluetooth_sync::{
5-
handle_bluetooth_toggle, sync_bluetooth_connected_status, sync_bluetooth_status,
6+
handle_bluetooth_toggle, stream_bluetooth_device_status, sync_bluetooth_connected_status,
7+
sync_bluetooth_status,
68
};
79
pub use network_sync::{
8-
handle_wireless_toggle, sync_connected_network, sync_network_status, sync_network_strength,
10+
handle_wireless_toggle, stream_network_device_events, sync_connected_network, sync_network_status,
11+
sync_network_strength,
912
};

shell/crates/settings_drawer/src/services/network_sync.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::events::{AppEvents, NmEvents};
22
use futures::{SinkExt, StreamExt, channel::mpsc, select};
3-
use networkmanager::service::NetworkManagerService;
3+
use networkmanager::{interfaces::wireless::NMState, service::NetworkManagerService};
44

55
pub async fn sync_network_status(mut tx: mpsc::Sender<AppEvents>) {
66
let network_manager = match NetworkManagerService::new().await {
@@ -20,6 +20,25 @@ pub async fn sync_network_status(mut tx: mpsc::Sender<AppEvents>) {
2020
}
2121
}
2222

23+
pub async fn stream_network_device_events(tx: mpsc::Sender<AppEvents>) {
24+
let network_manager = match NetworkManagerService::new().await {
25+
Ok(nm) => nm,
26+
Err(e) => {
27+
eprintln!("Failed to create NetworkManagerService: {}", e);
28+
return;
29+
}
30+
};
31+
let wireless_status_receiver = network_manager.stream_device_events().await;
32+
while let Ok(nm_state) = wireless_status_receiver.recv() {
33+
match nm_state {
34+
NMState::ConnectedGlobal => {
35+
let _ = sync_connected_network(tx.clone()).await;
36+
}
37+
_ => {}
38+
}
39+
}
40+
}
41+
2342
pub async fn sync_network_strength(mut tx: mpsc::Sender<AppEvents>) {
2443
let network_manager = match NetworkManagerService::new().await {
2544
Ok(nm) => nm,
@@ -62,7 +81,7 @@ pub async fn sync_connected_network(mut tx: mpsc::Sender<AppEvents>) {
6281
}
6382

6483
pub async fn handle_wireless_toggle(mut nm_rx: mpsc::Receiver<NmEvents>) {
65-
let network_manager = match NetworkManagerService::new().await {
84+
let network_manager = match NetworkManagerService::new().await {
6685
Ok(nm) => nm,
6786
Err(e) => {
6887
eprintln!("Failed to create NetworkManagerService: {}", e);

0 commit comments

Comments
 (0)