mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-08 14:42:02 +02:00
wip: fix bluetooth and wifi
This commit is contained in:
parent
a8aca57ea1
commit
d02da7d3f7
|
@ -175,14 +175,13 @@ fn bluetooth_enabled_switch_handler(
|
|||
glib::Propagation::Proceed
|
||||
}
|
||||
|
||||
pub fn populate_connected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
|
||||
pub fn populate_connected_bluetooth_devices(listeners: Arc<Listeners>,bluetooth_box: Arc<BluetoothBox>) {
|
||||
// TODO handle saved devices -> they also exist
|
||||
gio::spawn_blocking(move || {
|
||||
let ref_box = bluetooth_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 devices = get_bluetooth_devices(ref_box.clone());
|
||||
dbg!(&adapters);
|
||||
{
|
||||
let imp = bluetooth_box.imp();
|
||||
let list = imp.reset_model_list.write().unwrap();
|
||||
|
@ -199,6 +198,7 @@ pub fn populate_connected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
|
|||
*model_index += 1;
|
||||
}
|
||||
}
|
||||
start_bluetooth_listener(listeners, ref_box.clone());
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let new_adapter_ref = ref_box.clone();
|
||||
|
@ -230,30 +230,27 @@ 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 rssi = device.rssi.clone();
|
||||
let bluetooth_entry = BluetoothEntry::new(device, ref_box.clone());
|
||||
imp.available_devices
|
||||
.borrow_mut()
|
||||
.insert(path, bluetooth_entry.clone());
|
||||
if connected {
|
||||
imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
|
||||
imp.connected_devices
|
||||
.borrow_mut()
|
||||
.insert(path, bluetooth_entry.clone());
|
||||
} else {
|
||||
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);
|
||||
if rssi == -1 {
|
||||
imp.reset_bluetooth_saved_devices.add(&*bluetooth_entry);
|
||||
imp.saved_devices
|
||||
.borrow_mut()
|
||||
.insert(path, bluetooth_entry.clone());
|
||||
} else {
|
||||
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
|
||||
imp.available_devices
|
||||
.borrow_mut()
|
||||
.insert(path, bluetooth_entry.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -426,31 +423,13 @@ fn bluetooth_listener_loop(
|
|||
}
|
||||
}
|
||||
|
||||
fn get_connected_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, "GetConnectedBluetoothDevices", ());
|
||||
if res.is_err() {
|
||||
show_error::<BluetoothBox>(
|
||||
bluetooth_box.clone(),
|
||||
"Failed to get connected bluetooth devices",
|
||||
);
|
||||
return Vec::new();
|
||||
}
|
||||
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",
|
||||
);
|
||||
show_error::<BluetoothBox>(bluetooth_box.clone(), "Failed to get bluetooth devices");
|
||||
return Vec::new();
|
||||
}
|
||||
res.unwrap().0
|
||||
|
|
|
@ -24,6 +24,8 @@ pub struct BluetoothBox {
|
|||
#[template_child]
|
||||
pub reset_bluetooth_available_devices: TemplateChild<PreferencesGroup>,
|
||||
#[template_child]
|
||||
pub reset_bluetooth_saved_devices: TemplateChild<PreferencesGroup>,
|
||||
#[template_child]
|
||||
pub reset_bluetooth_refresh_button: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub reset_bluetooth_adapter: TemplateChild<ComboRow>,
|
||||
|
@ -41,6 +43,7 @@ pub struct BluetoothBox {
|
|||
pub error: TemplateChild<ReSetError>,
|
||||
pub available_devices: BluetoothMap,
|
||||
pub connected_devices: BluetoothMap,
|
||||
pub saved_devices: BluetoothMap,
|
||||
pub reset_bluetooth_adapters: Arc<RwLock<HashMap<String, (BluetoothAdapter, u32)>>>,
|
||||
pub reset_current_bluetooth_adapter: Arc<RefCell<BluetoothAdapter>>,
|
||||
pub reset_model_list: Arc<RwLock<StringList>>,
|
||||
|
|
|
@ -29,8 +29,8 @@ pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Posi
|
|||
scan_for_wifi(wifi_box.clone());
|
||||
let wifi_frame = wrap_in_flow_box_child(SettingBox::new(&*wifi_box));
|
||||
let bluetooth_box = BluetoothBox::new(listeners.clone());
|
||||
populate_connected_bluetooth_devices(bluetooth_box.clone());
|
||||
start_bluetooth_listener(listeners, bluetooth_box.clone());
|
||||
populate_connected_bluetooth_devices(listeners, bluetooth_box.clone());
|
||||
// start_bluetooth_listener(listeners, bluetooth_box.clone());
|
||||
let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&wifi_frame, -1);
|
||||
|
@ -59,8 +59,8 @@ pub const HANDLE_BLUETOOTH_CLICK: fn(Arc<Listeners>, FlowBox, Rc<RefCell<Positio
|
|||
return;
|
||||
}
|
||||
let bluetooth_box = BluetoothBox::new(listeners.clone());
|
||||
start_bluetooth_listener(listeners, bluetooth_box.clone());
|
||||
populate_connected_bluetooth_devices(bluetooth_box.clone());
|
||||
populate_connected_bluetooth_devices(listeners, bluetooth_box.clone());
|
||||
// start_bluetooth_listener(listeners, bluetooth_box.clone());
|
||||
let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&bluetooth_frame, -1);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.4"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.4"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.4"/>
|
||||
|
@ -87,6 +87,15 @@
|
|||
<property name="title">Available Devices</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup" id="reset_bluetooth_saved_devices">
|
||||
<property name="margin-bottom">5</property>
|
||||
<property name="margin-end">5</property>
|
||||
<property name="margin-start">5</property>
|
||||
<property name="margin-top">10</property>
|
||||
<property name="title">Saved Devices</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.0"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="libadwaita" version="1.4"/>
|
||||
<object class="AdwComboRow" id="reset_card_entry">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<template class="resetError" parent="GtkPopover">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.4"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<template class="resetListBoxRow" parent="GtkListBoxRow">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gio" version="2.0"/>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.4"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<template class="resetPopup" parent="GtkPopover">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="libadwaita" version="1.0"/>
|
||||
<template class="resetSavedWifiEntry" parent="AdwActionRow">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<template class="resetSettingBox" parent="GtkBox">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<object class="GtkShortcutsWindow" id="help_overlay">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<template class="resetSidebarEntry" parent="GtkListBoxRow">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.3"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.3"/>
|
||||
|
|
|
@ -152,6 +152,7 @@
|
|||
(10,212,"AdwActionRow","reset_bluetooth_main_tab",208,None,None,None,None,None,None),
|
||||
(10,213,"GtkImage",None,212,None,None,None,None,None,None),
|
||||
(10,214,"resetError","error",1,None,None,None,2,None,None),
|
||||
(10,215,"AdwPreferencesGroup","reset_bluetooth_saved_devices",121,None,None,None,3,None,None),
|
||||
(11,1,"AdwActionRow","resetBluetoothEntry",None,None,None,None,None,None,None),
|
||||
(12,11,"GtkBox","resetAudioInput",None,None,None,None,None,None,None),
|
||||
(12,12,"GtkLabel",None,11,None,None,None,None,None,None),
|
||||
|
@ -590,6 +591,11 @@
|
|||
(10,213,"GtkWidget","halign","end",None,None,None,None,None,None,None,None,None),
|
||||
(10,213,"GtkWidget","hexpand","True",None,None,None,None,None,None,None,None,None),
|
||||
(10,213,"GtkWidget","margin-end","5",None,None,None,None,None,None,None,None,None),
|
||||
(10,215,"AdwPreferencesGroup","title","Saved Devices",None,None,None,None,None,None,None,None,None),
|
||||
(10,215,"GtkWidget","margin-bottom","5",None,None,None,None,None,None,None,None,None),
|
||||
(10,215,"GtkWidget","margin-end","5",None,None,None,None,None,None,None,None,None),
|
||||
(10,215,"GtkWidget","margin-start","5",None,None,None,None,None,None,None,None,None),
|
||||
(10,215,"GtkWidget","margin-top","10",None,None,None,None,None,None,None,None,None),
|
||||
(11,1,"GtkWidget","margin-start","5",None,None,None,None,None,None,None,None,None),
|
||||
(11,32,"GtkListBoxRow","child",None,None,None,None,None,39,None,None,None,None),
|
||||
(11,32,"GtkWidget","margin-start","5",None,None,None,None,None,None,None,None,None),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.6"/>
|
||||
<requires lib="libadwaita" version="1.4"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.2"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="libadwaita" version="1.0"/>
|
||||
<template class="resetWifiEntry" parent="AdwActionRow">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.4"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.17.3 -->
|
||||
<!-- Created with Cambalache 0.90.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.12"/>
|
||||
<requires lib="libadwaita" version="1.2"/>
|
||||
|
|
Loading…
Reference in a new issue