feat: Add ability to show bluetooth devices immediately

This commit is contained in:
dashie 2024-04-04 10:54:20 +02:00
parent 5f0781ee18
commit a8aca57ea1
7 changed files with 85 additions and 70 deletions

View file

@ -171,8 +171,8 @@ pub fn populate_audio_objects<
default_audio_object_function: &'static DBusFunction,
set_default_audio_object_function: &'static DBusFunction,
get_audio_streams_function: &'static DBusFunction,
set_audio_object_mute_function: &'static DBusFunction,
set_audio_object_volume_function: &'static DBusFunction,
set_audio_object_mute_function: &'static DBusFunction,
) {
gio::spawn_blocking(move || {
let sources = audio_dbus_call::<AudioBox, (Vec<AudioObject>,), ()>(

View file

@ -20,13 +20,9 @@ use crate::components::base::error_impl::ReSetErrorImpl;
use super::input_stream_entry::InputStreamEntry;
use super::sink_box_impl;
use super::sink_const::GETDEFAULT;
use super::sink_const::GETDEFAULTNAME;
use super::sink_const::GETOBJECTS;
use super::sink_const::GETSTREAMS;
use super::sink_const::SETDEFAULT;
use super::sink_const::SETMUTE;
use super::sink_const::SETVOLUME;
use super::sink_const::{
GETDEFAULT, GETDEFAULTNAME, GETOBJECTS, GETSTREAMS, SETDEFAULT, SETMUTE, SETVOLUME,
};
use super::sink_entry::SinkEntry;
glib::wrapper! {

View file

@ -179,7 +179,9 @@ pub fn populate_connected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
// TODO handle saved devices -> they also exist
gio::spawn_blocking(move || {
let ref_box = bluetooth_box.clone();
let devices = get_connected_devices(ref_box.clone());
let devices = get_bluetooth_devices(ref_box.clone());
dbg!(&devices);
let connected_devices = get_connected_devices(ref_box.clone());
let adapters = get_bluetooth_adapters(ref_box.clone());
{
let imp = bluetooth_box.imp();
@ -228,6 +230,7 @@ pub fn populate_connected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
});
for device in devices {
dbg!(&device);
let path = device.path.clone();
let connected = device.connected;
let bluetooth_entry = BluetoothEntry::new(device, ref_box.clone());
@ -240,6 +243,19 @@ pub fn populate_connected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
}
}
for device in connected_devices {
let path = device.path.clone();
let connected = device.connected;
let bluetooth_entry = BluetoothEntry::new(device, ref_box.clone());
imp.connected_devices
.borrow_mut()
.insert(path, bluetooth_entry.clone());
if connected {
imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
} else {
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
}
}
});
});
});
@ -425,6 +441,21 @@ fn get_connected_devices(bluetooth_box: Arc<BluetoothBox>) -> Vec<BluetoothDevic
res.unwrap().0
}
fn get_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) -> Vec<BluetoothDevice> {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
let res: Result<(Vec<BluetoothDevice>,), Error> =
proxy.method_call(BLUETOOTH, "GetBluetoothDevices", ());
if res.is_err() {
show_error::<BluetoothBox>(
bluetooth_box.clone(),
"Failed to get bluetooth devices",
);
return Vec::new();
}
res.unwrap().0
}
fn get_bluetooth_adapters(bluetooth_box: Arc<BluetoothBox>) -> Vec<BluetoothAdapter> {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));

View file

@ -7,7 +7,7 @@ use gtk::prelude::{GObjectPropertyExpressionExt, ListBoxRowExt, ListItemExt, Wid
use gtk::{Align, SignalListItemFactory, StringObject};
pub const DBUS_PATH: &str = "/org/Xetibo/ReSet/Daemon";
pub const WIRELESS: &str = "org.Xetibo.ReSet.Wireless";
pub const WIRELESS: &str = "org.Xetibo.ReSet.Network";
pub const BLUETOOTH: &str = "org.Xetibo.ReSet.Bluetooth";
pub const AUDIO: &str = "org.Xetibo.ReSet.Audio";
pub const BASE: &str = "org.Xetibo.ReSet.Daemon";

View file

@ -116,7 +116,7 @@ pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
if devices.is_empty() {
return;
}
let access_points = get_access_points(wifibox_ref.clone());
let access_points = get_access_points(wifi_box.clone());
{
let imp = wifibox_ref.imp();
let list = imp.reset_model_list.write().unwrap();
@ -251,6 +251,7 @@ pub fn get_wifi_devices(wifi_box: Arc<WifiBox>) -> Vec<WifiDevice> {
let res: Result<(Vec<WifiDevice>,), Error> =
proxy.method_call(WIRELESS, "GetAllWifiDevices", ());
if res.is_err() {
dbg!(&res);
show_error::<WifiBox>(wifi_box.clone(), "Failed to get WiFi devices");
return Vec::new();
}