fix: Use ssid over path for events

This commit is contained in:
Fabio Lenherr / DashieTM 2023-12-16 12:18:13 +01:00
parent 4a9f8bf90a
commit c860fcddee
7 changed files with 532 additions and 46 deletions

View file

@ -221,9 +221,18 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
return;
}
let device_added_box = bluetooth_box.clone();
let device_removed_box = bluetooth_box.clone();
let device_changed_box = bluetooth_box.clone();
let loop_box = bluetooth_box.clone();
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
let _: Result<(), Error> = proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
loop_box
.imp()
.reset_bluetooth_available_devices
.set_description(Some("Scanning..."));
let device_added =
BluetoothDeviceAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
.static_clone();
@ -233,10 +242,6 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
let device_changed =
BluetoothDeviceChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
.static_clone();
let device_added_box = bluetooth_box.clone();
let device_removed_box = bluetooth_box.clone();
let device_changed_box = bluetooth_box.clone();
let loop_box = bluetooth_box.clone();
let res = conn.add_match(device_added, move |ir: BluetoothDeviceAdded, _, _| {
let bluetooth_box = device_added_box.clone();
@ -338,6 +343,10 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
if !listeners.bluetooth_listener.load(Ordering::SeqCst) {
let _: Result<(), Error> =
proxy.method_call(BLUETOOTH, "StopBluetoothListener", ());
loop_box
.imp()
.reset_bluetooth_available_devices
.set_description(None);
break;
}
if listener_active && time.elapsed().unwrap() > Duration::from_millis(10000) {
@ -352,6 +361,10 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
});
});
let _: Result<(), Error> = proxy.method_call(BLUETOOTH, "StopBluetoothScan", ());
loop_box
.imp()
.reset_bluetooth_available_devices
.set_description(None);
}
if !listener_active && listeners.bluetooth_scan_requested.load(Ordering::SeqCst) {
listeners
@ -360,6 +373,10 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
listener_active = true;
let _: Result<(), Error> =
proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
loop_box
.imp()
.reset_bluetooth_available_devices
.set_description(Some("Scanning..."));
time = SystemTime::now();
}
thread::sleep(Duration::from_millis(100));

View file

@ -166,7 +166,8 @@ pub fn populate_sources(input_box: Arc<SourceBox>) {
for entry in 0..*index {
if model_list.string(entry) == Some(name.alias.clone().into()) {
input_box_imp.reset_source_dropdown.set_selected(entry);
}
return;
}
}
input_box_imp.reset_source_dropdown.connect_selected_notify(
clone!(@weak input_box_imp => move |dropdown| {
@ -260,6 +261,7 @@ pub fn refresh_default_source(new_source: Source, input_box: Arc<SourceBox>, ent
for entry in 0..*imp.reset_model_index.read().unwrap() {
if model_list.string(entry) == Some(new_source.alias.clone().into()) {
imp.reset_source_dropdown.set_selected(entry);
return;
}
}
}
@ -419,15 +421,16 @@ pub fn start_input_box_listener(conn: Connection, source_box: Arc<SourceBox>) ->
let mut index = input_box_imp.reset_model_index.write().unwrap();
let model_list = input_box_imp.reset_model_list.write().unwrap();
if model_list.string(*index - 1) == Some("Monitor of Dummy Output".into()) {
if alias == "Monitor of Dummy Output" {
return;
}
model_list.append(&alias);
model_list.remove(*index - 1);
map.insert(alias, (source_index, name));
input_box_imp.reset_source_dropdown.set_selected(0);
} else {
model_list.append(&alias);
map.insert(alias, (source_index, name));
map.insert(alias.clone(), (source_index, name));
if alias == "Monitor of Dummy Output" {
input_box_imp.reset_source_dropdown.set_selected(0);
}
*index += 1;
}
});
@ -464,11 +467,11 @@ pub fn start_input_box_listener(conn: Connection, source_box: Arc<SourceBox>) ->
if *index == 1 {
model_list.append("Monitor of Dummy Output");
map.insert(String::from("Monitor of Dummy Output"), (0, String::from("Monitor of Dummy Output")));
}
for entry in 0..*index {
if model_list.string(entry) == Some(alias.clone().into()) {
model_list.remove(entry);
return;
}
}
if *index > 1 {
@ -609,7 +612,7 @@ pub fn start_input_box_listener(conn: Connection, source_box: Arc<SourceBox>) ->
for entry in 0..*index {
if model_list.string(entry) == Some(alias.clone().into()) {
imp.reset_source_selection.set_selected(entry);
}
}
}
});
});

View file

@ -169,6 +169,7 @@ pub fn populate_sinks(output_box: Arc<SinkBox>) {
for entry in 0..*index {
if model_list.string(entry) == Some(name.alias.clone().into()) {
output_box_imp.reset_sink_dropdown.set_selected(entry);
return;
}
}
output_box_imp.reset_sink_dropdown.connect_selected_notify(
@ -264,6 +265,7 @@ pub fn refresh_default_sink(new_sink: Sink, output_box: Arc<SinkBox>, entry: boo
for entry in 0..*index {
if model_list.string(entry) == Some(new_sink.alias.clone().into()) {
imp.reset_sink_dropdown.set_selected(entry);
return;
}
}
}
@ -423,7 +425,7 @@ pub fn start_output_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Co
if model_list.string(*index - 1) == Some("Dummy Output".into()) {
model_list.append(&alias);
model_list.remove(*index - 1);
map.insert(alias.clone(), (sink_index, name));
map.insert(alias, (sink_index, name));
output_box_imp.reset_sink_dropdown.set_selected(0);
} else {
model_list.append(&alias);
@ -472,6 +474,7 @@ pub fn start_output_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Co
for entry in 0..*index {
if model_list.string(entry) == Some(alias.clone().into()) {
model_list.remove(entry);
return;
}
}
if *index > 1 {
@ -608,6 +611,7 @@ pub fn start_output_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Co
for entry in 0..*index {
if model_list.string(entry) == Some(alias.clone().into()) {
imp.reset_sink_selection.set_selected(entry);
return;
}
}
});

View file

@ -158,7 +158,7 @@ pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
let ssid = access_point.ssid.clone();
let path = access_point.dbus_path.clone();
let connected =
imp.reset_current_wifi_device.borrow().active_access_point == path;
imp.reset_current_wifi_device.borrow().active_access_point == ssid;
let entry = WifiEntry::new(connected, access_point, imp);
wifi_entries.insert(ssid, entry.clone());
wifi_entries_path.insert(path, entry.clone());
@ -294,7 +294,7 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
return;
}
let connected = imp.reset_current_wifi_device.borrow().active_access_point
== ir.access_point.dbus_path;
== ir.access_point.ssid;
let entry = WifiEntry::new(connected, ir.access_point, imp);
wifi_entries.insert(ssid, entry.clone());
wifi_entries_path.insert(path, entry.clone());
@ -366,7 +366,7 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
.borrow()
.set_sensitive(false);
}
if ir.access_point.dbus_path
if ir.access_point.ssid
== imp.reset_current_wifi_device.borrow().active_access_point
{
entry_imp
@ -403,7 +403,8 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
for entry in wifi_entries.iter_mut() {
let imp = entry.1.imp();
let mut connected = imp.connected.borrow_mut();
*connected = imp.access_point.borrow().dbus_path == current_device.path;
*connected =
imp.access_point.borrow().ssid == current_device.active_access_point;
if *connected {
imp.reset_wifi_connected.borrow().set_text("Connected");
} else {

View file

@ -2,7 +2,7 @@ use std::ops::Deref;
use std::sync::Arc;
use std::time::Duration;
use crate::components::utils::{WIRELESS, DBUS_PATH, BASE};
use crate::components::utils::{BASE, DBUS_PATH, WIRELESS};
use crate::components::wifi::utils::get_connection_settings;
use adw::glib;
use adw::glib::{Object, PropertySet};
@ -119,20 +119,18 @@ impl WifiEntry {
pub fn click_disconnect(entry: Arc<WifiEntry>) {
let entry_ref = entry.clone();
entry_ref
.imp()
.reset_wifi_connected
.borrow()
.set_text("Disconnecting...");
entry.set_activatable(false);
gio::spawn_blocking(move || {
let imp = entry_ref.imp();
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
BASE,
DBUS_PATH,
Duration::from_millis(10000),
);
let res: Result<(bool,), Error> = proxy.method_call(
WIRELESS,
"DisconnectFromCurrentAccessPoint",
(),
);
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(10000));
let res: Result<(bool,), Error> =
proxy.method_call(WIRELESS, "DisconnectFromCurrentAccessPoint", ());
if res.is_err() {
imp.connected.replace(false);
return;
@ -151,22 +149,19 @@ pub fn click_stored_network(entry: Arc<WifiEntry>) {
let entry_imp = entry.imp();
let access_point = entry_imp.access_point.borrow().clone();
let entry_ref = entry.clone();
entry.set_activatable(false);
entry.set_sensitive(false);
entry_imp
.reset_wifi_connected
.borrow()
.set_text("Connecting...");
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
BASE,
DBUS_PATH,
Duration::from_millis(10000),
);
let res: Result<(bool,), Error> = proxy.method_call(
WIRELESS,
"ConnectToKnownAccessPoint",
(access_point,),
);
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(10000));
let res: Result<(bool,), Error> =
proxy.method_call(WIRELESS, "ConnectToKnownAccessPoint", (access_point,));
glib::spawn_future(async move {
glib::idle_add_once(move || {
entry.set_activatable(true);
entry.set_sensitive(true);
let imp = entry_ref.imp();
if res.is_err() {
imp.connected.replace(false);
@ -194,14 +189,11 @@ pub fn click_new_network(entry: Arc<WifiEntry>) {
popup.reset_popup_label.set_visible(true);
popup.reset_popup_entry.set_sensitive(false);
popup.reset_popup_button.set_sensitive(false);
entry.set_sensitive(false);
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
BASE,
DBUS_PATH,
Duration::from_millis(10000),
);
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(10000));
let res: Result<(bool,), Error> = proxy.method_call(
WIRELESS,
"ConnectToNewAccessPoint",
@ -209,6 +201,7 @@ pub fn click_new_network(entry: Arc<WifiEntry>) {
);
glib::spawn_future(async move {
glib::idle_add_once(move || {
entry.set_sensitive(false);
if res.is_err() {
let imp = entry_ref.imp();
imp.reset_wifi_popup