fix: Use threading for every single dbus call on audio

This commit is contained in:
Fabio Lenherr / DashieTM 2023-11-15 23:24:35 +01:00
parent ed905cd075
commit af06f8da32
5 changed files with 176 additions and 138 deletions

View file

@ -1042,14 +1042,14 @@
{
"type": "archive",
"archive-type": "tar-gzip",
"url": "https://static.crates.io/crates/reset_daemon/reset_daemon-0.1.3.crate",
"sha256": "1d7b1c575b773eadd0fc8991de8abb883cfb7bce9c5e8c4f9e10b85cb142efee",
"dest": "cargo/vendor/reset_daemon-0.1.3"
"url": "https://static.crates.io/crates/reset_daemon/reset_daemon-0.1.4.crate",
"sha256": "2978104d24796489f84a2636a8797730bfeac5693a5550751b1fd638dd7bea58",
"dest": "cargo/vendor/reset_daemon-0.1.4"
},
{
"type": "inline",
"contents": "{\"package\": \"1d7b1c575b773eadd0fc8991de8abb883cfb7bce9c5e8c4f9e10b85cb142efee\", \"files\": {}}",
"dest": "cargo/vendor/reset_daemon-0.1.3",
"contents": "{\"package\": \"2978104d24796489f84a2636a8797730bfeac5693a5550751b1fd638dd7bea58\", \"files\": {}}",
"dest": "cargo/vendor/reset_daemon-0.1.4",
"dest-filename": ".cargo-checksum.json"
},
{

View file

@ -8,7 +8,7 @@ use dbus::blocking::Connection;
use dbus::Error;
use glib::subclass::types::ObjectSubclassIsExt;
use glib::{clone, Cast, Propagation};
use gtk::StringObject;
use gtk::{gio, StringObject};
use ReSet_Lib::audio::audio::OutputStream;
use super::outputStreamEntryImpl;
@ -125,52 +125,63 @@ 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(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> = proxy.method_call(
let _: Result<(), Error> = proxy.method_call(
"org.xetibo.ReSet",
"SetOutputStreamVolume",
(index, channels, value as u32),
);
if res.is_err() {
return false;
}
res.unwrap().0
// if res.is_err() {
// return false;
// }
// res.unwrap().0
});
true
}
fn toggle_output_stream_mute(index: u32, muted: bool) -> bool {
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> =
let _: Result<(), Error> =
proxy.method_call("org.xetibo.ReSet", "SetOutputStreamMute", (index, muted));
if res.is_err() {
return false;
}
res.unwrap().0
// if res.is_err() {
// return false;
// }
// res.unwrap().0
});
true
}
fn set_source_of_output_stream(stream: u32, source: u32) -> bool {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> = proxy.method_call(
"org.xetibo.ReSet",
"SetSourceOfOutputStream",
(stream, source),
);
if res.is_err() {
return false;
}
res.unwrap().0
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let _: Result<(bool,), Error> = proxy.method_call(
"org.xetibo.ReSet",
"SetSourceOfOutputStream",
(stream, source),
);
// if res.is_err() {
// return false;
// }
// res.unwrap().0
});
true
}
// TODO propagate error from dbus

View file

@ -4,13 +4,13 @@ use std::time::Duration;
use adw::glib;
use adw::glib::Object;
use adw::prelude::{ButtonExt, RangeExt, CheckButtonExt};
use adw::prelude::{ButtonExt, CheckButtonExt, RangeExt};
use dbus::blocking::Connection;
use dbus::Error;
use glib::subclass::types::ObjectSubclassIsExt;
use glib::{clone, Propagation};
use gtk::{gio, CheckButton};
use ReSet_Lib::audio::audio::Source;
use gtk::CheckButton;
use super::sourceEntryImpl;
@ -80,51 +80,60 @@ impl SourceEntry {
}
pub fn set_source_volume(value: f64, index: u32, channels: u16) -> bool {
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> = proxy.method_call(
let _: Result<(), Error> = proxy.method_call(
"org.xetibo.ReSet",
"SetSourceVolume",
(index, channels, value as u32),
);
if res.is_err() {
return false;
}
res.unwrap().0
// if res.is_err() {
// return false;
// }
// res.unwrap().0
});
true
}
pub fn toggle_source_mute(index: u32, muted: bool) -> bool {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> =
proxy.method_call("org.xetibo.ReSet", "SetSourceMute", (index, muted));
if res.is_err() {
return false;
}
res.unwrap().0
}
pub fn set_default_source(name: Arc<String>) {
thread::spawn(move || {
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> =
let _: Result<(), Error> =
proxy.method_call("org.xetibo.ReSet", "SetSourceMute", (index, muted));
// if res.is_err() {
// return false;
// }
// res.unwrap().0
});
true
}
pub fn set_default_source(name: Arc<String>) -> bool {
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let _: Result<(), Error> =
proxy.method_call("org.xetibo.ReSet", "SetDefaultSink", (name.as_str(),));
if res.is_err() {
return;
}
// if res.is_err() {
// return;
// }
// handle change
});
true
}
// TODO propagate error from dbus

View file

@ -8,7 +8,7 @@ use dbus::blocking::Connection;
use dbus::Error;
use glib::subclass::types::ObjectSubclassIsExt;
use glib::{clone, Cast, Propagation};
use gtk::StringObject;
use gtk::{gio, StringObject};
use ReSet_Lib::audio::audio::InputStream;
use super::inputStreamEntryImpl;
@ -24,7 +24,6 @@ impl InputStreamEntry {
pub fn new(sink_box: Arc<SinkBox>, stream: InputStream) -> Self {
let obj: Self = Object::builder().build();
// TODO use event callback for progress bar -> this is the "im speaking" indicator
// TODO handle events
{
let index = stream.sink_index;
let box_imp = sink_box.imp();
@ -145,49 +144,60 @@ impl InputStreamEntry {
}
fn set_inputstream_volume(value: f64, index: u32, channels: u16) -> bool {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> = proxy.method_call(
"org.xetibo.ReSet",
"SetInputStreamVolume",
(index, channels, value as u32),
);
if res.is_err() {
return false;
}
res.unwrap().0
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let _: Result<(), Error> = proxy.method_call(
"org.xetibo.ReSet",
"SetInputStreamVolume",
(index, channels, value as u32),
);
// if res.is_err() {
// return false;
// }
// res.unwrap().0
});
true
}
fn toggle_input_stream_mute(index: u32, muted: bool) -> bool {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> =
proxy.method_call("org.xetibo.ReSet", "SetInputStreamMute", (index, muted));
if res.is_err() {
return false;
}
res.unwrap().0
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let _: Result<(), Error> =
proxy.method_call("org.xetibo.ReSet", "SetInputStreamMute", (index, muted));
// if res.is_err() {
// return false;
// }
// res.unwrap().0
});
true
}
fn set_sink_of_input_stream(stream: u32, sink: u32) -> bool {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> =
proxy.method_call("org.xetibo.ReSet", "SetSinkOfInputStream", (stream, sink));
if res.is_err() {
return false;
}
res.unwrap().0
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let _: Result<(), Error> =
proxy.method_call("org.xetibo.ReSet", "SetSinkOfInputStream", (stream, sink));
// if res.is_err() {
// return false;
// }
// res.unwrap().0
});
true
}
// TODO propagate error from dbus

View file

@ -9,7 +9,7 @@ use dbus::blocking::Connection;
use dbus::Error;
use glib::subclass::types::ObjectSubclassIsExt;
use glib::{clone, Propagation};
use gtk::CheckButton;
use gtk::{gio, CheckButton};
use ReSet_Lib::audio::audio::Sink;
use super::sinkEntryImpl;
@ -80,51 +80,59 @@ impl SinkEntry {
}
pub fn set_sink_volume(value: f64, index: u32, channels: u16) -> bool {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> = proxy.method_call(
"org.xetibo.ReSet",
"SetSinkVolume",
(index, channels, value as u32),
);
if res.is_err() {
return false;
}
res.unwrap().0
}
pub fn toggle_sink_mute(index: u32, muted: bool) -> bool {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> =
proxy.method_call("org.xetibo.ReSet", "SetSinkMute", (index, muted));
if res.is_err() {
return false;
}
res.unwrap().0
}
pub fn set_default_sink(name: Arc<String>) {
thread::spawn(move || {
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let res: Result<(bool,), Error> =
let _: Result<(), Error> = proxy.method_call(
"org.xetibo.ReSet",
"SetSinkVolume",
(index, channels, value as u32),
);
// if res.is_err() {
// return false;
// }
// res.unwrap().0
});
true
}
pub fn toggle_sink_mute(index: u32, muted: bool) -> bool {
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let _: Result<(), Error> =
proxy.method_call("org.xetibo.ReSet", "SetSinkMute", (index, muted));
// if res.is_err() {
// return false;
// }
// res.unwrap().0
});
true
}
pub fn set_default_sink(name: Arc<String>) {
gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(1000),
);
let _: Result<(), Error> =
proxy.method_call("org.xetibo.ReSet", "SetDefaultSink", (name.as_str(),));
if res.is_err() {
return;
}
// if res.is_err() {
// return;
// }
// handle change
});
}
// TODO propagate error from dbus