fix: Use connect instead of pairing, as pairing does nothing currently

This commit is contained in:
Fabio Lenherr / DashieTM 2023-12-03 22:37:01 +01:00
parent 736bcb8e4d
commit c5fb9611c9
3 changed files with 45 additions and 22 deletions

View file

@ -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"

View file

@ -44,6 +44,7 @@ fn setupCallbacks(
listeners: Arc<Listeners>,
bluetooth_box: Arc<BluetoothBox>,
) -> Arc<BluetoothBox> {
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<BluetoothAdapter>,), 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<BluetoothAdapter>,), Error> = proxy.method_call(
"org.Xetibo.ReSetBluetooth",
"SetBluetoothAdapterEnabled",
(path, enabled),
);
}

View file

@ -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 || {