diff --git a/flatpak/cargo-sources.json b/flatpak/cargo-sources.json index 322a502..76117bb 100644 --- a/flatpak/cargo-sources.json +++ b/flatpak/cargo-sources.json @@ -457,14 +457,14 @@ { "type": "archive", "archive-type": "tar-gzip", - "url": "https://static.crates.io/crates/glib/glib-0.18.4.crate", - "sha256": "951bbd7fdc5c044ede9f05170f05a3ae9479239c3afdfe2d22d537a3add15c4e", - "dest": "cargo/vendor/glib-0.18.4" + "url": "https://static.crates.io/crates/glib/glib-0.18.3.crate", + "sha256": "58cf801b6f7829fa76db37449ab67c9c98a2b1bf21076d9113225621e61a0fa6", + "dest": "cargo/vendor/glib-0.18.3" }, { "type": "inline", - "contents": "{\"package\": \"951bbd7fdc5c044ede9f05170f05a3ae9479239c3afdfe2d22d537a3add15c4e\", \"files\": {}}", - "dest": "cargo/vendor/glib-0.18.4", + "contents": "{\"package\": \"58cf801b6f7829fa76db37449ab67c9c98a2b1bf21076d9113225621e61a0fa6\", \"files\": {}}", + "dest": "cargo/vendor/glib-0.18.3", "dest-filename": ".cargo-checksum.json" }, { @@ -808,14 +808,14 @@ { "type": "archive", "archive-type": "tar-gzip", - "url": "https://static.crates.io/crates/mio/mio-0.8.9.crate", - "sha256": "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0", - "dest": "cargo/vendor/mio-0.8.9" + "url": "https://static.crates.io/crates/mio/mio-0.8.10.crate", + "sha256": "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09", + "dest": "cargo/vendor/mio-0.8.10" }, { "type": "inline", - "contents": "{\"package\": \"3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0\", \"files\": {}}", - "dest": "cargo/vendor/mio-0.8.9", + "contents": "{\"package\": \"8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09\", \"files\": {}}", + "dest": "cargo/vendor/mio-0.8.10", "dest-filename": ".cargo-checksum.json" }, { @@ -873,14 +873,14 @@ { "type": "archive", "archive-type": "tar-gzip", - "url": "https://static.crates.io/crates/once_cell/once_cell-1.18.0.crate", - "sha256": "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d", - "dest": "cargo/vendor/once_cell-1.18.0" + "url": "https://static.crates.io/crates/once_cell/once_cell-1.19.0.crate", + "sha256": "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92", + "dest": "cargo/vendor/once_cell-1.19.0" }, { "type": "inline", - "contents": "{\"package\": \"dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d\", \"files\": {}}", - "dest": "cargo/vendor/once_cell-1.18.0", + "contents": "{\"package\": \"3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92\", \"files\": {}}", + "dest": "cargo/vendor/once_cell-1.19.0", "dest-filename": ".cargo-checksum.json" }, { @@ -964,14 +964,14 @@ { "type": "archive", "archive-type": "tar-gzip", - "url": "https://static.crates.io/crates/proc-macro-crate/proc-macro-crate-2.0.0.crate", - "sha256": "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8", - "dest": "cargo/vendor/proc-macro-crate-2.0.0" + "url": "https://static.crates.io/crates/proc-macro-crate/proc-macro-crate-2.0.1.crate", + "sha256": "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a", + "dest": "cargo/vendor/proc-macro-crate-2.0.1" }, { "type": "inline", - "contents": "{\"package\": \"7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8\", \"files\": {}}", - "dest": "cargo/vendor/proc-macro-crate-2.0.0", + "contents": "{\"package\": \"97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a\", \"files\": {}}", + "dest": "cargo/vendor/proc-macro-crate-2.0.1", "dest-filename": ".cargo-checksum.json" }, { @@ -1068,14 +1068,14 @@ { "type": "archive", "archive-type": "tar-gzip", - "url": "https://static.crates.io/crates/reset_daemon/reset_daemon-0.6.0.crate", - "sha256": "11611caa1a9c1c642522228b72ac309502572916924c100b20d06a830b1fad07", - "dest": "cargo/vendor/reset_daemon-0.6.0" + "url": "https://static.crates.io/crates/reset_daemon/reset_daemon-0.6.1.crate", + "sha256": "65079f1d86d15af21811551ea55daf2a05f654c9a27943c918e23d55aa9e4af3", + "dest": "cargo/vendor/reset_daemon-0.6.1" }, { "type": "inline", - "contents": "{\"package\": \"11611caa1a9c1c642522228b72ac309502572916924c100b20d06a830b1fad07\", \"files\": {}}", - "dest": "cargo/vendor/reset_daemon-0.6.0", + "contents": "{\"package\": \"65079f1d86d15af21811551ea55daf2a05f654c9a27943c918e23d55aa9e4af3\", \"files\": {}}", + "dest": "cargo/vendor/reset_daemon-0.6.1", "dest-filename": ".cargo-checksum.json" }, { @@ -1302,27 +1302,27 @@ { "type": "archive", "archive-type": "tar-gzip", - "url": "https://static.crates.io/crates/toml/toml-0.8.8.crate", - "sha256": "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35", - "dest": "cargo/vendor/toml-0.8.8" + "url": "https://static.crates.io/crates/toml/toml-0.8.2.crate", + "sha256": "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d", + "dest": "cargo/vendor/toml-0.8.2" }, { "type": "inline", - "contents": "{\"package\": \"a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35\", \"files\": {}}", - "dest": "cargo/vendor/toml-0.8.8", + "contents": "{\"package\": \"185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d\", \"files\": {}}", + "dest": "cargo/vendor/toml-0.8.2", "dest-filename": ".cargo-checksum.json" }, { "type": "archive", "archive-type": "tar-gzip", - "url": "https://static.crates.io/crates/toml_datetime/toml_datetime-0.6.5.crate", - "sha256": "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1", - "dest": "cargo/vendor/toml_datetime-0.6.5" + "url": "https://static.crates.io/crates/toml_datetime/toml_datetime-0.6.3.crate", + "sha256": "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b", + "dest": "cargo/vendor/toml_datetime-0.6.3" }, { "type": "inline", - "contents": "{\"package\": \"3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1\", \"files\": {}}", - "dest": "cargo/vendor/toml_datetime-0.6.5", + "contents": "{\"package\": \"7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b\", \"files\": {}}", + "dest": "cargo/vendor/toml_datetime-0.6.3", "dest-filename": ".cargo-checksum.json" }, { @@ -1341,27 +1341,14 @@ { "type": "archive", "archive-type": "tar-gzip", - "url": "https://static.crates.io/crates/toml_edit/toml_edit-0.20.7.crate", - "sha256": "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81", - "dest": "cargo/vendor/toml_edit-0.20.7" + "url": "https://static.crates.io/crates/toml_edit/toml_edit-0.20.2.crate", + "sha256": "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338", + "dest": "cargo/vendor/toml_edit-0.20.2" }, { "type": "inline", - "contents": "{\"package\": \"70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81\", \"files\": {}}", - "dest": "cargo/vendor/toml_edit-0.20.7", - "dest-filename": ".cargo-checksum.json" - }, - { - "type": "archive", - "archive-type": "tar-gzip", - "url": "https://static.crates.io/crates/toml_edit/toml_edit-0.21.0.crate", - "sha256": "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03", - "dest": "cargo/vendor/toml_edit-0.21.0" - }, - { - "type": "inline", - "contents": "{\"package\": \"d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03\", \"files\": {}}", - "dest": "cargo/vendor/toml_edit-0.21.0", + "contents": "{\"package\": \"396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338\", \"files\": {}}", + "dest": "cargo/vendor/toml_edit-0.20.2", "dest-filename": ".cargo-checksum.json" }, { @@ -1575,14 +1562,14 @@ { "type": "archive", "archive-type": "tar-gzip", - "url": "https://static.crates.io/crates/winnow/winnow-0.5.19.crate", - "sha256": "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b", - "dest": "cargo/vendor/winnow-0.5.19" + "url": "https://static.crates.io/crates/winnow/winnow-0.5.26.crate", + "sha256": "b67b5f0a4e7a27a64c651977932b9dc5667ca7fc31ac44b03ed37a0cf42fdfff", + "dest": "cargo/vendor/winnow-0.5.26" }, { "type": "inline", - "contents": "{\"package\": \"829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b\", \"files\": {}}", - "dest": "cargo/vendor/winnow-0.5.19", + "contents": "{\"package\": \"b67b5f0a4e7a27a64c651977932b9dc5667ca7fc31ac44b03ed37a0cf42fdfff\", \"files\": {}}", + "dest": "cargo/vendor/winnow-0.5.26", "dest-filename": ".cargo-checksum.json" }, { diff --git a/src/components/bluetooth/bluetooth_box.rs b/src/components/bluetooth/bluetooth_box.rs index b3e1f9c..c820b7d 100644 --- a/src/components/bluetooth/bluetooth_box.rs +++ b/src/components/bluetooth/bluetooth_box.rs @@ -296,11 +296,11 @@ pub fn start_bluetooth_listener(listeners: Arc, bluetooth_box: Arc 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; // } diff --git a/src/components/input/source_box.rs b/src/components/input/source_box.rs index 11f6023..c48865c 100644 --- a/src/components/input/source_box.rs +++ b/src/components/input/source_box.rs @@ -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) { 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) { } 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) { 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, 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) { fn get_output_streams() -> Vec { 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,), Error> = proxy.method_call(AUDIO, "ListOutputStreams", ()); if res.is_err() { @@ -323,13 +328,8 @@ fn get_output_streams() -> Vec { fn get_sources() -> Vec { let conn = Connection::new_session().unwrap(); - let proxy = conn.with_proxy( - BASE, - DBUS_PATH, - Duration::from_millis(1000), - ); - let res: Result<(Vec,), Error> = - proxy.method_call(AUDIO, "ListSources", ()); + let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000)); + let res: Result<(Vec,), Error> = proxy.method_call(AUDIO, "ListSources", ()); if res.is_err() { return Vec::new(); } @@ -338,13 +338,8 @@ fn get_sources() -> Vec { fn get_cards() -> Vec { let conn = Connection::new_session().unwrap(); - let proxy = conn.with_proxy( - BASE, - DBUS_PATH, - Duration::from_millis(1000), - ); - let res: Result<(Vec,), Error> = - proxy.method_call(AUDIO, "ListCards", ()); + let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000)); + let res: Result<(Vec,), Error> = proxy.method_call(AUDIO, "ListCards", ()); if res.is_err() { return Vec::new(); } @@ -353,13 +348,8 @@ fn get_cards() -> Vec { 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) -> 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) -> 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) -> 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) -> 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, Arc, 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) -> 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); + } } }); }); diff --git a/src/components/input/source_box_impl.rs b/src/components/input/source_box_impl.rs index b087434..da5b78f 100644 --- a/src/components/input/source_box_impl.rs +++ b/src/components/input/source_box_impl.rs @@ -16,7 +16,8 @@ use super::source_entry::SourceEntry; type SourceEntryMap = Arc, Arc, String)>>>; type OutputStreamEntryMap = Arc, Arc)>>>; -type SourceMap = Arc>>; +// the key is the alias, the first value u32 is the index of the source, the second is the technical name +type SourceMap = Arc>>; #[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>, pub reset_model_index: Arc>, - // 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>, } diff --git a/src/components/output/input_stream_entry.rs b/src/components/output/input_stream_entry.rs index bf241d2..2824515 100644 --- a/src/components/output/input_stream_entry.rs +++ b/src/components/output/input_stream_entry.rs @@ -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; // } diff --git a/src/components/output/sink_box.rs b/src/components/output/sink_box.rs index 5ccfa4b..0b9b58c 100644 --- a/src/components/output/sink_box.rs +++ b/src/components/output/sink_box.rs @@ -106,9 +106,9 @@ pub fn populate_sinks(output_box: Arc) { 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) { 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) { 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, 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) -> 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) -> 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) -> 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, Arc, 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) -> 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); + } } }); }); diff --git a/src/components/output/sink_box_impl.rs b/src/components/output/sink_box_impl.rs index 64d0fa9..52a7031 100644 --- a/src/components/output/sink_box_impl.rs +++ b/src/components/output/sink_box_impl.rs @@ -18,7 +18,7 @@ type SinkEntryMap = Arc, Arc, Str type InputStreamEntryMap = Arc, Arc)>>>; // 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>>; +type SinkMap = Arc>>; #[derive(Default, CompositeTemplate)] #[template(resource = "/org/Xetibo/ReSet/resetAudioOutput.ui")] diff --git a/src/components/wifi/wifi_box.rs b/src/components/wifi/wifi_box.rs index 137a021..b03a54c 100644 --- a/src/components/wifi/wifi_box.rs +++ b/src/components/wifi/wifi_box.rs @@ -71,12 +71,12 @@ fn setup_callbacks(listeners: Arc, wifi_box: Arc) -> Arc) { 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) { 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, wifi_box: Arc) { 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, wifi_box: Arc) { 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, wifi_box: Arc) { 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, wifi_box: Arc) { } 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(); diff --git a/src/components/wifi/wifi_box_impl.rs b/src/components/wifi/wifi_box_impl.rs index 9e0f93a..8db8512 100644 --- a/src/components/wifi/wifi_box_impl.rs +++ b/src/components/wifi/wifi_box_impl.rs @@ -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, #[template_child] pub reset_available_networks: TemplateChild, - pub wifi_entries: Arc, Arc>>>, - pub wifi_entries_path: Arc, Arc>>>, + pub wifi_entries: Arc, Arc>>>, + pub wifi_entries_path: Arc, Arc>>>, pub reset_wifi_devices: Arc>>, pub reset_current_wifi_device: Arc>, pub reset_model_list: Arc>, diff --git a/src/resources/resetAudioInput.ui b/src/resources/resetAudioInput.ui index 38e3c09..a66fa05 100644 --- a/src/resources/resetAudioInput.ui +++ b/src/resources/resetAudioInput.ui @@ -27,6 +27,9 @@ 10 + 5 + 5 + 5 Input Devices @@ -129,6 +132,10 @@ vertical + 5 + 5 + 5 + 5 Input Streams @@ -173,6 +180,10 @@ vertical + 5 + 5 + 5 + 5 Input Streams @@ -193,6 +204,10 @@ + 5 + 5 + 5 + 5 Devices diff --git a/src/resources/resetAudioOutput.ui b/src/resources/resetAudioOutput.ui index 3e6bfa6..b6c8903 100644 --- a/src/resources/resetAudioOutput.ui +++ b/src/resources/resetAudioOutput.ui @@ -27,6 +27,9 @@ 10 + 5 + 5 + 5 Output Devices @@ -130,6 +133,10 @@ vertical + 5 + 5 + 5 + 5 Output Streams @@ -174,6 +181,10 @@ vertical + 5 + 5 + 5 + 5 Output Streams @@ -194,6 +205,10 @@ + 5 + 5 + 5 + 5 Devices diff --git a/src/resources/resetBluetooth.ui b/src/resources/resetBluetooth.ui index e745362..b9c7057 100644 --- a/src/resources/resetBluetooth.ui +++ b/src/resources/resetBluetooth.ui @@ -39,6 +39,10 @@ vertical + 5 + 5 + 5 + 5 Bluetooth Adapter @@ -59,6 +63,15 @@ + + + 5 + 5 + 5 + 5 + Connected Devices + + @@ -67,17 +80,13 @@ 15 + 5 + 5 + 5 10 Available Devices - - - 5 - 5 - Connected Devices - - @@ -91,6 +100,10 @@ vertical + 5 + 5 + 5 + 5 Available Networks @@ -108,6 +121,10 @@ + 5 + 5 + 5 + 5 Visibility Settings diff --git a/src/resources/resetInputStreamEntry.ui b/src/resources/resetInputStreamEntry.ui index 33c6efb..045b622 100644 --- a/src/resources/resetInputStreamEntry.ui +++ b/src/resources/resetInputStreamEntry.ui @@ -4,6 +4,10 @@