From c5fb9611c9716741cd5901b10917409294fad8eb Mon Sep 17 00:00:00 2001 From: Fabio Lenherr / DashieTM Date: Sun, 3 Dec 2023 22:37:01 +0100 Subject: [PATCH] fix: Use connect instead of pairing, as pairing does nothing currently --- Cargo.toml | 2 +- src/components/bluetooth/bluetoothBox.rs | 26 +++++++++++++-- src/components/bluetooth/bluetoothEntry.rs | 39 +++++++++++----------- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9ea2d73..c42f10d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" description = "A wip universal Linux settings application." [dependencies] -reset_daemon = "0.3.6" +reset_daemon = "0.3.7" ReSet-Lib = "0.6.1" adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] } dbus = "0.9.7" diff --git a/src/components/bluetooth/bluetoothBox.rs b/src/components/bluetooth/bluetoothBox.rs index 503134b..c10aa6d 100644 --- a/src/components/bluetooth/bluetoothBox.rs +++ b/src/components/bluetooth/bluetoothBox.rs @@ -44,6 +44,7 @@ fn setupCallbacks( listeners: Arc, bluetooth_box: Arc, ) -> Arc { + let bluetooth_box_ref = bluetooth_box.clone(); let imp = bluetooth_box.imp(); // let bluetooth_box_ref = bluetooth_box.clone(); imp.resetVisibility.set_activatable(true); @@ -55,11 +56,18 @@ fn setupCallbacks( .set_action_name(Some("navigation.pop")); // TODO add a manual search button here imp.resetBluetoothSwitch.connect_state_set(move |_, state| { - // TODO restart bluetooth search here. if !state { + let imp = bluetooth_box_ref.imp(); + imp.resetBluetoothConnectedDevices.remove_all(); listeners.bluetooth_listener.store(false, Ordering::SeqCst); + set_adapter_enabled( + imp.resetCurrentBluetoothAdapter.borrow().path.clone(), + false, + ); } else { - listeners.bluetooth_listener.store(true, Ordering::SeqCst); + let imp = bluetooth_box_ref.imp(); + set_adapter_enabled(imp.resetCurrentBluetoothAdapter.borrow().path.clone(), true); + start_bluetooth_listener(listeners.clone(), bluetooth_box_ref.clone()); } glib::Propagation::Proceed }); @@ -320,3 +328,17 @@ fn set_bluetooth_adapter(path: Path<'static>) { let _: Result<(Vec,), Error> = proxy.method_call("org.Xetibo.ReSetBluetooth", "SetBluetoothAdapter", (path,)); } + +fn set_adapter_enabled(path: Path<'static>, enabled: bool) { + let conn = Connection::new_session().unwrap(); + let proxy = conn.with_proxy( + "org.Xetibo.ReSetDaemon", + "/org/Xetibo/ReSetDaemon", + Duration::from_millis(1000), + ); + let _: Result<(Vec,), Error> = proxy.method_call( + "org.Xetibo.ReSetBluetooth", + "SetBluetoothAdapterEnabled", + (path, enabled), + ); +} diff --git a/src/components/bluetooth/bluetoothEntry.rs b/src/components/bluetooth/bluetoothEntry.rs index 0b27254..1a9040a 100644 --- a/src/components/bluetooth/bluetoothEntry.rs +++ b/src/components/bluetooth/bluetoothEntry.rs @@ -49,15 +49,16 @@ impl BluetoothEntry { }); let gesture = GestureClick::new(); let connected = device.connected; - let paired = device.paired; + // let paired = device.paired; + // paired is not what we think + // TODO implement paired let path = device.path.clone(); gesture.connect_released(move |_, _, _, _| { + connect_to_device(path.clone()); if connected { disconnect_from_device(path.clone()); - } else if paired { - connect_to_device(path.clone()); } else { - pair_with_device(path.clone()); + connect_to_device(path.clone()); } }); entry.add_controller(gesture); @@ -81,21 +82,21 @@ fn connect_to_device(path: Path<'static>) { }); } -fn pair_with_device(path: Path<'static>) { - gio::spawn_blocking(move || { - let conn = Connection::new_session().unwrap(); - let proxy = conn.with_proxy( - "org.Xetibo.ReSetDaemon", - "/org/Xetibo/ReSetDaemon", - Duration::from_millis(1000), - ); - let _: Result<(bool,), Error> = proxy.method_call( - "org.Xetibo.ReSetBluetooth", - "PairWithBluetoothDevice", - (path,), - ); - }); -} +// fn pair_with_device(path: Path<'static>) { +// gio::spawn_blocking(move || { +// let conn = Connection::new_session().unwrap(); +// let proxy = conn.with_proxy( +// "org.Xetibo.ReSetDaemon", +// "/org/Xetibo/ReSetDaemon", +// Duration::from_millis(1000), +// ); +// let _: Result<(bool,), Error> = proxy.method_call( +// "org.Xetibo.ReSetBluetooth", +// "PairWithBluetoothDevice", +// (path,), +// ); +// }); +// } fn disconnect_from_device(path: Path<'static>) { gio::spawn_blocking(move || {