mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-17 10:18:32 +02:00
fix: Wifi connect and disconnect
This commit is contained in:
parent
d02da7d3f7
commit
12d5784f88
|
@ -175,13 +175,15 @@ fn bluetooth_enabled_switch_handler(
|
||||||
glib::Propagation::Proceed
|
glib::Propagation::Proceed
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn populate_connected_bluetooth_devices(listeners: Arc<Listeners>,bluetooth_box: Arc<BluetoothBox>) {
|
pub fn populate_connected_bluetooth_devices(
|
||||||
|
listeners: Arc<Listeners>,
|
||||||
|
bluetooth_box: Arc<BluetoothBox>,
|
||||||
|
) {
|
||||||
// TODO handle saved devices -> they also exist
|
// TODO handle saved devices -> they also exist
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
let ref_box = bluetooth_box.clone();
|
let ref_box = bluetooth_box.clone();
|
||||||
let adapters = get_bluetooth_adapters(ref_box.clone());
|
let adapters = get_bluetooth_adapters(ref_box.clone());
|
||||||
let devices = get_bluetooth_devices(ref_box.clone());
|
let devices = get_bluetooth_devices(ref_box.clone());
|
||||||
dbg!(&adapters);
|
|
||||||
{
|
{
|
||||||
let imp = bluetooth_box.imp();
|
let imp = bluetooth_box.imp();
|
||||||
let list = imp.reset_model_list.write().unwrap();
|
let list = imp.reset_model_list.write().unwrap();
|
||||||
|
@ -232,25 +234,23 @@ pub fn populate_connected_bluetooth_devices(listeners: Arc<Listeners>,bluetooth_
|
||||||
for device in devices {
|
for device in devices {
|
||||||
let path = device.path.clone();
|
let path = device.path.clone();
|
||||||
let connected = device.connected;
|
let connected = device.connected;
|
||||||
let rssi = device.rssi.clone();
|
let rssi = device.rssi;
|
||||||
let bluetooth_entry = BluetoothEntry::new(device, ref_box.clone());
|
let bluetooth_entry = BluetoothEntry::new(device, ref_box.clone());
|
||||||
if connected {
|
if connected {
|
||||||
imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
|
imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
|
||||||
imp.connected_devices
|
imp.connected_devices
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert(path, bluetooth_entry.clone());
|
.insert(path, bluetooth_entry.clone());
|
||||||
|
} else if rssi == -1 {
|
||||||
|
imp.reset_bluetooth_saved_devices.add(&*bluetooth_entry);
|
||||||
|
imp.saved_devices
|
||||||
|
.borrow_mut()
|
||||||
|
.insert(path, bluetooth_entry.clone());
|
||||||
} else {
|
} else {
|
||||||
if rssi == -1 {
|
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
|
||||||
imp.reset_bluetooth_saved_devices.add(&*bluetooth_entry);
|
imp.available_devices
|
||||||
imp.saved_devices
|
.borrow_mut()
|
||||||
.borrow_mut()
|
.insert(path, bluetooth_entry.clone());
|
||||||
.insert(path, bluetooth_entry.clone());
|
|
||||||
} else {
|
|
||||||
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
|
|
||||||
imp.available_devices
|
|
||||||
.borrow_mut()
|
|
||||||
.insert(path, bluetooth_entry.clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,15 +15,22 @@ pub fn device_changed_handler(
|
||||||
glib::spawn_future(async move {
|
glib::spawn_future(async move {
|
||||||
glib::idle_add_once(move || {
|
glib::idle_add_once(move || {
|
||||||
let imp = bluetooth_box.imp();
|
let imp = bluetooth_box.imp();
|
||||||
|
let rssi = ir.bluetooth_device.rssi;
|
||||||
let mut map = imp.available_devices.borrow_mut();
|
let mut map = imp.available_devices.borrow_mut();
|
||||||
if let Some(list_entry) = map.get_mut(&ir.bluetooth_device.path) {
|
if let Some(list_entry) = map.get_mut(&ir.bluetooth_device.path) {
|
||||||
let mut existing_bluetooth_device = list_entry.imp().bluetooth_device.borrow_mut();
|
let mut existing_bluetooth_device = list_entry.imp().bluetooth_device.borrow_mut();
|
||||||
if existing_bluetooth_device.connected != ir.bluetooth_device.connected {
|
if existing_bluetooth_device.connected != ir.bluetooth_device.connected {
|
||||||
if ir.bluetooth_device.connected {
|
if ir.bluetooth_device.connected {
|
||||||
imp.reset_bluetooth_available_devices.remove(&**list_entry);
|
imp.reset_bluetooth_available_devices.remove(&**list_entry);
|
||||||
|
imp.reset_bluetooth_saved_devices.remove(&**list_entry);
|
||||||
imp.reset_bluetooth_connected_devices.add(&**list_entry);
|
imp.reset_bluetooth_connected_devices.add(&**list_entry);
|
||||||
|
} else if rssi == -1 {
|
||||||
|
imp.reset_bluetooth_connected_devices.remove(&**list_entry);
|
||||||
|
imp.reset_bluetooth_saved_devices.add(&**list_entry);
|
||||||
|
imp.reset_bluetooth_available_devices.remove(&**list_entry);
|
||||||
} else {
|
} else {
|
||||||
imp.reset_bluetooth_connected_devices.remove(&**list_entry);
|
imp.reset_bluetooth_connected_devices.remove(&**list_entry);
|
||||||
|
imp.reset_bluetooth_saved_devices.remove(&**list_entry);
|
||||||
imp.reset_bluetooth_available_devices.add(&**list_entry);
|
imp.reset_bluetooth_available_devices.add(&**list_entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +69,9 @@ pub fn device_removed_handler(
|
||||||
if list_entry.imp().bluetooth_device.borrow().connected {
|
if list_entry.imp().bluetooth_device.borrow().connected {
|
||||||
imp.reset_bluetooth_connected_devices.remove(&*list_entry);
|
imp.reset_bluetooth_connected_devices.remove(&*list_entry);
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: is there a better way for this?
|
||||||
imp.reset_bluetooth_available_devices.remove(&*list_entry);
|
imp.reset_bluetooth_available_devices.remove(&*list_entry);
|
||||||
|
imp.reset_bluetooth_saved_devices.remove(&*list_entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -76,6 +85,7 @@ pub fn device_added_handler(device_added_box: Arc<BluetoothBox>, ir: BluetoothDe
|
||||||
glib::idle_add_once(move || {
|
glib::idle_add_once(move || {
|
||||||
let imp = bluetooth_box.imp();
|
let imp = bluetooth_box.imp();
|
||||||
let path = ir.bluetooth_device.path.clone();
|
let path = ir.bluetooth_device.path.clone();
|
||||||
|
let rssi = ir.bluetooth_device.rssi;
|
||||||
let connected = ir.bluetooth_device.connected;
|
let connected = ir.bluetooth_device.connected;
|
||||||
let bluetooth_entry = BluetoothEntry::new(ir.bluetooth_device, bluetooth_box.clone());
|
let bluetooth_entry = BluetoothEntry::new(ir.bluetooth_device, bluetooth_box.clone());
|
||||||
imp.available_devices
|
imp.available_devices
|
||||||
|
@ -83,6 +93,8 @@ pub fn device_added_handler(device_added_box: Arc<BluetoothBox>, ir: BluetoothDe
|
||||||
.insert(path, bluetooth_entry.clone());
|
.insert(path, bluetooth_entry.clone());
|
||||||
if connected {
|
if connected {
|
||||||
imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
|
imp.reset_bluetooth_connected_devices.add(&*bluetooth_entry);
|
||||||
|
} else if rssi == -1 {
|
||||||
|
imp.reset_bluetooth_saved_devices.add(&*bluetooth_entry);
|
||||||
} else {
|
} else {
|
||||||
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
|
imp.reset_bluetooth_available_devices.add(&*bluetooth_entry);
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,6 @@ pub fn get_wifi_devices(wifi_box: Arc<WifiBox>) -> Vec<WifiDevice> {
|
||||||
let res: Result<(Vec<WifiDevice>,), Error> =
|
let res: Result<(Vec<WifiDevice>,), Error> =
|
||||||
proxy.method_call(WIRELESS, "GetAllWifiDevices", ());
|
proxy.method_call(WIRELESS, "GetAllWifiDevices", ());
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
dbg!(&res);
|
|
||||||
show_error::<WifiBox>(wifi_box.clone(), "Failed to get WiFi devices");
|
show_error::<WifiBox>(wifi_box.clone(), "Failed to get WiFi devices");
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue