mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-12 12:57:44 +02:00
fix: Don't lock UI when turning all audio devices off
This commit is contained in:
parent
7635c96d9f
commit
37742471f4
19 changed files with 474 additions and 298 deletions
|
@ -296,11 +296,11 @@ pub fn start_bluetooth_listener(listeners: Arc<Listeners>, bluetooth_box: Arc<Bl
|
|||
list_entry.imp().bluetooth_device.borrow_mut();
|
||||
if existing_bluetooth_device.connected != ir.bluetooth_device.connected {
|
||||
if ir.bluetooth_device.connected {
|
||||
imp.reset_bluetooth_connected_devices.add(&**list_entry);
|
||||
imp.reset_bluetooth_available_devices.remove(&**list_entry);
|
||||
imp.reset_bluetooth_connected_devices.add(&**list_entry);
|
||||
} else {
|
||||
imp.reset_bluetooth_available_devices.add(&**list_entry);
|
||||
imp.reset_bluetooth_connected_devices.remove(&**list_entry);
|
||||
imp.reset_bluetooth_available_devices.add(&**list_entry);
|
||||
}
|
||||
}
|
||||
if existing_bluetooth_device.bonded != ir.bluetooth_device.bonded {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
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, AUDIO, BASE, DBUS_PATH,
|
||||
};
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ButtonExt, ComboRowExt, PreferencesRowExt, RangeExt};
|
||||
|
@ -29,6 +31,7 @@ impl OutputStreamEntry {
|
|||
let obj: Self = Object::builder().build();
|
||||
// TODO use event callback for progress bar -> this is the "im speaking" indicator
|
||||
{
|
||||
let index = stream.index;
|
||||
let box_imp = source_box.imp();
|
||||
let imp = obj.imp();
|
||||
let name = stream.application_name.clone() + ": " + stream.name.as_str();
|
||||
|
@ -70,16 +73,27 @@ impl OutputStreamEntry {
|
|||
{
|
||||
let list = box_imp.reset_model_list.read().unwrap();
|
||||
imp.reset_source_selection.set_model(Some(&*list));
|
||||
let map = box_imp.reset_source_map.write().unwrap();
|
||||
let mut name = box_imp.reset_default_source.try_borrow();
|
||||
while name.is_err() {
|
||||
name = box_imp.reset_default_source.try_borrow();
|
||||
}
|
||||
let name = name.unwrap();
|
||||
let name = &name.alias;
|
||||
let index = map.get(name);
|
||||
if let Some(index) = index {
|
||||
imp.reset_source_selection.set_selected(index.1);
|
||||
let source_list = box_imp.reset_source_list.read().unwrap();
|
||||
let name = source_list.get(&index);
|
||||
let index = box_imp.reset_model_index.read().unwrap();
|
||||
let model_list = box_imp.reset_model_list.read().unwrap();
|
||||
if let Some(name) = name {
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(name.2.clone().into()) {
|
||||
imp.reset_source_selection.set_selected(entry);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut name = box_imp.reset_default_source.try_borrow();
|
||||
while name.is_err() {
|
||||
name = box_imp.reset_default_source.try_borrow();
|
||||
}
|
||||
let name = name.unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(name.alias.clone().into()) {
|
||||
imp.reset_source_selection.set_selected(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
imp.reset_source_selection.connect_selected_notify(
|
||||
|
@ -133,11 +147,7 @@ impl OutputStreamEntry {
|
|||
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(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let _: Result<(), Error> = proxy.method_call(
|
||||
AUDIO,
|
||||
"SetOutputStreamVolume",
|
||||
|
@ -154,16 +164,8 @@ fn set_outputstream_volume(value: f64, index: u32, channels: u16) -> bool {
|
|||
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(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(), Error> = proxy.method_call(
|
||||
AUDIO,
|
||||
"SetOutputStreamMute",
|
||||
(index, muted),
|
||||
);
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let _: Result<(), Error> = proxy.method_call(AUDIO, "SetOutputStreamMute", (index, muted));
|
||||
// if res.is_err() {
|
||||
// return false;
|
||||
// }
|
||||
|
@ -175,16 +177,9 @@ fn toggle_output_stream_mute(index: u32, muted: bool) -> bool {
|
|||
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(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(bool,), Error> = proxy.method_call(
|
||||
AUDIO,
|
||||
"SetSourceOfOutputStream",
|
||||
(stream, source),
|
||||
);
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let _: Result<(bool,), Error> =
|
||||
proxy.method_call(AUDIO, "SetSourceOfOutputStream", (stream, source));
|
||||
// if res.is_err() {
|
||||
// return false;
|
||||
// }
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use adw::prelude::PreferencesRowExt;
|
||||
use re_set_lib::audio::audio_structures::{Card, OutputStream, Source};
|
||||
use re_set_lib::signals::{OutputStreamChanged, OutputStreamRemoved, OutputStreamAdded, SourceChanged, SourceRemoved, SourceAdded};
|
||||
use re_set_lib::signals::{
|
||||
OutputStreamAdded, OutputStreamChanged, OutputStreamRemoved, SourceAdded, SourceChanged,
|
||||
SourceRemoved,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
|
@ -21,7 +24,9 @@ use crate::components::base::card_entry::CardEntry;
|
|||
use crate::components::base::list_entry::ListEntry;
|
||||
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, BASE, DBUS_PATH, AUDIO};
|
||||
use crate::components::utils::{
|
||||
create_dropdown_label_factory, set_combo_row_ellipsis, AUDIO, BASE, DBUS_PATH,
|
||||
};
|
||||
|
||||
use super::output_stream_entry::OutputStreamEntry;
|
||||
use super::source_entry::{set_default_source, toggle_source_mute, SourceEntry};
|
||||
|
@ -97,9 +102,9 @@ pub fn populate_sources(input_box: Arc<SourceBox>) {
|
|||
input_box_imp
|
||||
.reset_default_source
|
||||
.replace(get_default_source());
|
||||
for (i, source) in (0_u32..).zip(sources.iter()) {
|
||||
for source in sources.iter() {
|
||||
list.append(&source.alias);
|
||||
map.insert(source.alias.clone(), (source.index, i, source.name.clone()));
|
||||
map.insert(source.alias.clone(), (source.index, source.name.clone()));
|
||||
*model_index += 1;
|
||||
}
|
||||
}
|
||||
|
@ -154,10 +159,14 @@ pub fn populate_sources(input_box: Arc<SourceBox>) {
|
|||
}
|
||||
let list = input_box_imp.reset_model_list.read().unwrap();
|
||||
input_box_imp.reset_source_dropdown.set_model(Some(&*list));
|
||||
let map = input_box_imp.reset_source_map.read().unwrap();
|
||||
let name = input_box_imp.reset_default_source.borrow();
|
||||
if let Some(index) = map.get(&name.alias) {
|
||||
input_box_imp.reset_source_dropdown.set_selected(index.1);
|
||||
|
||||
let index = input_box_imp.reset_model_index.read().unwrap();
|
||||
let model_list = input_box_imp.reset_model_list.read().unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(name.alias.clone().into()) {
|
||||
input_box_imp.reset_source_dropdown.set_selected(entry);
|
||||
}
|
||||
}
|
||||
input_box_imp.reset_source_dropdown.connect_selected_notify(
|
||||
clone!(@weak input_box_imp => move |dropdown| {
|
||||
|
@ -175,7 +184,7 @@ pub fn populate_sources(input_box: Arc<SourceBox>) {
|
|||
if source.is_none() {
|
||||
return;
|
||||
}
|
||||
let source = Arc::new(source.unwrap().2.clone());
|
||||
let source = Arc::new(source.unwrap().1.clone());
|
||||
gio::spawn_blocking(move || {
|
||||
let result = set_default_source(source);
|
||||
if result.is_none(){
|
||||
|
@ -247,12 +256,12 @@ pub fn refresh_default_source(new_source: Source, input_box: Arc<SourceBox>, ent
|
|||
let entry_imp = entry.unwrap().1.imp();
|
||||
entry_imp.reset_selected_source.set_active(true);
|
||||
} else {
|
||||
let map = imp.reset_source_map.read().unwrap();
|
||||
let entry = map.get(&new_source.alias);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
let model_list = imp.reset_model_list.read().unwrap();
|
||||
for entry in 0..*imp.reset_model_index.read().unwrap() {
|
||||
if model_list.string(entry) == Some(new_source.alias.clone().into()) {
|
||||
imp.reset_source_dropdown.set_selected(entry);
|
||||
}
|
||||
}
|
||||
imp.reset_source_dropdown.set_selected(entry.unwrap().1);
|
||||
}
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(volume as f64);
|
||||
|
@ -308,11 +317,7 @@ pub fn populate_cards(input_box: Arc<SourceBox>) {
|
|||
|
||||
fn get_output_streams() -> Vec<OutputStream> {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(Vec<OutputStream>,), Error> =
|
||||
proxy.method_call(AUDIO, "ListOutputStreams", ());
|
||||
if res.is_err() {
|
||||
|
@ -323,13 +328,8 @@ fn get_output_streams() -> Vec<OutputStream> {
|
|||
|
||||
fn get_sources() -> Vec<Source> {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let res: Result<(Vec<Source>,), Error> =
|
||||
proxy.method_call(AUDIO, "ListSources", ());
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(Vec<Source>,), Error> = proxy.method_call(AUDIO, "ListSources", ());
|
||||
if res.is_err() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
@ -338,13 +338,8 @@ fn get_sources() -> Vec<Source> {
|
|||
|
||||
fn get_cards() -> Vec<Card> {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let res: Result<(Vec<Card>,), Error> =
|
||||
proxy.method_call(AUDIO, "ListCards", ());
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(Vec<Card>,), Error> = proxy.method_call(AUDIO, "ListCards", ());
|
||||
if res.is_err() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
@ -353,13 +348,8 @@ fn get_cards() -> Vec<Card> {
|
|||
|
||||
fn get_default_source_name() -> String {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let res: Result<(String,), Error> =
|
||||
proxy.method_call(AUDIO, "GetDefaultSourceName", ());
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(String,), Error> = proxy.method_call(AUDIO, "GetDefaultSourceName", ());
|
||||
if res.is_err() {
|
||||
return String::from("");
|
||||
}
|
||||
|
@ -368,13 +358,8 @@ fn get_default_source_name() -> String {
|
|||
|
||||
fn get_default_source() -> Source {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let res: Result<(Source,), Error> =
|
||||
proxy.method_call(AUDIO, "GetDefaultSource", ());
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(Source,), Error> = proxy.method_call(AUDIO, "GetDefaultSource", ());
|
||||
if res.is_err() {
|
||||
return Source::default();
|
||||
}
|
||||
|
@ -382,36 +367,21 @@ fn get_default_source() -> Source {
|
|||
}
|
||||
|
||||
pub fn start_input_box_listener(conn: Connection, source_box: Arc<SourceBox>) -> Connection {
|
||||
let source_added = SourceAdded::match_rule(
|
||||
Some(&BASE.into()),
|
||||
Some(&Path::from(DBUS_PATH)),
|
||||
)
|
||||
.static_clone();
|
||||
let source_removed = SourceRemoved::match_rule(
|
||||
Some(&BASE.into()),
|
||||
Some(&Path::from(DBUS_PATH)),
|
||||
)
|
||||
.static_clone();
|
||||
let source_changed = SourceChanged::match_rule(
|
||||
Some(&BASE.into()),
|
||||
Some(&Path::from(DBUS_PATH)),
|
||||
)
|
||||
.static_clone();
|
||||
let output_stream_added = OutputStreamAdded::match_rule(
|
||||
Some(&BASE.into()),
|
||||
Some(&Path::from(DBUS_PATH)),
|
||||
)
|
||||
.static_clone();
|
||||
let output_stream_removed = OutputStreamRemoved::match_rule(
|
||||
Some(&BASE.into()),
|
||||
Some(&Path::from(DBUS_PATH)),
|
||||
)
|
||||
.static_clone();
|
||||
let output_stream_changed = OutputStreamChanged::match_rule(
|
||||
Some(&BASE.into()),
|
||||
Some(&Path::from(DBUS_PATH)),
|
||||
)
|
||||
.static_clone();
|
||||
let source_added =
|
||||
SourceAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||
let source_removed =
|
||||
SourceRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||
let source_changed =
|
||||
SourceChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||
let output_stream_added =
|
||||
OutputStreamAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
let output_stream_removed =
|
||||
OutputStreamRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
let output_stream_changed =
|
||||
OutputStreamChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
|
||||
let source_added_box = source_box.clone();
|
||||
let source_removed_box = source_box.clone();
|
||||
|
@ -426,7 +396,6 @@ pub fn start_input_box_listener(conn: Connection, source_box: Arc<SourceBox>) ->
|
|||
glib::idle_add_once(move || {
|
||||
let input_box = source_box.clone();
|
||||
let input_box_imp = input_box.imp();
|
||||
let mut list = input_box_imp.reset_source_list.write().unwrap();
|
||||
let source_index = ir.source.index;
|
||||
let alias = ir.source.alias.clone();
|
||||
let name = ir.source.name.clone();
|
||||
|
@ -443,17 +412,25 @@ pub fn start_input_box_listener(conn: Connection, source_box: Arc<SourceBox>) ->
|
|||
let source_clone = source_entry.clone();
|
||||
let entry = Arc::new(ListEntry::new(&*source_entry));
|
||||
entry.set_activatable(false);
|
||||
let mut list = input_box_imp.reset_source_list.write().unwrap();
|
||||
list.insert(source_index, (entry.clone(), source_clone, alias.clone()));
|
||||
input_box_imp.reset_sources.append(&*entry);
|
||||
let mut map = input_box_imp.reset_source_map.write().unwrap();
|
||||
let mut index = input_box_imp.reset_model_index.write().unwrap();
|
||||
input_box_imp
|
||||
.reset_model_list
|
||||
.write()
|
||||
.unwrap()
|
||||
.append(&alias);
|
||||
map.insert(alias, (source_index, *index, name));
|
||||
*index += 1;
|
||||
let model_list = input_box_imp.reset_model_list.write().unwrap();
|
||||
model_list.append(&alias);
|
||||
if model_list.string(*index - 1) == Some("Monitor of Dummy Output".into()) {
|
||||
if alias == "Monitor of Dummy Output" {
|
||||
return;
|
||||
}
|
||||
model_list.append(&alias);
|
||||
model_list.remove(*index - 1);
|
||||
map.insert(alias, (source_index, name));
|
||||
} else {
|
||||
model_list.append(&alias);
|
||||
map.insert(alias, (source_index, name));
|
||||
*index += 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
|
@ -469,25 +446,32 @@ pub fn start_input_box_listener(conn: Connection, source_box: Arc<SourceBox>) ->
|
|||
glib::idle_add_once(move || {
|
||||
let input_box = source_box.clone();
|
||||
let input_box_imp = input_box.imp();
|
||||
let mut list = input_box_imp.reset_source_list.write().unwrap();
|
||||
let entry = list.remove(&ir.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
let entry: Option<(Arc<ListEntry>, Arc<SourceEntry>, String)>;
|
||||
{
|
||||
let mut list = input_box_imp.reset_source_list.write().unwrap();
|
||||
entry = list.remove(&ir.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
input_box_imp
|
||||
.reset_sources
|
||||
.remove(&*entry.clone().unwrap().0);
|
||||
let mut map = input_box_imp.reset_source_map.write().unwrap();
|
||||
let entry_index = map.remove(&entry.unwrap().2);
|
||||
if let Some(entry_index) = entry_index {
|
||||
input_box_imp
|
||||
.reset_model_list
|
||||
.write()
|
||||
.unwrap()
|
||||
.remove(entry_index.1);
|
||||
}
|
||||
let alias = entry.unwrap().2;
|
||||
map.remove(&alias);
|
||||
let mut index = input_box_imp.reset_model_index.write().unwrap();
|
||||
if *index != 0 {
|
||||
let model_list = input_box_imp.reset_model_list.write().unwrap();
|
||||
|
||||
if *index == 1 {
|
||||
model_list.append("Monitor of Dummy Output");
|
||||
}
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(alias.clone().into()) {
|
||||
model_list.remove(entry);
|
||||
}
|
||||
}
|
||||
if *index > 1 {
|
||||
*index -= 1;
|
||||
}
|
||||
});
|
||||
|
@ -620,9 +604,12 @@ pub fn start_input_box_listener(conn: Connection, source_box: Arc<SourceBox>) ->
|
|||
let percentage = (fraction).to_string() + "%";
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(*volume as f64);
|
||||
let map = input_box_imp.reset_source_map.read().unwrap();
|
||||
if let Some(index) = map.get(&alias) {
|
||||
imp.reset_source_selection.set_selected(index.1);
|
||||
let index = input_box_imp.reset_model_index.read().unwrap();
|
||||
let model_list = input_box_imp.reset_model_list.read().unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(alias.clone().into()) {
|
||||
imp.reset_source_selection.set_selected(entry);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,7 +16,8 @@ use super::source_entry::SourceEntry;
|
|||
|
||||
type SourceEntryMap = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<SourceEntry>, String)>>>;
|
||||
type OutputStreamEntryMap = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<OutputStreamEntry>)>>>;
|
||||
type SourceMap = Arc<RwLock<HashMap<String, (u32, u32, String)>>>;
|
||||
// the key is the alias, the first value u32 is the index of the source, the second is the technical name
|
||||
type SourceMap = Arc<RwLock<HashMap<String, (u32, String)>>>;
|
||||
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
#[template(resource = "/org/Xetibo/ReSet/resetAudioInput.ui")]
|
||||
|
@ -50,8 +51,6 @@ pub struct SourceBox {
|
|||
pub reset_output_stream_list: OutputStreamEntryMap,
|
||||
pub reset_model_list: Arc<RwLock<StringList>>,
|
||||
pub reset_model_index: Arc<RwLock<u32>>,
|
||||
// first u32 is the index of the source, the second the index in the model list and the third is
|
||||
// the full name
|
||||
pub reset_source_map: SourceMap,
|
||||
pub volume_time_stamp: RefCell<Option<SystemTime>>,
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
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, AUDIO, BASE, DBUS_PATH,
|
||||
};
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ButtonExt, ComboRowExt, PreferencesRowExt, RangeExt};
|
||||
|
@ -79,29 +81,27 @@ impl InputStreamEntry {
|
|||
);
|
||||
{
|
||||
let list = box_imp.reset_model_list.read().unwrap();
|
||||
// while list.is_err() {
|
||||
// list = box_imp.resetModelList.try_borrow();
|
||||
// }
|
||||
// let list = list.unwrap();
|
||||
imp.reset_sink_selection.set_model(Some(&*list));
|
||||
let map = box_imp.reset_sink_map.read().unwrap();
|
||||
let sink_list = box_imp.reset_sink_list.read().unwrap();
|
||||
let name = sink_list.get(&index);
|
||||
let index = box_imp.reset_model_index.read().unwrap();
|
||||
let model_list = box_imp.reset_model_list.read().unwrap();
|
||||
if let Some(name) = name {
|
||||
let name = &name.2;
|
||||
let index = map.get(name);
|
||||
if let Some(index) = index {
|
||||
imp.reset_sink_selection.set_selected(index.1);
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(name.2.clone().into()) {
|
||||
imp.reset_sink_selection.set_selected(entry);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut name = box_imp.reset_default_sink.try_borrow();
|
||||
while name.is_err() {
|
||||
name = box_imp.reset_default_sink.try_borrow();
|
||||
}
|
||||
let name = &name.unwrap().alias;
|
||||
let index = map.get(name);
|
||||
if let Some(index) = index {
|
||||
imp.reset_sink_selection.set_selected(index.1);
|
||||
let name = name.unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(name.alias.clone().into()) {
|
||||
imp.reset_sink_selection.set_selected(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,11 +160,7 @@ impl InputStreamEntry {
|
|||
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(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let _: Result<(), Error> = proxy.method_call(
|
||||
AUDIO,
|
||||
"SetInputStreamVolume",
|
||||
|
@ -181,16 +177,8 @@ fn set_inputstream_volume(value: f64, index: u32, channels: u16) -> bool {
|
|||
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(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(), Error> = proxy.method_call(
|
||||
AUDIO,
|
||||
"SetInputStreamMute",
|
||||
(index, muted),
|
||||
);
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let _: Result<(), Error> = proxy.method_call(AUDIO, "SetInputStreamMute", (index, muted));
|
||||
// if res.is_err() {
|
||||
// return false;
|
||||
// }
|
||||
|
@ -202,16 +190,8 @@ fn toggle_input_stream_mute(index: u32, muted: bool) -> bool {
|
|||
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(
|
||||
BASE,
|
||||
DBUS_PATH,
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let _: Result<(), Error> = proxy.method_call(
|
||||
AUDIO,
|
||||
"SetSinkOfInputStream",
|
||||
(stream, sink),
|
||||
);
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let _: Result<(), Error> = proxy.method_call(AUDIO, "SetSinkOfInputStream", (stream, sink));
|
||||
// if res.is_err() {
|
||||
// return false;
|
||||
// }
|
||||
|
|
|
@ -106,9 +106,9 @@ pub fn populate_sinks(output_box: Arc<SinkBox>) {
|
|||
output_box_imp
|
||||
.reset_default_sink
|
||||
.replace(get_default_sink());
|
||||
for (i, sink) in (0_u32..).zip(sinks.iter()) {
|
||||
for sink in sinks.iter() {
|
||||
list.append(&sink.alias);
|
||||
map.insert(sink.alias.clone(), (sink.index, i, sink.name.clone()));
|
||||
map.insert(sink.alias.clone(), (sink.index, sink.name.clone()));
|
||||
*model_index += 1;
|
||||
}
|
||||
}
|
||||
|
@ -164,8 +164,13 @@ pub fn populate_sinks(output_box: Arc<SinkBox>) {
|
|||
output_box_imp.reset_sink_dropdown.set_model(Some(&*list));
|
||||
let map = output_box_imp.reset_sink_map.read().unwrap();
|
||||
let name = output_box_imp.reset_default_sink.borrow();
|
||||
if let Some(index) = map.get(&name.alias) {
|
||||
output_box_imp.reset_sink_dropdown.set_selected(index.1);
|
||||
|
||||
let index = output_box_imp.reset_model_index.read().unwrap();
|
||||
let model_list = output_box_imp.reset_model_list.read().unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(name.alias.clone().into()) {
|
||||
output_box_imp.reset_sink_dropdown.set_selected(entry);
|
||||
}
|
||||
}
|
||||
output_box_imp.reset_sink_dropdown.connect_selected_notify(
|
||||
clone!(@weak output_box_imp => move |dropdown| {
|
||||
|
@ -183,7 +188,7 @@ pub fn populate_sinks(output_box: Arc<SinkBox>) {
|
|||
if sink.is_none() {
|
||||
return;
|
||||
}
|
||||
let new_sink_name = Arc::new(sink.unwrap().2.clone());
|
||||
let new_sink_name = Arc::new(sink.unwrap().1.clone());
|
||||
gio::spawn_blocking(move || {
|
||||
let result = set_default_sink(new_sink_name);
|
||||
if result.is_none() {
|
||||
|
@ -255,12 +260,13 @@ pub fn refresh_default_sink(new_sink: Sink, output_box: Arc<SinkBox>, entry: boo
|
|||
let entry_imp = entry.unwrap().1.imp();
|
||||
entry_imp.reset_selected_sink.set_active(true);
|
||||
} else {
|
||||
let map = imp.reset_sink_map.read().unwrap();
|
||||
let entry = map.get(&new_sink.alias);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
let index = imp.reset_model_index.read().unwrap();
|
||||
let model_list = imp.reset_model_list.read().unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(new_sink.alias.clone().into()) {
|
||||
imp.reset_sink_dropdown.set_selected(entry);
|
||||
}
|
||||
}
|
||||
imp.reset_sink_dropdown.set_selected(entry.unwrap().1);
|
||||
}
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(volume as f64);
|
||||
|
@ -388,12 +394,12 @@ pub fn start_output_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Co
|
|||
let input_stream_changed_box = sink_box.clone();
|
||||
|
||||
let res = conn.add_match(sink_added, move |ir: SinkAdded, _, _| {
|
||||
println!("sink added {}", ir.sink.alias);
|
||||
let sink_box = sink_added_box.clone();
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let output_box = sink_box.clone();
|
||||
let output_box_imp = output_box.imp();
|
||||
let mut list = output_box_imp.reset_sink_list.write().unwrap();
|
||||
let sink_index = ir.sink.index;
|
||||
let alias = ir.sink.alias.clone();
|
||||
let name = ir.sink.name.clone();
|
||||
|
@ -410,17 +416,24 @@ pub fn start_output_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Co
|
|||
let sink_clone = sink_entry.clone();
|
||||
let entry = Arc::new(ListEntry::new(&*sink_entry));
|
||||
entry.set_activatable(false);
|
||||
let mut list = output_box_imp.reset_sink_list.write().unwrap();
|
||||
list.insert(sink_index, (entry.clone(), sink_clone, alias.clone()));
|
||||
output_box_imp.reset_sinks.append(&*entry);
|
||||
let mut map = output_box_imp.reset_sink_map.write().unwrap();
|
||||
let mut index = output_box_imp.reset_model_index.write().unwrap();
|
||||
output_box_imp
|
||||
.reset_model_list
|
||||
.write()
|
||||
.unwrap()
|
||||
.append(&alias);
|
||||
map.insert(alias, (sink_index, *index, name));
|
||||
*index += 1;
|
||||
let model_list = output_box_imp.reset_model_list.write().unwrap();
|
||||
if model_list.string(*index - 1) == Some("Dummy Output".into()) {
|
||||
if alias == "Dummy Output" {
|
||||
return;
|
||||
}
|
||||
model_list.append(&alias);
|
||||
model_list.remove(*index - 1);
|
||||
map.insert(alias, (sink_index, name));
|
||||
} else {
|
||||
model_list.append(&alias);
|
||||
map.insert(alias, (sink_index, name));
|
||||
*index += 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
|
@ -436,25 +449,33 @@ pub fn start_output_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Co
|
|||
glib::idle_add_once(move || {
|
||||
let output_box = sink_box.clone();
|
||||
let output_box_imp = output_box.imp();
|
||||
let mut list = output_box_imp.reset_sink_list.write().unwrap();
|
||||
let entry = list.remove(&ir.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
|
||||
let entry: Option<(Arc<ListEntry>, Arc<SinkEntry>, String)>;
|
||||
{
|
||||
let mut list = output_box_imp.reset_sink_list.write().unwrap();
|
||||
entry = list.remove(&ir.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
output_box_imp
|
||||
.reset_sinks
|
||||
.remove(&*entry.clone().unwrap().0);
|
||||
let mut map = output_box_imp.reset_sink_map.write().unwrap();
|
||||
let entry_index = map.remove(&entry.unwrap().2);
|
||||
if let Some(entry_index) = entry_index {
|
||||
output_box_imp
|
||||
.reset_model_list
|
||||
.write()
|
||||
.unwrap()
|
||||
.remove(entry_index.1);
|
||||
}
|
||||
let alias = entry.unwrap().2;
|
||||
map.remove(&alias);
|
||||
let mut index = output_box_imp.reset_model_index.write().unwrap();
|
||||
if *index != 0 {
|
||||
let model_list = output_box_imp.reset_model_list.write().unwrap();
|
||||
|
||||
if *index == 1 {
|
||||
model_list.append("Dummy Output");
|
||||
}
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(alias.clone().into()) {
|
||||
model_list.remove(entry);
|
||||
}
|
||||
}
|
||||
if *index > 1 {
|
||||
*index -= 1;
|
||||
}
|
||||
});
|
||||
|
@ -583,9 +604,12 @@ pub fn start_output_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Co
|
|||
let percentage = (fraction).to_string() + "%";
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(*volume as f64);
|
||||
let map = output_box_imp.reset_sink_map.read().unwrap();
|
||||
if let Some(index) = map.get(&alias) {
|
||||
imp.reset_sink_selection.set_selected(index.1);
|
||||
let index = output_box_imp.reset_model_index.read().unwrap();
|
||||
let model_list = output_box_imp.reset_model_list.read().unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(alias.clone().into()) {
|
||||
imp.reset_sink_selection.set_selected(entry);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ type SinkEntryMap = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<SinkEntry>, Str
|
|||
type InputStreamEntryMap = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<InputStreamEntry>)>>>;
|
||||
// key is model name -> alias, first u32 is the index of the sink, the second the index in the model list and the third is
|
||||
// the detailed name
|
||||
type SinkMap = Arc<RwLock<HashMap<String, (u32, u32, String)>>>;
|
||||
type SinkMap = Arc<RwLock<HashMap<String, (u32, String)>>>;
|
||||
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
#[template(resource = "/org/Xetibo/ReSet/resetAudioOutput.ui")]
|
||||
|
|
|
@ -71,12 +71,12 @@ fn setup_callbacks(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) -> Arc<Wif
|
|||
imp.reset_wifi_devices.write().unwrap().clear();
|
||||
*imp.reset_model_list.write().unwrap() = StringList::new(&[]);
|
||||
*imp.reset_model_index.write().unwrap() = 0;
|
||||
let mut map = imp.wifi_entries.lock().unwrap();
|
||||
let mut map = imp.wifi_entries.write().unwrap();
|
||||
for entry in map.iter() {
|
||||
imp.reset_wifi_list.remove(&*(*entry.1));
|
||||
}
|
||||
map.clear();
|
||||
imp.wifi_entries_path.lock().unwrap().clear();
|
||||
imp.wifi_entries_path.write().unwrap().clear();
|
||||
listeners.wifi_listener.store(false, Ordering::SeqCst);
|
||||
} else {
|
||||
start_event_listener(listeners.clone(), wifibox_ref.clone());
|
||||
|
@ -96,8 +96,8 @@ pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
|
|||
let wifi_entries_path = wifi_box.imp().wifi_entries_path.clone();
|
||||
|
||||
gio::spawn_blocking(move || {
|
||||
let access_points = get_access_points();
|
||||
let devices = get_wifi_devices();
|
||||
let access_points = get_access_points();
|
||||
{
|
||||
let imp = wifibox_ref.imp();
|
||||
let list = imp.reset_model_list.write().unwrap();
|
||||
|
@ -119,8 +119,8 @@ pub fn scan_for_wifi(wifi_box: Arc<WifiBox>) {
|
|||
dbus_start_network_events();
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let mut wifi_entries = wifi_entries.lock().unwrap();
|
||||
let mut wifi_entries_path = wifi_entries_path.lock().unwrap();
|
||||
let mut wifi_entries = wifi_entries.write().unwrap();
|
||||
let mut wifi_entries_path = wifi_entries_path.write().unwrap();
|
||||
let imp = wifibox_ref.imp();
|
||||
|
||||
let list = imp.reset_model_list.read().unwrap();
|
||||
|
@ -286,8 +286,8 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
|||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let imp = wifi_box.imp();
|
||||
let mut wifi_entries = imp.wifi_entries.lock().unwrap();
|
||||
let mut wifi_entries_path = imp.wifi_entries_path.lock().unwrap();
|
||||
let mut wifi_entries = imp.wifi_entries.write().unwrap();
|
||||
let mut wifi_entries_path = imp.wifi_entries_path.write().unwrap();
|
||||
let ssid = ir.access_point.ssid.clone();
|
||||
let path = ir.access_point.dbus_path.clone();
|
||||
if wifi_entries.get(&ssid).is_some() || ssid.is_empty() {
|
||||
|
@ -312,8 +312,8 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
|||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let imp = wifi_box.imp();
|
||||
let mut wifi_entries = imp.wifi_entries.lock().unwrap();
|
||||
let mut wifi_entries_path = imp.wifi_entries_path.lock().unwrap();
|
||||
let mut wifi_entries = imp.wifi_entries.write().unwrap();
|
||||
let mut wifi_entries_path = imp.wifi_entries_path.write().unwrap();
|
||||
let entry = wifi_entries_path.remove(&ir.access_point);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
|
@ -335,7 +335,7 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
|||
glib::spawn_future(async move {
|
||||
glib::idle_add_local_once(move || {
|
||||
let imp = wifi_box.imp();
|
||||
let wifi_entries = imp.wifi_entries.lock().unwrap();
|
||||
let wifi_entries = imp.wifi_entries.read().unwrap();
|
||||
let entry = wifi_entries.get(&ir.access_point.ssid);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
|
@ -399,7 +399,7 @@ pub fn start_event_listener(listeners: Arc<Listeners>, wifi_box: Arc<WifiBox>) {
|
|||
} else {
|
||||
*current_device = ir.wifi_device;
|
||||
}
|
||||
let mut wifi_entries = imp.wifi_entries.lock().unwrap();
|
||||
let mut wifi_entries = imp.wifi_entries.write().unwrap();
|
||||
for entry in wifi_entries.iter_mut() {
|
||||
let imp = entry.1.imp();
|
||||
let mut connected = imp.connected.borrow_mut();
|
||||
|
|
|
@ -7,7 +7,7 @@ use gtk::{prelude::*, StringList};
|
|||
use re_set_lib::network::network_structures::WifiDevice;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use crate::components::base::list_entry::ListEntry;
|
||||
use crate::components::wifi::wifi_entry::WifiEntry;
|
||||
|
@ -31,8 +31,8 @@ pub struct WifiBox {
|
|||
pub reset_stored_wifi_list: TemplateChild<PreferencesGroup>,
|
||||
#[template_child]
|
||||
pub reset_available_networks: TemplateChild<ActionRow>,
|
||||
pub wifi_entries: Arc<Mutex<HashMap<Vec<u8>, Arc<WifiEntry>>>>,
|
||||
pub wifi_entries_path: Arc<Mutex<HashMap<Path<'static>, Arc<WifiEntry>>>>,
|
||||
pub wifi_entries: Arc<RwLock<HashMap<Vec<u8>, Arc<WifiEntry>>>>,
|
||||
pub wifi_entries_path: Arc<RwLock<HashMap<Path<'static>, Arc<WifiEntry>>>>,
|
||||
pub reset_wifi_devices: Arc<RwLock<HashMap<String, (WifiDevice, u32)>>>,
|
||||
pub reset_current_wifi_device: Arc<RefCell<WifiDevice>>,
|
||||
pub reset_model_list: Arc<RwLock<StringList>>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue