chore: Use namespace with flatpak compatibility

This commit is contained in:
Fabio Lenherr / DashieTM 2023-12-12 22:35:16 +01:00
parent 770bdda317
commit 3ed909a5e4
21 changed files with 296 additions and 270 deletions

View file

@ -123,6 +123,11 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
let list = imp.reset_model_list.write().unwrap();
let mut model_index = imp.reset_model_index.write().unwrap();
let mut map = imp.reset_bluetooth_adapters.write().unwrap();
{
if imp.reset_bluetooth_adapters.read().unwrap().is_empty() {
return;
}
}
imp.reset_current_bluetooth_adapter
.replace(adapters.last().unwrap().clone());
for (index, adapter) in adapters.into_iter().enumerate() {
@ -204,25 +209,25 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.Xetibo.ReSetDaemon",
"/org/Xetibo/ReSetDaemon",
"org.Xetibo.ReSet.Daemon",
"/org/Xetibo/ReSet/Dameon",
Duration::from_millis(1000),
);
let _: Result<(), Error> =
proxy.method_call("org.Xetibo.ReSetBluetooth", "StartBluetoothListener", ());
proxy.method_call("org.Xetibo.ReSet.Bluetooth", "StartBluetoothListener", ());
let device_added = BluetoothDeviceAdded::match_rule(
Some(&"org.Xetibo.ReSetDaemon".into()),
Some(&Path::from("/org/Xetibo/ReSetDaemon")),
Some(&"org.Xetibo.ReSet.Daemon".into()),
Some(&Path::from("/org/Xetibo/ReSet/Dameon")),
)
.static_clone();
let device_removed = BluetoothDeviceRemoved::match_rule(
Some(&"org.Xetibo.ReSetDaemon".into()),
Some(&Path::from("/org/Xetibo/ReSetDaemon")),
Some(&"org.Xetibo.ReSet.Daemon".into()),
Some(&Path::from("/org/Xetibo/ReSet/Dameon")),
)
.static_clone();
let device_changed = BluetoothDeviceChanged::match_rule(
Some(&"org.Xetibo.ReSetDaemon".into()),
Some(&Path::from("/org/Xetibo/ReSetDaemon")),
Some(&"org.Xetibo.ReSet.Daemon".into()),
Some(&Path::from("/org/Xetibo/ReSet/Dameon")),
)
.static_clone();
let device_added_box = bluetooth_box.clone();
@ -329,7 +334,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
let _ = conn.process(Duration::from_millis(1000));
if !listeners.bluetooth_listener.load(Ordering::SeqCst) {
let _: Result<(), Error> =
proxy.method_call("org.Xetibo.ReSetBluetooth", "StopBluetoothListener", ());
proxy.method_call("org.Xetibo.ReSet.Bluetooth", "StopBluetoothListener", ());
break;
}
if listener_active && time.elapsed().unwrap() > Duration::from_millis(10000) {
@ -344,7 +349,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
});
});
let _: Result<(), Error> =
proxy.method_call("org.Xetibo.ReSetBluetooth", "StopBluetoothScan", ());
proxy.method_call("org.Xetibo.ReSet.Bluetooth", "StopBluetoothScan", ());
}
if !listener_active && listeners.bluetooth_scan_requested.load(Ordering::SeqCst) {
listeners
@ -352,7 +357,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
.store(false, Ordering::SeqCst);
listener_active = true;
let _: Result<(), Error> =
proxy.method_call("org.Xetibo.ReSetBluetooth", "StartBluetoothListener", ());
proxy.method_call("org.Xetibo.ReSet.Bluetooth", "StartBluetoothListener", ());
time = SystemTime::now();
}
thread::sleep(Duration::from_millis(100));
@ -363,12 +368,12 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
fn get_connected_devices() -> Vec<BluetoothDevice> {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.Xetibo.ReSetDaemon",
"/org/Xetibo/ReSetDaemon",
"org.Xetibo.ReSet.Daemon",
"/org/Xetibo/ReSet/Dameon",
Duration::from_millis(1000),
);
let res: Result<(Vec<BluetoothDevice>,), Error> = proxy.method_call(
"org.Xetibo.ReSetBluetooth",
"org.Xetibo.ReSet.Bluetooth",
"GetConnectedBluetoothDevices",
(),
);
@ -381,12 +386,12 @@ fn get_connected_devices() -> Vec<BluetoothDevice> {
fn get_bluetooth_adapters() -> Vec<BluetoothAdapter> {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.Xetibo.ReSetDaemon",
"/org/Xetibo/ReSetDaemon",
"org.Xetibo.ReSet.Daemon",
"/org/Xetibo/ReSet/Dameon",
Duration::from_millis(1000),
);
let res: Result<(Vec<BluetoothAdapter>,), Error> =
proxy.method_call("org.Xetibo.ReSetBluetooth", "GetBluetoothAdapters", ());
proxy.method_call("org.Xetibo.ReSet.Bluetooth", "GetBluetoothAdapters", ());
if res.is_err() {
return Vec::new();
}
@ -396,23 +401,23 @@ fn get_bluetooth_adapters() -> Vec<BluetoothAdapter> {
fn set_bluetooth_adapter(path: Path<'static>) {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.Xetibo.ReSetDaemon",
"/org/Xetibo/ReSetDaemon",
"org.Xetibo.ReSet.Daemon",
"/org/Xetibo/ReSet/Dameon",
Duration::from_millis(1000),
);
let _: Result<(Vec<BluetoothAdapter>,), Error> =
proxy.method_call("org.Xetibo.ReSetBluetooth", "SetBluetoothAdapter", (path,));
proxy.method_call("org.Xetibo.ReSet.Bluetooth", "SetBluetoothAdapter", (path,));
}
fn set_bluetooth_adapter_visibility(path: Path<'static>, visible: bool) {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.Xetibo.ReSetDaemon",
"/org/Xetibo/ReSetDaemon",
"org.Xetibo.ReSet.Daemon",
"/org/Xetibo/ReSet/Dameon",
Duration::from_millis(1000),
);
let _: Result<(bool,), Error> = proxy.method_call(
"org.Xetibo.ReSetBluetooth",
"org.Xetibo.ReSet.Bluetooth",
"SetBluetoothAdapterDiscoverability",
(path, visible),
);
@ -421,12 +426,12 @@ fn set_bluetooth_adapter_visibility(path: Path<'static>, visible: bool) {
fn set_bluetooth_adapter_pairability(path: Path<'static>, visible: bool) {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.Xetibo.ReSetDaemon",
"/org/Xetibo/ReSetDaemon",
"org.Xetibo.ReSet.Daemon",
"/org/Xetibo/ReSet/Dameon",
Duration::from_millis(1000),
);
let _: Result<(bool,), Error> = proxy.method_call(
"org.Xetibo.ReSetBluetooth",
"org.Xetibo.ReSet.Bluetooth",
"SetBluetoothAdapterPairability",
(path, visible),
);
@ -435,12 +440,12 @@ fn set_bluetooth_adapter_pairability(path: Path<'static>, visible: bool) {
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",
"org.Xetibo.ReSet.Daemon",
"/org/Xetibo/ReSet/Dameon",
Duration::from_millis(1000),
);
let _: Result<(Vec<BluetoothAdapter>,), Error> = proxy.method_call(
"org.Xetibo.ReSetBluetooth",
"org.Xetibo.ReSet.Bluetooth",
"SetBluetoothAdapterEnabled",
(path, enabled),
);

View file

@ -87,12 +87,12 @@ fn connect_to_device(entry: Arc<BluetoothEntry>, path: Path<'static>) {
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.Xetibo.ReSetDaemon",
"/org/Xetibo/ReSetDaemon",
"org.Xetibo.ReSet.Daemon",
"/org/Xetibo/ReSet/Daemon",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> = proxy.method_call(
"org.Xetibo.ReSetBluetooth",
"org.Xetibo.ReSet.Bluetooth",
"ConnectToBluetoothDevice",
(path,),
);
@ -118,12 +118,12 @@ fn connect_to_device(entry: Arc<BluetoothEntry>, path: Path<'static>) {
// gio::spawn_blocking(move || {
// let conn = Connection::new_session().unwrap();
// let proxy = conn.with_proxy(
// "org.Xetibo.ReSetDaemon",
// "/org/Xetibo/ReSetDaemon",
// "org.Xetibo.ReSet.Daemon",
// "/org/Xetibo/ReSet/Daemon",
// Duration::from_millis(1000),
// );
// let _: Result<(bool,), Error> = proxy.method_call(
// "org.Xetibo.ReSetBluetooth",
// "org.Xetibo.ReSet.Bluetooth",
// "PairWithBluetoothDevice",
// (path,),
// );
@ -134,12 +134,12 @@ fn disconnect_from_device(entry: Arc<BluetoothEntry>, path: Path<'static>) {
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.Xetibo.ReSetDaemon",
"/org/Xetibo/ReSetDaemon",
"org.Xetibo.ReSet.Daemon",
"/org/Xetibo/ReSet/Daemon",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> = proxy.method_call(
"org.Xetibo.ReSetBluetooth",
"org.Xetibo.ReSet.Bluetooth",
"DisconnectFromBluetoothDevice",
(path,),
);
@ -164,11 +164,11 @@ fn remove_device_pairing(path: Path<'static>) {
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.Xetibo.ReSetDaemon",
"/org/Xetibo/ReSetDaemon",
"org.Xetibo.ReSet.Daemon",
"/org/Xetibo/ReSet/Daemon",
Duration::from_millis(1000),
);
let _: Result<(bool,), Error> =
proxy.method_call("org.Xetibo.ReSetBluetooth", "RemoveDevicePairing", (path,));
proxy.method_call("org.Xetibo.ReSet.Bluetooth", "RemoveDevicePairing", (path,));
});
}