mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-12 08:28:32 +02:00
fix: Bluetooth and wifi restart
This commit is contained in:
parent
cca11a50ee
commit
b864dc9caf
|
@ -8,7 +8,7 @@ license = "GPL-3.0-only"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reset_daemon = "0.5.6"
|
reset_daemon = "0.5.6"
|
||||||
re_set-lib = "0.8.2"
|
re_set-lib = "0.8.4"
|
||||||
adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] }
|
adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] }
|
||||||
dbus = "0.9.7"
|
dbus = "0.9.7"
|
||||||
gtk = { version = "0.7.3", package = "gtk4", features = ["v4_12"] }
|
gtk = { version = "0.7.3", package = "gtk4", features = ["v4_12"] }
|
||||||
|
|
|
@ -7,20 +7,13 @@ use std::{
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use dbus::{
|
use dbus::{blocking::Connection, Error};
|
||||||
arg::{self, Append},
|
|
||||||
blocking::Connection,
|
|
||||||
Error,
|
|
||||||
};
|
|
||||||
use gtk::gio;
|
use gtk::gio;
|
||||||
use re_set_lib::{
|
|
||||||
audio::audio_structures::{InputStream, OutputStream, Sink, Source},
|
|
||||||
signals::GetVal,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
input::source_box::{start_input_box_listener, SourceBox},
|
input::source_box::{start_input_box_listener, SourceBox},
|
||||||
output::sink_box::{start_output_box_listener, SinkBox}, utils::{BASE, DBUS_PATH, AUDIO, WIRELESS},
|
output::sink_box::{start_output_box_listener, SinkBox},
|
||||||
|
utils::{AUDIO, BASE, DBUS_PATH, WIRELESS},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Eq)]
|
#[derive(Default, PartialEq, Eq)]
|
||||||
|
@ -52,13 +45,8 @@ impl Listeners {
|
||||||
self.wifi_listener.store(false, Ordering::SeqCst);
|
self.wifi_listener.store(false, Ordering::SeqCst);
|
||||||
thread::spawn(|| {
|
thread::spawn(|| {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let _: Result<(bool,), Error> = proxy.method_call(WIRELESS, "StopNetworkListener", ());
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let _: Result<(bool,), Error> =
|
|
||||||
proxy.method_call(WIRELESS, "StopNetworkListener", ());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,330 +59,6 @@ impl Listeners {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct SinkAdded {
|
|
||||||
pub sink: Sink,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for SinkAdded {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.sink.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for SinkAdded {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(SinkAdded { sink: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for SinkAdded {
|
|
||||||
const NAME: &'static str = "SinkAdded";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetVal<(Sink,)> for SinkAdded {
|
|
||||||
fn get_value(&self) -> (Sink,) {
|
|
||||||
(self.sink.clone(),)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct SinkChanged {
|
|
||||||
pub sink: Sink,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for SinkChanged {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.sink.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for SinkChanged {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(SinkChanged { sink: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for SinkChanged {
|
|
||||||
const NAME: &'static str = "SinkChanged";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetVal<(Sink,)> for SinkChanged {
|
|
||||||
fn get_value(&self) -> (Sink,) {
|
|
||||||
(self.sink.clone(),)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct SinkRemoved {
|
|
||||||
pub index: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for SinkRemoved {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.index.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for SinkRemoved {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(SinkRemoved { index: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for SinkRemoved {
|
|
||||||
const NAME: &'static str = "SinkRemoved";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetVal<(u32,)> for SinkRemoved {
|
|
||||||
fn get_value(&self) -> (u32,) {
|
|
||||||
(self.index,)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct InputStreamAdded {
|
|
||||||
pub stream: InputStream,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for InputStreamAdded {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.stream.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for InputStreamAdded {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(InputStreamAdded { stream: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for InputStreamAdded {
|
|
||||||
const NAME: &'static str = "InputStreamAdded";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetVal<(InputStream,)> for InputStreamAdded {
|
|
||||||
fn get_value(&self) -> (InputStream,) {
|
|
||||||
(self.stream.clone(),)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct InputStreamChanged {
|
|
||||||
pub stream: InputStream,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for InputStreamChanged {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.stream.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for InputStreamChanged {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(InputStreamChanged { stream: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for InputStreamChanged {
|
|
||||||
const NAME: &'static str = "InputStreamChanged";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct InputStreamRemoved {
|
|
||||||
pub index: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for InputStreamRemoved {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.index.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for InputStreamRemoved {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(InputStreamRemoved { index: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for InputStreamRemoved {
|
|
||||||
const NAME: &'static str = "InputStreamRemoved";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetVal<(u32,)> for InputStreamRemoved {
|
|
||||||
fn get_value(&self) -> (u32,) {
|
|
||||||
(self.index,)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct SourceAdded {
|
|
||||||
pub source: Source,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for SourceAdded {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.source.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for SourceAdded {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(SourceAdded { source: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for SourceAdded {
|
|
||||||
const NAME: &'static str = "SourceAdded";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetVal<(Source,)> for SourceAdded {
|
|
||||||
fn get_value(&self) -> (Source,) {
|
|
||||||
(self.source.clone(),)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct SourceChanged {
|
|
||||||
pub source: Source,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for SourceChanged {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.source.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for SourceChanged {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(SourceChanged { source: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for SourceChanged {
|
|
||||||
const NAME: &'static str = "SourceChanged";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetVal<(Source,)> for SourceChanged {
|
|
||||||
fn get_value(&self) -> (Source,) {
|
|
||||||
(self.source.clone(),)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct SourceRemoved {
|
|
||||||
pub index: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for SourceRemoved {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.index.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for SourceRemoved {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(SourceRemoved { index: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for SourceRemoved {
|
|
||||||
const NAME: &'static str = "SourceRemoved";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetVal<(u32,)> for SourceRemoved {
|
|
||||||
fn get_value(&self) -> (u32,) {
|
|
||||||
(self.index,)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct OutputStreamAdded {
|
|
||||||
pub stream: OutputStream,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for OutputStreamAdded {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.stream.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for OutputStreamAdded {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(OutputStreamAdded { stream: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for OutputStreamAdded {
|
|
||||||
const NAME: &'static str = "OutputStreamAdded";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetVal<(OutputStream,)> for OutputStreamAdded {
|
|
||||||
fn get_value(&self) -> (OutputStream,) {
|
|
||||||
(self.stream.clone(),)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct OutputStreamChanged {
|
|
||||||
pub stream: OutputStream,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for OutputStreamChanged {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.stream.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for OutputStreamChanged {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(OutputStreamChanged { stream: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for OutputStreamChanged {
|
|
||||||
const NAME: &'static str = "OutputStreamChanged";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct OutputStreamRemoved {
|
|
||||||
pub index: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::AppendAll for OutputStreamRemoved {
|
|
||||||
fn append(&self, i: &mut arg::IterAppend) {
|
|
||||||
self.index.append_by_ref(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl arg::ReadAll for OutputStreamRemoved {
|
|
||||||
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
|
|
||||||
Ok(OutputStreamRemoved { index: i.read()? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dbus::message::SignalArgs for OutputStreamRemoved {
|
|
||||||
const NAME: &'static str = "OutputStreamRemoved";
|
|
||||||
const INTERFACE: &'static str = AUDIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetVal<(u32,)> for OutputStreamRemoved {
|
|
||||||
fn get_value(&self) -> (u32,) {
|
|
||||||
(self.index,)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn start_audio_listener(
|
pub fn start_audio_listener(
|
||||||
listeners: Arc<Listeners>,
|
listeners: Arc<Listeners>,
|
||||||
sink_box: Option<Arc<SinkBox>>,
|
sink_box: Option<Arc<SinkBox>>,
|
||||||
|
@ -430,20 +94,12 @@ pub fn start_audio_listener(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_dbus_audio_listener(conn: Connection) -> Connection {
|
fn start_dbus_audio_listener(conn: Connection) -> Connection {
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let _: Result<(), Error> = proxy.method_call(AUDIO, "StartAudioListener", ());
|
let _: Result<(), Error> = proxy.method_call(AUDIO, "StartAudioListener", ());
|
||||||
conn
|
conn
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop_dbus_audio_listener(conn: Connection) {
|
fn stop_dbus_audio_listener(conn: Connection) {
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let _: Result<(), Error> = proxy.method_call(AUDIO, "StopAudioListener", ());
|
let _: Result<(), Error> = proxy.method_call(AUDIO, "StopAudioListener", ());
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
use adw::glib;
|
use adw::glib;
|
||||||
use adw::glib::Object;
|
use adw::glib::Object;
|
||||||
use adw::prelude::{ComboRowExt, ListModelExtManual, PreferencesGroupExt};
|
use adw::prelude::{ComboRowExt, PreferencesGroupExt};
|
||||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||||
use dbus::blocking::Connection;
|
use dbus::blocking::Connection;
|
||||||
use dbus::message::SignalArgs;
|
use dbus::message::SignalArgs;
|
||||||
|
@ -13,14 +13,14 @@ use dbus::{Error, Path};
|
||||||
use glib::{clone, Cast};
|
use glib::{clone, Cast};
|
||||||
use gtk::glib::Variant;
|
use gtk::glib::Variant;
|
||||||
use gtk::prelude::{ActionableExt, ButtonExt, ListBoxRowExt, WidgetExt};
|
use gtk::prelude::{ActionableExt, ButtonExt, ListBoxRowExt, WidgetExt};
|
||||||
use gtk::{gio, StringObject, Widget};
|
use gtk::{gio, StringObject};
|
||||||
use re_set_lib::bluetooth::bluetooth_structures::{BluetoothAdapter, BluetoothDevice};
|
use re_set_lib::bluetooth::bluetooth_structures::{BluetoothAdapter, BluetoothDevice};
|
||||||
use re_set_lib::signals::{BluetoothDeviceAdded, BluetoothDeviceChanged, BluetoothDeviceRemoved};
|
use re_set_lib::signals::{BluetoothDeviceAdded, BluetoothDeviceChanged, BluetoothDeviceRemoved};
|
||||||
|
|
||||||
use crate::components::base::utils::Listeners;
|
use crate::components::base::utils::Listeners;
|
||||||
use crate::components::bluetooth::bluetooth_box_impl;
|
use crate::components::bluetooth::bluetooth_box_impl;
|
||||||
use crate::components::bluetooth::bluetooth_entry::BluetoothEntry;
|
use crate::components::bluetooth::bluetooth_entry::BluetoothEntry;
|
||||||
use crate::components::utils::{DBUS_PATH, BASE, BLUETOOTH};
|
use crate::components::utils::{BASE, BLUETOOTH, DBUS_PATH};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct BluetoothBox(ObjectSubclass<bluetooth_box_impl::BluetoothBox>)
|
pub struct BluetoothBox(ObjectSubclass<bluetooth_box_impl::BluetoothBox>)
|
||||||
|
@ -82,17 +82,24 @@ fn setup_callbacks(
|
||||||
.connect_state_set(move |_, state| {
|
.connect_state_set(move |_, state| {
|
||||||
if !state {
|
if !state {
|
||||||
let imp = bluetooth_box_ref.imp();
|
let imp = bluetooth_box_ref.imp();
|
||||||
for x in imp
|
let mut available_devices = imp.available_devices.borrow_mut();
|
||||||
.reset_bluetooth_connected_devices
|
for entry in available_devices.iter() {
|
||||||
.observe_children()
|
imp.reset_bluetooth_available_devices.remove(&**entry.1);
|
||||||
.iter::<Object>()
|
|
||||||
.flatten()
|
|
||||||
{
|
|
||||||
// todo test this
|
|
||||||
if let Some(item) = x.downcast_ref::<Widget>() {
|
|
||||||
imp.reset_bluetooth_available_devices.remove(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
available_devices.clear();
|
||||||
|
|
||||||
|
let mut connected_devices = imp.connected_devices.borrow_mut();
|
||||||
|
for entry in connected_devices.iter() {
|
||||||
|
imp.reset_bluetooth_connected_devices.remove(&**entry.1);
|
||||||
|
}
|
||||||
|
connected_devices.clear();
|
||||||
|
|
||||||
|
imp.reset_bluetooth_pairable_switch.set_active(false);
|
||||||
|
imp.reset_bluetooth_pairable_switch.set_sensitive(false);
|
||||||
|
imp.reset_bluetooth_discoverable_switch.set_active(false);
|
||||||
|
imp.reset_bluetooth_discoverable_switch.set_sensitive(false);
|
||||||
|
imp.reset_bluetooth_refresh_button.set_sensitive(false);
|
||||||
|
|
||||||
listeners_ref
|
listeners_ref
|
||||||
.bluetooth_listener
|
.bluetooth_listener
|
||||||
.store(false, Ordering::SeqCst);
|
.store(false, Ordering::SeqCst);
|
||||||
|
@ -101,12 +108,26 @@ fn setup_callbacks(
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let imp = bluetooth_box_ref.imp();
|
let restart_ref = bluetooth_box_ref.clone();
|
||||||
set_adapter_enabled(
|
let restart_listener_ref = listeners_ref.clone();
|
||||||
imp.reset_current_bluetooth_adapter.borrow().path.clone(),
|
{
|
||||||
true,
|
let imp = bluetooth_box_ref.imp();
|
||||||
);
|
imp.reset_bluetooth_discoverable_switch.set_sensitive(true);
|
||||||
start_bluetooth_listener(listeners_ref.clone(), bluetooth_box_ref.clone());
|
imp.reset_bluetooth_pairable_switch.set_sensitive(true);
|
||||||
|
}
|
||||||
|
gio::spawn_blocking(move || {
|
||||||
|
if set_adapter_enabled(
|
||||||
|
restart_ref
|
||||||
|
.imp()
|
||||||
|
.reset_current_bluetooth_adapter
|
||||||
|
.borrow()
|
||||||
|
.path
|
||||||
|
.clone(),
|
||||||
|
true,
|
||||||
|
) {
|
||||||
|
start_bluetooth_listener(restart_listener_ref.clone(), restart_ref.clone());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
glib::Propagation::Proceed
|
glib::Propagation::Proceed
|
||||||
});
|
});
|
||||||
|
@ -151,14 +172,8 @@ pub fn populate_conntected_bluetooth_devices(bluetooth_box: Arc<BluetoothBox>) {
|
||||||
let current_adapter = imp.reset_current_bluetooth_adapter.borrow();
|
let current_adapter = imp.reset_current_bluetooth_adapter.borrow();
|
||||||
imp.reset_bluetooth_switch
|
imp.reset_bluetooth_switch
|
||||||
.set_state(current_adapter.powered);
|
.set_state(current_adapter.powered);
|
||||||
imp.reset_bluetooth_switch
|
|
||||||
.set_active(current_adapter.powered);
|
|
||||||
imp.reset_bluetooth_discoverable_switch
|
imp.reset_bluetooth_discoverable_switch
|
||||||
.set_active(current_adapter.discoverable);
|
.set_active(current_adapter.discoverable);
|
||||||
imp.reset_bluetooth_discoverable_switch
|
|
||||||
.set_active(current_adapter.discoverable);
|
|
||||||
imp.reset_bluetooth_pairable_switch
|
|
||||||
.set_active(current_adapter.pairable);
|
|
||||||
imp.reset_bluetooth_pairable_switch
|
imp.reset_bluetooth_pairable_switch
|
||||||
.set_active(current_adapter.pairable);
|
.set_active(current_adapter.pairable);
|
||||||
}
|
}
|
||||||
|
@ -207,28 +222,17 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
||||||
}
|
}
|
||||||
|
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let _: Result<(), Error> = proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
|
||||||
DBUS_PATH,
|
let device_added =
|
||||||
Duration::from_millis(1000),
|
BluetoothDeviceAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||||
);
|
.static_clone();
|
||||||
let _: Result<(), Error> =
|
let device_removed =
|
||||||
proxy.method_call(BLUETOOTH, "StartBluetoothListener", ());
|
BluetoothDeviceRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||||
let device_added = BluetoothDeviceAdded::match_rule(
|
.static_clone();
|
||||||
Some(&BASE.into()),
|
let device_changed =
|
||||||
Some(&Path::from(DBUS_PATH)),
|
BluetoothDeviceChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||||
)
|
.static_clone();
|
||||||
.static_clone();
|
|
||||||
let device_removed = BluetoothDeviceRemoved::match_rule(
|
|
||||||
Some(&BASE.into()),
|
|
||||||
Some(&Path::from(DBUS_PATH)),
|
|
||||||
)
|
|
||||||
.static_clone();
|
|
||||||
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_added_box = bluetooth_box.clone();
|
||||||
let device_removed_box = bluetooth_box.clone();
|
let device_removed_box = bluetooth_box.clone();
|
||||||
let device_changed_box = bluetooth_box.clone();
|
let device_changed_box = bluetooth_box.clone();
|
||||||
|
@ -347,8 +351,7 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
||||||
.set_sensitive(true);
|
.set_sensitive(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
let _: Result<(), Error> =
|
let _: Result<(), Error> = proxy.method_call(BLUETOOTH, "StopBluetoothScan", ());
|
||||||
proxy.method_call(BLUETOOTH, "StopBluetoothScan", ());
|
|
||||||
}
|
}
|
||||||
if !listener_active && listeners.bluetooth_scan_requested.load(Ordering::SeqCst) {
|
if !listener_active && listeners.bluetooth_scan_requested.load(Ordering::SeqCst) {
|
||||||
listeners
|
listeners
|
||||||
|
@ -366,16 +369,9 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
||||||
|
|
||||||
fn get_connected_devices() -> Vec<BluetoothDevice> {
|
fn get_connected_devices() -> Vec<BluetoothDevice> {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let res: Result<(Vec<BluetoothDevice>,), Error> =
|
||||||
DBUS_PATH,
|
proxy.method_call(BLUETOOTH, "GetConnectedBluetoothDevices", ());
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let res: Result<(Vec<BluetoothDevice>,), Error> = proxy.method_call(
|
|
||||||
BLUETOOTH,
|
|
||||||
"GetConnectedBluetoothDevices",
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
@ -384,11 +380,7 @@ fn get_connected_devices() -> Vec<BluetoothDevice> {
|
||||||
|
|
||||||
fn get_bluetooth_adapters() -> Vec<BluetoothAdapter> {
|
fn get_bluetooth_adapters() -> Vec<BluetoothAdapter> {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let res: Result<(Vec<BluetoothAdapter>,), Error> =
|
let res: Result<(Vec<BluetoothAdapter>,), Error> =
|
||||||
proxy.method_call(BLUETOOTH, "GetBluetoothAdapters", ());
|
proxy.method_call(BLUETOOTH, "GetBluetoothAdapters", ());
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
|
@ -399,22 +391,14 @@ fn get_bluetooth_adapters() -> Vec<BluetoothAdapter> {
|
||||||
|
|
||||||
fn set_bluetooth_adapter(path: Path<'static>) {
|
fn set_bluetooth_adapter(path: Path<'static>) {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let _: Result<(Path<'static>,), Error> =
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let _: Result<(Vec<BluetoothAdapter>,), Error> =
|
|
||||||
proxy.method_call(BLUETOOTH, "SetBluetoothAdapter", (path,));
|
proxy.method_call(BLUETOOTH, "SetBluetoothAdapter", (path,));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_bluetooth_adapter_visibility(path: Path<'static>, visible: bool) {
|
fn set_bluetooth_adapter_visibility(path: Path<'static>, visible: bool) {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let _: Result<(bool,), Error> = proxy.method_call(
|
let _: Result<(bool,), Error> = proxy.method_call(
|
||||||
BLUETOOTH,
|
BLUETOOTH,
|
||||||
"SetBluetoothAdapterDiscoverability",
|
"SetBluetoothAdapterDiscoverability",
|
||||||
|
@ -424,28 +408,18 @@ fn set_bluetooth_adapter_visibility(path: Path<'static>, visible: bool) {
|
||||||
|
|
||||||
fn set_bluetooth_adapter_pairability(path: Path<'static>, visible: bool) {
|
fn set_bluetooth_adapter_pairability(path: Path<'static>, visible: bool) {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let _: Result<(bool,), Error> =
|
||||||
DBUS_PATH,
|
proxy.method_call(BLUETOOTH, "SetBluetoothAdapterPairability", (path, visible));
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let _: Result<(bool,), Error> = proxy.method_call(
|
|
||||||
BLUETOOTH,
|
|
||||||
"SetBluetoothAdapterPairability",
|
|
||||||
(path, visible),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_adapter_enabled(path: Path<'static>, enabled: bool) {
|
fn set_adapter_enabled(path: Path<'static>, enabled: bool) -> bool {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let result: Result<(bool,), Error> =
|
||||||
DBUS_PATH,
|
proxy.method_call(BLUETOOTH, "SetBluetoothAdapterEnabled", (path, enabled));
|
||||||
Duration::from_millis(1000),
|
if result.is_err() {
|
||||||
);
|
return false;
|
||||||
let _: Result<(Vec<BluetoothAdapter>,), Error> = proxy.method_call(
|
}
|
||||||
BLUETOOTH,
|
result.unwrap().0
|
||||||
"SetBluetoothAdapterEnabled",
|
|
||||||
(path, enabled),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use adw::prelude::PreferencesRowExt;
|
use adw::prelude::PreferencesRowExt;
|
||||||
use re_set_lib::audio::audio_structures::{Card, OutputStream, Source};
|
use re_set_lib::audio::audio_structures::{Card, OutputStream, Source};
|
||||||
|
use re_set_lib::signals::{OutputStreamChanged, OutputStreamRemoved, OutputStreamAdded, SourceChanged, SourceRemoved, SourceAdded};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
|
@ -18,10 +19,6 @@ use gtk::{gio, StringObject};
|
||||||
|
|
||||||
use crate::components::base::card_entry::CardEntry;
|
use crate::components::base::card_entry::CardEntry;
|
||||||
use crate::components::base::list_entry::ListEntry;
|
use crate::components::base::list_entry::ListEntry;
|
||||||
use crate::components::base::utils::{
|
|
||||||
OutputStreamAdded, OutputStreamChanged, OutputStreamRemoved, SourceAdded, SourceChanged,
|
|
||||||
SourceRemoved,
|
|
||||||
};
|
|
||||||
use crate::components::input::source_box_impl;
|
use crate::components::input::source_box_impl;
|
||||||
use crate::components::input::source_entry::set_source_volume;
|
use crate::components::input::source_entry::set_source_volume;
|
||||||
use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis, BASE, DBUS_PATH, AUDIO};
|
use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis, BASE, DBUS_PATH, AUDIO};
|
||||||
|
|
|
@ -3,6 +3,12 @@ use adw::prelude::PreferencesRowExt;
|
||||||
use re_set_lib::audio::audio_structures::Card;
|
use re_set_lib::audio::audio_structures::Card;
|
||||||
use re_set_lib::audio::audio_structures::InputStream;
|
use re_set_lib::audio::audio_structures::InputStream;
|
||||||
use re_set_lib::audio::audio_structures::Sink;
|
use re_set_lib::audio::audio_structures::Sink;
|
||||||
|
use re_set_lib::signals::InputStreamAdded;
|
||||||
|
use re_set_lib::signals::InputStreamChanged;
|
||||||
|
use re_set_lib::signals::InputStreamRemoved;
|
||||||
|
use re_set_lib::signals::SinkAdded;
|
||||||
|
use re_set_lib::signals::SinkChanged;
|
||||||
|
use re_set_lib::signals::SinkRemoved;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
|
@ -19,9 +25,6 @@ use gtk::{gio, StringObject};
|
||||||
|
|
||||||
use crate::components::base::card_entry::CardEntry;
|
use crate::components::base::card_entry::CardEntry;
|
||||||
use crate::components::base::list_entry::ListEntry;
|
use crate::components::base::list_entry::ListEntry;
|
||||||
use crate::components::base::utils::{
|
|
||||||
InputStreamAdded, InputStreamChanged, InputStreamRemoved, SinkAdded, SinkChanged, SinkRemoved,
|
|
||||||
};
|
|
||||||
use crate::components::output::sink_entry::set_sink_volume;
|
use crate::components::output::sink_entry::set_sink_volume;
|
||||||
use crate::components::utils::AUDIO;
|
use crate::components::utils::AUDIO;
|
||||||
use crate::components::utils::BASE;
|
use crate::components::utils::BASE;
|
||||||
|
@ -312,13 +315,8 @@ pub fn populate_cards(output_box: Arc<SinkBox>) {
|
||||||
|
|
||||||
fn get_input_streams() -> Vec<InputStream> {
|
fn get_input_streams() -> Vec<InputStream> {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let res: Result<(Vec<InputStream>,), Error> = proxy.method_call(AUDIO, "ListInputStreams", ());
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let res: Result<(Vec<InputStream>,), Error> =
|
|
||||||
proxy.method_call(AUDIO, "ListInputStreams", ());
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
@ -327,13 +325,8 @@ fn get_input_streams() -> Vec<InputStream> {
|
||||||
|
|
||||||
fn get_sinks() -> Vec<Sink> {
|
fn get_sinks() -> Vec<Sink> {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let res: Result<(Vec<Sink>,), Error> = proxy.method_call(AUDIO, "ListSinks", ());
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let res: Result<(Vec<Sink>,), Error> =
|
|
||||||
proxy.method_call(AUDIO, "ListSinks", ());
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
@ -342,13 +335,8 @@ fn get_sinks() -> Vec<Sink> {
|
||||||
|
|
||||||
fn get_cards() -> Vec<Card> {
|
fn get_cards() -> Vec<Card> {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let res: Result<(Vec<Card>,), Error> = proxy.method_call(AUDIO, "ListCards", ());
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let res: Result<(Vec<Card>,), Error> =
|
|
||||||
proxy.method_call(AUDIO, "ListCards", ());
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
@ -357,13 +345,8 @@ fn get_cards() -> Vec<Card> {
|
||||||
|
|
||||||
fn get_default_sink_name() -> String {
|
fn get_default_sink_name() -> String {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let res: Result<(String,), Error> = proxy.method_call(AUDIO, "GetDefaultSinkName", ());
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let res: Result<(String,), Error> =
|
|
||||||
proxy.method_call(AUDIO, "GetDefaultSinkName", ());
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
return String::from("");
|
return String::from("");
|
||||||
}
|
}
|
||||||
|
@ -372,13 +355,8 @@ fn get_default_sink_name() -> String {
|
||||||
|
|
||||||
fn get_default_sink() -> Sink {
|
fn get_default_sink() -> Sink {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
BASE,
|
let res: Result<(Sink,), Error> = proxy.method_call(AUDIO, "GetDefaultSink", ());
|
||||||
DBUS_PATH,
|
|
||||||
Duration::from_millis(1000),
|
|
||||||
);
|
|
||||||
let res: Result<(Sink,), Error> =
|
|
||||||
proxy.method_call(AUDIO, "GetDefaultSink", ());
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
return Sink::default();
|
return Sink::default();
|
||||||
}
|
}
|
||||||
|
@ -386,36 +364,21 @@ fn get_default_sink() -> Sink {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_output_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Connection {
|
pub fn start_output_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Connection {
|
||||||
let sink_added = SinkAdded::match_rule(
|
let sink_added =
|
||||||
Some(&BASE.into()),
|
SinkAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||||
Some(&Path::from(DBUS_PATH)),
|
let sink_removed =
|
||||||
)
|
SinkRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||||
.static_clone();
|
let sink_changed =
|
||||||
let sink_removed = SinkRemoved::match_rule(
|
SinkChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||||
Some(&BASE.into()),
|
let input_stream_added =
|
||||||
Some(&Path::from(DBUS_PATH)),
|
InputStreamAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||||
)
|
.static_clone();
|
||||||
.static_clone();
|
let input_stream_removed =
|
||||||
let sink_changed = SinkChanged::match_rule(
|
InputStreamRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||||
Some(&BASE.into()),
|
.static_clone();
|
||||||
Some(&Path::from(DBUS_PATH)),
|
let input_stream_changed =
|
||||||
)
|
InputStreamChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||||
.static_clone();
|
.static_clone();
|
||||||
let input_stream_added = InputStreamAdded::match_rule(
|
|
||||||
Some(&BASE.into()),
|
|
||||||
Some(&Path::from(DBUS_PATH)),
|
|
||||||
)
|
|
||||||
.static_clone();
|
|
||||||
let input_stream_removed = InputStreamRemoved::match_rule(
|
|
||||||
Some(&BASE.into()),
|
|
||||||
Some(&Path::from(DBUS_PATH)),
|
|
||||||
)
|
|
||||||
.static_clone();
|
|
||||||
let input_stream_changed = InputStreamChanged::match_rule(
|
|
||||||
Some(&BASE.into()),
|
|
||||||
Some(&Path::from(DBUS_PATH)),
|
|
||||||
)
|
|
||||||
.static_clone();
|
|
||||||
|
|
||||||
let sink_added_box = sink_box.clone();
|
let sink_added_box = sink_box.clone();
|
||||||
let sink_removed_box = sink_box.clone();
|
let sink_removed_box = sink_box.clone();
|
||||||
|
|
|
@ -19,7 +19,7 @@ use gtk::glib::Variant;
|
||||||
use gtk::prelude::{ActionableExt, WidgetExt};
|
use gtk::prelude::{ActionableExt, WidgetExt};
|
||||||
use gtk::{gio, StringList, StringObject};
|
use gtk::{gio, StringList, StringObject};
|
||||||
use re_set_lib::network::network_structures::{AccessPoint, WifiDevice, WifiStrength};
|
use re_set_lib::network::network_structures::{AccessPoint, WifiDevice, WifiStrength};
|
||||||
use re_set_lib::signals::{AccessPointAdded, WifiDeviceChanged};
|
use re_set_lib::signals::{AccessPointAdded, WifiDeviceChanged, WifiDeviceReset};
|
||||||
use re_set_lib::signals::{AccessPointChanged, AccessPointRemoved};
|
use re_set_lib::signals::{AccessPointChanged, AccessPointRemoved};
|
||||||
|
|
||||||
use crate::components::wifi::wifi_box_impl;
|
use crate::components::wifi::wifi_box_impl;
|
||||||
|
@ -265,6 +265,7 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
||||||
let removed_ref = wifi_box.clone();
|
let removed_ref = wifi_box.clone();
|
||||||
let changed_ref = wifi_box.clone();
|
let changed_ref = wifi_box.clone();
|
||||||
let wifi_changed_ref = wifi_box.clone();
|
let wifi_changed_ref = wifi_box.clone();
|
||||||
|
let wifi_reset_ref = wifi_box.clone();
|
||||||
let access_point_added =
|
let access_point_added =
|
||||||
AccessPointAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
AccessPointAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||||
.static_clone();
|
.static_clone();
|
||||||
|
@ -277,6 +278,9 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
||||||
let device_changed =
|
let device_changed =
|
||||||
WifiDeviceChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
WifiDeviceChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||||
.static_clone();
|
.static_clone();
|
||||||
|
let devices_reset =
|
||||||
|
WifiDeviceReset::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||||
|
.static_clone();
|
||||||
let res = conn.add_match(access_point_added, move |ir: AccessPointAdded, _, _| {
|
let res = conn.add_match(access_point_added, move |ir: AccessPointAdded, _, _| {
|
||||||
let wifi_box = added_ref.clone();
|
let wifi_box = added_ref.clone();
|
||||||
glib::spawn_future(async move {
|
glib::spawn_future(async move {
|
||||||
|
@ -414,6 +418,44 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
||||||
println!("fail on wifi device change event");
|
println!("fail on wifi device change event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let res = conn.add_match(devices_reset, move |ir: WifiDeviceReset, _, _| {
|
||||||
|
if ir.devices.is_empty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let imp = wifi_reset_ref.imp();
|
||||||
|
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();
|
||||||
|
imp.reset_current_wifi_device
|
||||||
|
.replace(ir.devices.last().unwrap().clone());
|
||||||
|
for (index, device) in ir.devices.into_iter().enumerate() {
|
||||||
|
list.append(&device.name);
|
||||||
|
map.insert(device.name.clone(), (device, index as u32));
|
||||||
|
*model_index += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let wifi_box = wifi_reset_ref.clone();
|
||||||
|
glib::spawn_future(async move {
|
||||||
|
glib::idle_add_once(move || {
|
||||||
|
let imp = wifi_box.imp();
|
||||||
|
let list = imp.reset_model_list.read().unwrap();
|
||||||
|
imp.reset_wifi_device.set_model(Some(&*list));
|
||||||
|
let map = imp.reset_wifi_devices.read().unwrap();
|
||||||
|
{
|
||||||
|
let device = imp.reset_current_wifi_device.borrow();
|
||||||
|
if let Some(index) = map.get(&device.name) {
|
||||||
|
imp.reset_wifi_device.set_selected(index.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
true
|
||||||
|
});
|
||||||
|
if res.is_err() {
|
||||||
|
println!("fail on wifi device change event");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let _ = conn.process(Duration::from_millis(1000));
|
let _ = conn.process(Duration::from_millis(1000));
|
||||||
|
|
|
@ -33,7 +33,6 @@ pub struct WifiBox {
|
||||||
pub reset_available_networks: TemplateChild<ActionRow>,
|
pub reset_available_networks: TemplateChild<ActionRow>,
|
||||||
pub wifi_entries: Arc<Mutex<HashMap<Vec<u8>, Arc<WifiEntry>>>>,
|
pub wifi_entries: Arc<Mutex<HashMap<Vec<u8>, Arc<WifiEntry>>>>,
|
||||||
pub wifi_entries_path: Arc<Mutex<HashMap<Path<'static>, Arc<WifiEntry>>>>,
|
pub wifi_entries_path: Arc<Mutex<HashMap<Path<'static>, Arc<WifiEntry>>>>,
|
||||||
pub saved_wifi_entries: Arc<Mutex<Vec<ListEntry>>>,
|
|
||||||
pub reset_wifi_devices: Arc<RwLock<HashMap<String, (WifiDevice, u32)>>>,
|
pub reset_wifi_devices: Arc<RwLock<HashMap<String, (WifiDevice, u32)>>>,
|
||||||
pub reset_current_wifi_device: Arc<RefCell<WifiDevice>>,
|
pub reset_current_wifi_device: Arc<RefCell<WifiDevice>>,
|
||||||
pub reset_model_list: Arc<RwLock<StringList>>,
|
pub reset_model_list: Arc<RwLock<StringList>>,
|
||||||
|
|
Loading…
Reference in a new issue