diff --git a/Cargo.toml b/Cargo.toml index 72dfd04..c39d5c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,8 @@ repository = "https://github.com/Xetibo/ReSet" license = "GPL-3.0-only" [dependencies] -reset_daemon = "0.5.3" -re_set-lib = "0.8.0" +reset_daemon = "0.5.5" +re_set-lib = "0.8.1" adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] } dbus = "0.9.7" gtk = { version = "0.7.3", package = "gtk4", features = ["v4_12"] } diff --git a/src/components/base/card_entry.rs b/src/components/base/card_entry.rs index c021f69..17c53ca 100644 --- a/src/components/base/card_entry.rs +++ b/src/components/base/card_entry.rs @@ -13,6 +13,7 @@ use components::utils::create_dropdown_label_factory; use re_set_lib::audio::audio_structures::Card; use crate::components; +use crate::components::utils::{BASE, DBUS_PATH, AUDIO}; use super::card_entry_impl; @@ -66,12 +67,12 @@ fn set_card_profile_of_device(device_index: u32, profile_name: String) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = proxy.method_call( - "org.Xetibo.ReSet.Audio", + AUDIO, "SetCardProfileOfDevice", (device_index, profile_name), ); diff --git a/src/components/base/utils.rs b/src/components/base/utils.rs index ab71927..a7eaff0 100644 --- a/src/components/base/utils.rs +++ b/src/components/base/utils.rs @@ -20,7 +20,7 @@ use re_set_lib::{ use crate::components::{ input::source_box::{start_input_box_listener, SourceBox}, - output::sink_box::{start_output_box_listener, SinkBox}, + output::sink_box::{start_output_box_listener, SinkBox}, utils::{BASE, DBUS_PATH, AUDIO, WIRELESS}, }; #[derive(Default, PartialEq, Eq)] @@ -53,12 +53,12 @@ impl Listeners { thread::spawn(|| { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(bool,), Error> = - proxy.method_call("org.Xetibo.ReSet.Wireless", "StopNetworkListener", ()); + proxy.method_call(WIRELESS, "StopNetworkListener", ()); }); } @@ -90,7 +90,7 @@ impl arg::ReadAll for SinkAdded { impl dbus::message::SignalArgs for SinkAdded { const NAME: &'static str = "SinkAdded"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } impl GetVal<(Sink,)> for SinkAdded { @@ -118,7 +118,7 @@ impl arg::ReadAll for SinkChanged { impl dbus::message::SignalArgs for SinkChanged { const NAME: &'static str = "SinkChanged"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } impl GetVal<(Sink,)> for SinkChanged { @@ -146,7 +146,7 @@ impl arg::ReadAll for SinkRemoved { impl dbus::message::SignalArgs for SinkRemoved { const NAME: &'static str = "SinkRemoved"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } impl GetVal<(u32,)> for SinkRemoved { @@ -174,7 +174,7 @@ impl arg::ReadAll for InputStreamAdded { impl dbus::message::SignalArgs for InputStreamAdded { const NAME: &'static str = "InputStreamAdded"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } impl GetVal<(InputStream,)> for InputStreamAdded { @@ -202,7 +202,7 @@ impl arg::ReadAll for InputStreamChanged { impl dbus::message::SignalArgs for InputStreamChanged { const NAME: &'static str = "InputStreamChanged"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } #[derive(Debug)] @@ -224,7 +224,7 @@ impl arg::ReadAll for InputStreamRemoved { impl dbus::message::SignalArgs for InputStreamRemoved { const NAME: &'static str = "InputStreamRemoved"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } impl GetVal<(u32,)> for InputStreamRemoved { @@ -252,7 +252,7 @@ impl arg::ReadAll for SourceAdded { impl dbus::message::SignalArgs for SourceAdded { const NAME: &'static str = "SourceAdded"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } impl GetVal<(Source,)> for SourceAdded { @@ -280,7 +280,7 @@ impl arg::ReadAll for SourceChanged { impl dbus::message::SignalArgs for SourceChanged { const NAME: &'static str = "SourceChanged"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } impl GetVal<(Source,)> for SourceChanged { @@ -308,7 +308,7 @@ impl arg::ReadAll for SourceRemoved { impl dbus::message::SignalArgs for SourceRemoved { const NAME: &'static str = "SourceRemoved"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } impl GetVal<(u32,)> for SourceRemoved { @@ -336,7 +336,7 @@ impl arg::ReadAll for OutputStreamAdded { impl dbus::message::SignalArgs for OutputStreamAdded { const NAME: &'static str = "OutputStreamAdded"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } impl GetVal<(OutputStream,)> for OutputStreamAdded { @@ -364,7 +364,7 @@ impl arg::ReadAll for OutputStreamChanged { impl dbus::message::SignalArgs for OutputStreamChanged { const NAME: &'static str = "OutputStreamChanged"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } #[derive(Debug)] @@ -386,7 +386,7 @@ impl arg::ReadAll for OutputStreamRemoved { impl dbus::message::SignalArgs for OutputStreamRemoved { const NAME: &'static str = "OutputStreamRemoved"; - const INTERFACE: &'static str = "org.Xetibo.ReSet.Audio"; + const INTERFACE: &'static str = AUDIO; } impl GetVal<(u32,)> for OutputStreamRemoved { @@ -431,19 +431,19 @@ pub fn start_audio_listener( fn start_dbus_audio_listener(conn: Connection) -> Connection { let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); - let _: Result<(), Error> = proxy.method_call("org.Xetibo.ReSet.Audio", "StartAudioListener", ()); + let _: Result<(), Error> = proxy.method_call(AUDIO, "StartAudioListener", ()); conn } fn stop_dbus_audio_listener(conn: Connection) { let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); - let _: Result<(), Error> = proxy.method_call("org.Xetibo.ReSet.Audio", "StopAudioListener", ()); + let _: Result<(), Error> = proxy.method_call(AUDIO, "StopAudioListener", ()); } diff --git a/src/components/bluetooth/bluetooth_box.rs b/src/components/bluetooth/bluetooth_box.rs index bda36d2..1f7c19e 100644 --- a/src/components/bluetooth/bluetooth_box.rs +++ b/src/components/bluetooth/bluetooth_box.rs @@ -20,6 +20,7 @@ use re_set_lib::signals::{BluetoothDeviceAdded, BluetoothDeviceChanged, Bluetoot use crate::components::base::utils::Listeners; use crate::components::bluetooth::bluetooth_box_impl; use crate::components::bluetooth::bluetooth_entry::BluetoothEntry; +use crate::components::utils::{DBUS_PATH, BASE, BLUETOOTH}; glib::wrapper! { pub struct BluetoothBox(ObjectSubclass) @@ -123,10 +124,8 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc) { 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; - } + if adapters.is_empty() { + return; } imp.reset_current_bluetooth_adapter .replace(adapters.last().unwrap().clone()); @@ -209,25 +208,25 @@ pub fn start_bluetooth_listener(listeners: Arc, bluetooth_box: Arc = - proxy.method_call("org.Xetibo.ReSet.Bluetooth", "StartBluetoothListener", ()); + proxy.method_call(BLUETOOTH, "StartBluetoothListener", ()); let device_added = BluetoothDeviceAdded::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let device_removed = BluetoothDeviceRemoved::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let device_changed = BluetoothDeviceChanged::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let device_added_box = bluetooth_box.clone(); @@ -334,7 +333,7 @@ pub fn start_bluetooth_listener(listeners: Arc, bluetooth_box: Arc = - proxy.method_call("org.Xetibo.ReSet.Bluetooth", "StopBluetoothListener", ()); + proxy.method_call(BLUETOOTH, "StopBluetoothListener", ()); break; } if listener_active && time.elapsed().unwrap() > Duration::from_millis(10000) { @@ -349,7 +348,7 @@ pub fn start_bluetooth_listener(listeners: Arc, bluetooth_box: Arc = - proxy.method_call("org.Xetibo.ReSet.Bluetooth", "StopBluetoothScan", ()); + proxy.method_call(BLUETOOTH, "StopBluetoothScan", ()); } if !listener_active && listeners.bluetooth_scan_requested.load(Ordering::SeqCst) { listeners @@ -357,7 +356,7 @@ pub fn start_bluetooth_listener(listeners: Arc, bluetooth_box: Arc = - proxy.method_call("org.Xetibo.ReSet.Bluetooth", "StartBluetoothListener", ()); + proxy.method_call(BLUETOOTH, "StartBluetoothListener", ()); time = SystemTime::now(); } thread::sleep(Duration::from_millis(100)); @@ -368,12 +367,12 @@ pub fn start_bluetooth_listener(listeners: Arc, bluetooth_box: Arc Vec { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Vec,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Bluetooth", + BLUETOOTH, "GetConnectedBluetoothDevices", (), ); @@ -386,12 +385,12 @@ fn get_connected_devices() -> Vec { fn get_bluetooth_adapters() -> Vec { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Vec,), Error> = - proxy.method_call("org.Xetibo.ReSet.Bluetooth", "GetBluetoothAdapters", ()); + proxy.method_call(BLUETOOTH, "GetBluetoothAdapters", ()); if res.is_err() { return Vec::new(); } @@ -401,23 +400,23 @@ fn get_bluetooth_adapters() -> Vec { fn set_bluetooth_adapter(path: Path<'static>) { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(Vec,), Error> = - proxy.method_call("org.Xetibo.ReSet.Bluetooth", "SetBluetoothAdapter", (path,)); + proxy.method_call(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.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(bool,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Bluetooth", + BLUETOOTH, "SetBluetoothAdapterDiscoverability", (path, visible), ); @@ -426,12 +425,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.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(bool,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Bluetooth", + BLUETOOTH, "SetBluetoothAdapterPairability", (path, visible), ); @@ -440,12 +439,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.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(Vec,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Bluetooth", + BLUETOOTH, "SetBluetoothAdapterEnabled", (path, enabled), ); diff --git a/src/components/bluetooth/bluetooth_entry.rs b/src/components/bluetooth/bluetooth_entry.rs index 298576f..bca6cfb 100644 --- a/src/components/bluetooth/bluetooth_entry.rs +++ b/src/components/bluetooth/bluetooth_entry.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use std::time::Duration; use crate::components::bluetooth::bluetooth_entry_impl; +use crate::components::utils::{BASE, DBUS_PATH, BLUETOOTH}; use adw::glib::Object; use adw::prelude::{ActionRowExt, PreferencesRowExt}; use adw::{glib, ActionRow}; @@ -87,12 +88,12 @@ fn connect_to_device(entry: Arc, path: Path<'static>) { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(bool,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Bluetooth", + BLUETOOTH, "ConnectToBluetoothDevice", (path,), ); @@ -118,12 +119,12 @@ fn connect_to_device(entry: Arc, path: Path<'static>) { // gio::spawn_blocking(move || { // let conn = Connection::new_session().unwrap(); // let proxy = conn.with_proxy( -// "org.Xetibo.ReSet.Daemon", -// "/org/Xetibo/ReSet/Daemon", +// BASE, +// DBUS_PATH, // Duration::from_millis(1000), // ); // let _: Result<(bool,), Error> = proxy.method_call( -// "org.Xetibo.ReSet.Bluetooth", +// BLUETOOTH, // "PairWithBluetoothDevice", // (path,), // ); @@ -134,12 +135,12 @@ fn disconnect_from_device(entry: Arc, path: Path<'static>) { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(bool,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Bluetooth", + BLUETOOTH, "DisconnectFromBluetoothDevice", (path,), ); @@ -164,11 +165,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.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(bool,), Error> = - proxy.method_call("org.Xetibo.ReSet.Bluetooth", "RemoveDevicePairing", (path,)); + proxy.method_call(BLUETOOTH, "RemoveDevicePairing", (path,)); }); } diff --git a/src/components/input/output_stream_entry.rs b/src/components/input/output_stream_entry.rs index a3aaab8..2b4339c 100644 --- a/src/components/input/output_stream_entry.rs +++ b/src/components/input/output_stream_entry.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use std::time::{Duration, SystemTime}; -use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis}; +use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis, BASE, DBUS_PATH, AUDIO}; use adw::glib; use adw::glib::Object; use adw::prelude::{ButtonExt, ComboRowExt, PreferencesRowExt, RangeExt}; @@ -134,12 +134,12 @@ fn set_outputstream_volume(value: f64, index: u32, channels: u16) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = proxy.method_call( - "org.Xetibo.ReSet.Audio", + AUDIO, "SetOutputStreamVolume", (index, channels, value as u32), ); @@ -155,12 +155,12 @@ fn toggle_output_stream_mute(index: u32, muted: bool) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = proxy.method_call( - "org.Xetibo.ReSet.Audio", + AUDIO, "SetOutputStreamMute", (index, muted), ); @@ -176,12 +176,12 @@ fn set_source_of_output_stream(stream: u32, source: u32) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(bool,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Audio", + AUDIO, "SetSourceOfOutputStream", (stream, source), ); diff --git a/src/components/input/source_box.rs b/src/components/input/source_box.rs index b1d2211..2fff091 100644 --- a/src/components/input/source_box.rs +++ b/src/components/input/source_box.rs @@ -24,7 +24,7 @@ use crate::components::base::utils::{ }; use crate::components::input::source_box_impl; use crate::components::input::source_entry::set_source_volume; -use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis}; +use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis, BASE, DBUS_PATH, AUDIO}; use super::output_stream_entry::OutputStreamEntry; use super::source_entry::{set_default_source, toggle_source_mute, SourceEntry}; @@ -312,12 +312,12 @@ pub fn populate_cards(input_box: Arc) { fn get_output_streams() -> Vec { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Vec,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "ListOutputStreams", ()); + proxy.method_call(AUDIO, "ListOutputStreams", ()); if res.is_err() { return Vec::new(); } @@ -327,12 +327,12 @@ fn get_output_streams() -> Vec { fn get_sources() -> Vec { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Vec,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "ListSources", ()); + proxy.method_call(AUDIO, "ListSources", ()); if res.is_err() { return Vec::new(); } @@ -342,12 +342,12 @@ fn get_sources() -> Vec { fn get_cards() -> Vec { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Vec,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "ListCards", ()); + proxy.method_call(AUDIO, "ListCards", ()); if res.is_err() { return Vec::new(); } @@ -357,12 +357,12 @@ fn get_cards() -> Vec { fn get_default_source_name() -> String { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(String,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "GetDefaultSourceName", ()); + proxy.method_call(AUDIO, "GetDefaultSourceName", ()); if res.is_err() { return String::from(""); } @@ -372,12 +372,12 @@ fn get_default_source_name() -> String { fn get_default_source() -> Source { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Source,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "GetDefaultSource", ()); + proxy.method_call(AUDIO, "GetDefaultSource", ()); if res.is_err() { return Source::default(); } @@ -386,33 +386,33 @@ fn get_default_source() -> Source { pub fn start_input_box_listener(conn: Connection, source_box: Arc) -> Connection { let source_added = SourceAdded::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let source_removed = SourceRemoved::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let source_changed = SourceChanged::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let output_stream_added = OutputStreamAdded::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let output_stream_removed = OutputStreamRemoved::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let output_stream_changed = OutputStreamChanged::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); diff --git a/src/components/input/source_entry.rs b/src/components/input/source_entry.rs index 1edea34..6b5bfc3 100644 --- a/src/components/input/source_entry.rs +++ b/src/components/input/source_entry.rs @@ -11,6 +11,8 @@ use glib::{clone, Propagation}; use gtk::{gio, CheckButton}; use re_set_lib::audio::audio_structures::Source; +use crate::components::utils::{BASE, DBUS_PATH, AUDIO}; + use super::source_box::{refresh_default_source, SourceBox}; use super::source_entry_impl; @@ -105,12 +107,12 @@ pub fn set_source_volume(value: f64, index: u32, channels: u16) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = proxy.method_call( - "org.Xetibo.ReSet.Audio", + AUDIO, "SetSourceVolume", (index, channels, value as u32), ); @@ -126,12 +128,12 @@ pub fn toggle_source_mute(index: u32, muted: bool) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "SetSourceMute", (index, muted)); + proxy.method_call(AUDIO, "SetSourceMute", (index, muted)); // if res.is_err() { // return false; // } @@ -143,12 +145,12 @@ pub fn toggle_source_mute(index: u32, muted: bool) -> bool { pub fn set_default_source(name: Arc) -> Option { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Source,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Audio", + AUDIO, "SetDefaultSource", (name.as_str(),), ); diff --git a/src/components/output/input_stream_entry.rs b/src/components/output/input_stream_entry.rs index e06e0a6..bf241d2 100644 --- a/src/components/output/input_stream_entry.rs +++ b/src/components/output/input_stream_entry.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use std::time::{Duration, SystemTime}; -use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis}; +use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis, BASE, DBUS_PATH, AUDIO}; use adw::glib; use adw::glib::Object; use adw::prelude::{ButtonExt, ComboRowExt, PreferencesRowExt, RangeExt}; @@ -161,12 +161,12 @@ fn set_inputstream_volume(value: f64, index: u32, channels: u16) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = proxy.method_call( - "org.Xetibo.ReSet.Audio", + AUDIO, "SetInputStreamVolume", (index, channels, value as u32), ); @@ -182,12 +182,12 @@ fn toggle_input_stream_mute(index: u32, muted: bool) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = proxy.method_call( - "org.Xetibo.ReSet.Audio", + AUDIO, "SetInputStreamMute", (index, muted), ); @@ -203,12 +203,12 @@ fn set_sink_of_input_stream(stream: u32, sink: u32) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = proxy.method_call( - "org.Xetibo.ReSet.Audio", + AUDIO, "SetSinkOfInputStream", (stream, sink), ); diff --git a/src/components/output/sink_box.rs b/src/components/output/sink_box.rs index 5ae7ee9..40a1ec3 100644 --- a/src/components/output/sink_box.rs +++ b/src/components/output/sink_box.rs @@ -23,6 +23,9 @@ use crate::components::base::utils::{ InputStreamAdded, InputStreamChanged, InputStreamRemoved, SinkAdded, SinkChanged, SinkRemoved, }; use crate::components::output::sink_entry::set_sink_volume; +use crate::components::utils::AUDIO; +use crate::components::utils::BASE; +use crate::components::utils::DBUS_PATH; use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis}; use super::input_stream_entry::InputStreamEntry; @@ -310,12 +313,12 @@ pub fn populate_cards(output_box: Arc) { fn get_input_streams() -> Vec { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Vec,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "ListInputStreams", ()); + proxy.method_call(AUDIO, "ListInputStreams", ()); if res.is_err() { return Vec::new(); } @@ -325,12 +328,12 @@ fn get_input_streams() -> Vec { fn get_sinks() -> Vec { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Vec,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "ListSinks", ()); + proxy.method_call(AUDIO, "ListSinks", ()); if res.is_err() { return Vec::new(); } @@ -340,12 +343,12 @@ fn get_sinks() -> Vec { fn get_cards() -> Vec { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Vec,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "ListCards", ()); + proxy.method_call(AUDIO, "ListCards", ()); if res.is_err() { return Vec::new(); } @@ -355,12 +358,12 @@ fn get_cards() -> Vec { fn get_default_sink_name() -> String { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(String,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "GetDefaultSinkName", ()); + proxy.method_call(AUDIO, "GetDefaultSinkName", ()); if res.is_err() { return String::from(""); } @@ -370,12 +373,12 @@ fn get_default_sink_name() -> String { fn get_default_sink() -> Sink { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Sink,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "GetDefaultSink", ()); + proxy.method_call(AUDIO, "GetDefaultSink", ()); if res.is_err() { return Sink::default(); } @@ -384,33 +387,33 @@ fn get_default_sink() -> Sink { pub fn start_output_box_listener(conn: Connection, sink_box: Arc) -> Connection { let sink_added = SinkAdded::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let sink_removed = SinkRemoved::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let sink_changed = SinkChanged::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let input_stream_added = InputStreamAdded::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let input_stream_removed = InputStreamRemoved::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); let input_stream_changed = InputStreamChanged::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), + Some(&BASE.into()), + Some(&Path::from(DBUS_PATH)), ) .static_clone(); diff --git a/src/components/output/sink_entry.rs b/src/components/output/sink_entry.rs index 9c883d2..040ce21 100644 --- a/src/components/output/sink_entry.rs +++ b/src/components/output/sink_entry.rs @@ -11,6 +11,8 @@ use glib::{clone, Propagation}; use gtk::{gio, CheckButton}; use re_set_lib::audio::audio_structures::Sink; +use crate::components::utils::{AUDIO, DBUS_PATH, BASE}; + use super::sink_box::{refresh_default_sink, SinkBox}; use super::sink_entry_impl; @@ -103,12 +105,12 @@ pub fn set_sink_volume(value: f64, index: u32, channels: u16) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = proxy.method_call( - "org.Xetibo.ReSet.Audio", + AUDIO, "SetSinkVolume", (index, channels, value as u32), ); @@ -124,12 +126,12 @@ pub fn toggle_sink_mute(index: u32, muted: bool) -> bool { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "SetSinkMute", (index, muted)); + proxy.method_call(AUDIO, "SetSinkMute", (index, muted)); // if res.is_err() { // return false; // } @@ -141,12 +143,12 @@ pub fn toggle_sink_mute(index: u32, muted: bool) -> bool { pub fn set_default_sink(name: Arc) -> Option { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: Result<(Sink,), Error> = - proxy.method_call("org.Xetibo.ReSet.Audio", "SetDefaultSink", (name.as_str(),)); + proxy.method_call(AUDIO, "SetDefaultSink", (name.as_str(),)); if res.is_err() { return None; } diff --git a/src/components/utils.rs b/src/components/utils.rs index e8b47a4..3ab1dd4 100644 --- a/src/components/utils.rs +++ b/src/components/utils.rs @@ -5,6 +5,12 @@ use glib::{Cast, Object}; use gtk::prelude::{GObjectPropertyExpressionExt, ListBoxRowExt, ListItemExt, WidgetExt}; use gtk::{Align, SignalListItemFactory, StringObject}; +pub const DBUS_PATH: &str = "/org/Xetibo/ReSet/Daemon"; +pub const WIRELESS: &str = "org.Xetibo.ReSet.Wireless"; +pub const BLUETOOTH: &str = "org.Xetibo.ReSet.Bluetooth"; +pub const AUDIO: &str = "org.Xetibo.ReSet.Audio"; +pub const BASE: &str = "org.Xetibo.ReSet.Daemon"; + pub fn create_dropdown_label_factory() -> SignalListItemFactory { let factory = SignalListItemFactory::new(); factory.connect_setup(|_, item| { diff --git a/src/components/wifi/saved_wifi_entry.rs b/src/components/wifi/saved_wifi_entry.rs index ec5eacb..0f02f21 100644 --- a/src/components/wifi/saved_wifi_entry.rs +++ b/src/components/wifi/saved_wifi_entry.rs @@ -1,6 +1,7 @@ use std::rc::Rc; use std::time::Duration; +use crate::components::utils::{BASE, DBUS_PATH, WIRELESS}; use crate::components::wifi::saved_wifi_entry_impl; use crate::components::wifi::utils::get_connection_settings; use crate::components::wifi::wifi_box_impl::WifiBox; @@ -66,11 +67,11 @@ fn delete_connection(path: Path<'static>) { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(), Error> = - proxy.method_call("org.Xetibo.ReSet.Wireless", "DeleteConnection", (path,)); + proxy.method_call(WIRELESS, "DeleteConnection", (path,)); }); } diff --git a/src/components/wifi/utils.rs b/src/components/wifi/utils.rs index eda4767..8d0543b 100644 --- a/src/components/wifi/utils.rs +++ b/src/components/wifi/utils.rs @@ -6,6 +6,10 @@ use re_set_lib::network::connection::Connection as ResetConnection; use std::collections::HashMap; use std::time::Duration; +use crate::components::utils::BASE; +use crate::components::utils::DBUS_PATH; +use crate::components::utils::WIRELESS; + #[derive(Default, Copy, Clone)] pub enum IpProtocol { #[default] @@ -19,12 +23,12 @@ type ResultType = pub fn get_connection_settings(path: Path<'static>) -> ResetConnection { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let res: ResultType = - proxy.method_call("org.Xetibo.ReSet.Wireless", "GetConnectionSettings", (path,)); + proxy.method_call(WIRELESS, "GetConnectionSettings", (path,)); if res.is_err() { ResetConnection::default(); } diff --git a/src/components/wifi/wifi_box.rs b/src/components/wifi/wifi_box.rs index bca9f2b..f167b78 100644 --- a/src/components/wifi/wifi_box.rs +++ b/src/components/wifi/wifi_box.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use std::time::Duration; use crate::components::base::utils::Listeners; -use crate::components::utils::set_combo_row_ellipsis; +use crate::components::utils::{set_combo_row_ellipsis, BASE, DBUS_PATH, WIRELESS}; use adw::glib; use adw::glib::Object; use adw::prelude::{ComboRowExt, ListBoxRowExt, PreferencesGroupExt, PreferencesRowExt}; @@ -103,10 +103,8 @@ pub fn scan_for_wifi(wifi_box: Arc) { let list = imp.reset_model_list.write().unwrap(); let mut model_index = imp.reset_model_index.write().unwrap(); let mut map = imp.reset_wifi_devices.write().unwrap(); - { - if imp.reset_current_wifi_device.borrow().path == Path::from("/") { - return; - } + if devices.is_empty() { + return; } imp.reset_current_wifi_device .replace(devices.last().unwrap().clone()); @@ -192,24 +190,15 @@ pub fn show_stored_connections(wifi_box: Arc) { pub fn dbus_start_network_events() { let conn = Connection::new_session().unwrap(); - let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", - Duration::from_millis(1000), - ); - let _: Result<(), Error> = - proxy.method_call("org.Xetibo.ReSet.Wireless", "StartNetworkListener", ()); + let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000)); + let _: Result<(), Error> = proxy.method_call(WIRELESS, "StartNetworkListener", ()); } pub fn get_access_points() -> Vec { let conn = Connection::new_session().unwrap(); - let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", - Duration::from_millis(1000), - ); + let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000)); let res: Result<(Vec,), Error> = - proxy.method_call("org.Xetibo.ReSet.Wireless", "ListAccessPoints", ()); + proxy.method_call(WIRELESS, "ListAccessPoints", ()); if res.is_err() { return Vec::new(); } @@ -219,24 +208,15 @@ pub fn get_access_points() -> Vec { pub fn set_wifi_device(path: Path<'static>) { let conn = Connection::new_session().unwrap(); - let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", - Duration::from_millis(1000), - ); - let _: Result<(bool,), Error> = - proxy.method_call("org.Xetibo.ReSet.Wireless", "SetWifiDevice", (path,)); + let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000)); + let _: Result<(bool,), Error> = proxy.method_call(WIRELESS, "SetWifiDevice", (path,)); } pub fn get_wifi_devices() -> Vec { let conn = Connection::new_session().unwrap(); - let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", - Duration::from_millis(1000), - ); + let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000)); let res: Result<(Vec,), Error> = - proxy.method_call("org.Xetibo.ReSet.Wireless", "GetAllWifiDevices", ()); + proxy.method_call(WIRELESS, "GetAllWifiDevices", ()); if res.is_err() { return Vec::new(); } @@ -246,13 +226,8 @@ pub fn get_wifi_devices() -> Vec { pub fn get_wifi_status() -> bool { let conn = Connection::new_session().unwrap(); - let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", - Duration::from_millis(1000), - ); - let res: Result<(bool,), Error> = - proxy.method_call("org.Xetibo.ReSet.Wireless", "GetWifiStatus", ()); + let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000)); + let res: Result<(bool,), Error> = proxy.method_call(WIRELESS, "GetWifiStatus", ()); if res.is_err() { return false; } @@ -261,13 +236,8 @@ pub fn get_wifi_status() -> bool { pub fn get_stored_connections() -> Vec<(Path<'static>, Vec)> { let conn = Connection::new_session().unwrap(); - let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", - Duration::from_millis(1000), - ); - let res: ResultMap = - proxy.method_call("org.Xetibo.ReSet.Wireless", "ListStoredConnections", ()); + let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000)); + let res: ResultMap = proxy.method_call(WIRELESS, "ListStoredConnections", ()); if res.is_err() { return Vec::new(); } @@ -277,13 +247,8 @@ pub fn get_stored_connections() -> Vec<(Path<'static>, Vec)> { pub fn set_wifi_enabled(enabled: bool) { let conn = Connection::new_session().unwrap(); - let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", - Duration::from_millis(1000), - ); - let _: Result<(bool,), Error> = - proxy.method_call("org.Xetibo.ReSet.Wireless", "SetWifiEnabled", (enabled,)); + let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000)); + let _: Result<(bool,), Error> = proxy.method_call(WIRELESS, "SetWifiEnabled", (enabled,)); } pub fn start_event_listener(listeners: Arc, wifi_box: Arc) { @@ -300,26 +265,18 @@ pub fn start_event_listener(listeners: Arc, wifi_box: Arc) { let removed_ref = wifi_box.clone(); let changed_ref = wifi_box.clone(); let wifi_changed_ref = wifi_box.clone(); - let access_point_added = AccessPointAdded::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), - ) - .static_clone(); - let access_point_removed = AccessPointRemoved::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), - ) - .static_clone(); - let access_point_changed = AccessPointChanged::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), - ) - .static_clone(); - let device_changed = WifiDeviceChanged::match_rule( - Some(&"org.Xetibo.ReSet.Daemon".into()), - Some(&Path::from("/org/Xetibo/ReSet/Daemon")), - ) - .static_clone(); + let access_point_added = + AccessPointAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))) + .static_clone(); + let access_point_removed = + AccessPointRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))) + .static_clone(); + let access_point_changed = + AccessPointChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))) + .static_clone(); + let device_changed = + WifiDeviceChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))) + .static_clone(); let res = conn.add_match(access_point_added, move |ir: AccessPointAdded, _, _| { let wifi_box = added_ref.clone(); glib::spawn_future(async move { diff --git a/src/components/wifi/wifi_entry.rs b/src/components/wifi/wifi_entry.rs index 030f13b..44d468f 100644 --- a/src/components/wifi/wifi_entry.rs +++ b/src/components/wifi/wifi_entry.rs @@ -2,6 +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::wifi::utils::get_connection_settings; use adw::glib; use adw::glib::{Object, PropertySet}; @@ -123,12 +124,12 @@ pub fn click_disconnect(entry: Arc) { let imp = entry_ref.imp(); let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(10000), ); let res: Result<(bool,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Wireless", + WIRELESS, "DisconnectFromCurrentAccessPoint", (), ); @@ -154,12 +155,12 @@ pub fn click_stored_network(entry: Arc) { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(10000), ); let res: Result<(bool,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Wireless", + WIRELESS, "ConnectToKnownAccessPoint", (access_point,), ); @@ -197,12 +198,12 @@ pub fn click_new_network(entry: Arc) { gio::spawn_blocking(move || { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(10000), ); let res: Result<(bool,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Wireless", + WIRELESS, "ConnectToNewAccessPoint", (access_point, password), ); diff --git a/src/components/wifi/wifi_options.rs b/src/components/wifi/wifi_options.rs index 14429e9..ecd1948 100644 --- a/src/components/wifi/wifi_options.rs +++ b/src/components/wifi/wifi_options.rs @@ -18,6 +18,7 @@ use re_set_lib::network::connection::{ use IpProtocol::{IPv4, IPv6}; +use crate::components::utils::{BASE, DBUS_PATH, WIRELESS}; use crate::components::wifi::utils::IpProtocol; use crate::components::wifi::wifi_address_entry::WifiAddressEntry; use crate::components::wifi::wifi_options_impl; @@ -59,7 +60,7 @@ impl WifiOptions { .set_active(conn.settings.autoconnect); self_imp .reset_wifi_metered - .set_active(conn.settings.metered != -1); + .set_active(conn.settings.metered != 0); match &conn.device { TypeSettings::WIFI(wifi) => { self_imp.reset_wifi_link_speed.set_visible(false); @@ -389,12 +390,12 @@ fn set_connection_settings(path: Path<'static>, prop: HashMap) gio::spawn_blocking(move || { let conn = dbus::blocking::Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(1000), ); let _: Result<(bool,), Error> = proxy.method_call( - "org.Xetibo.ReSet.Wireless", + WIRELESS, "SetConnectionSettings", (path, prop), ); diff --git a/src/main.rs b/src/main.rs index 1ff8138..03a7e00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::thread; use std::time::Duration; +use components::utils::{BASE, DBUS_PATH}; use components::window::reset_window::ReSetWindow; use dbus::blocking::Connection; use dbus::Error; @@ -9,6 +10,8 @@ use gtk::prelude::*; use gtk::{gio, Application, CssProvider}; use reset_daemon::run_daemon; + + mod components; const APP_ID: &str = "org.Xetibo.ReSet"; @@ -53,12 +56,12 @@ fn shutdown(_: &Application) { thread::spawn(|| { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(100), ); let res: Result<(), Error> = - proxy.method_call("org.Xetibo.ReSet.Daemon", "UnregisterClient", ("ReSet",)); + proxy.method_call(BASE, "UnregisterClient", ("ReSet",)); res }); } @@ -67,16 +70,16 @@ async fn daemon_check() { let handle = thread::spawn(|| { let conn = Connection::new_session().unwrap(); let proxy = conn.with_proxy( - "org.Xetibo.ReSet.Daemon", - "/org/Xetibo/ReSet/Daemon", + BASE, + DBUS_PATH, Duration::from_millis(100), ); let res: Result<(), Error> = - proxy.method_call("org.Xetibo.ReSet.Daemon", "RegisterClient", ("ReSet",)); + proxy.method_call(BASE, "RegisterClient", ("ReSet",)); res }); let res = handle.join(); if res.unwrap().is_err() { - run_daemon(APP_ID).await; + run_daemon().await; } }