Add application control prototype
This commit is contained in:
parent
cc2ff29def
commit
d1eec7399a
1 changed files with 47 additions and 8 deletions
|
@ -82,9 +82,23 @@ pub fn run() {
|
|||
mainloop.borrow_mut().unlock();
|
||||
|
||||
//---------------------
|
||||
mainloop.borrow_mut().lock();
|
||||
let ml = Rc::clone(&mainloop);
|
||||
let ctx = Rc::clone(&context);
|
||||
mute_sink_input(ml, ctx, "Firefox", false);
|
||||
//---------------------
|
||||
|
||||
let sink_filter = Regex::new("USB_Audio_CODEC").expect("Creating RegEx failed");
|
||||
loop {
|
||||
std::thread::sleep(time::Duration::from_secs(u64::MAX));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_default_sink(
|
||||
mainloop: Rc<RefCell<Mainloop>>,
|
||||
context: Rc<RefCell<Context>>,
|
||||
name: &str,
|
||||
) {
|
||||
mainloop.borrow_mut().lock();
|
||||
let sink_filter = Regex::new(name).expect("Creating RegEx failed");
|
||||
let callback_context = context.clone();
|
||||
context
|
||||
.borrow_mut()
|
||||
|
@ -100,11 +114,36 @@ pub fn run() {
|
|||
}
|
||||
_ => {}
|
||||
});
|
||||
|
||||
mainloop.borrow_mut().unlock();
|
||||
//---------------------
|
||||
|
||||
loop {
|
||||
std::thread::sleep(time::Duration::from_secs(u64::MAX));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mute_sink_input(
|
||||
mainloop: Rc<RefCell<Mainloop>>,
|
||||
context: Rc<RefCell<Context>>,
|
||||
name: &str,
|
||||
state: bool,
|
||||
) {
|
||||
mainloop.borrow_mut().lock();
|
||||
let sink_filter = Regex::new(name).expect("Creating RegEx failed");
|
||||
let callback_context = context.clone();
|
||||
context
|
||||
.borrow_mut()
|
||||
.introspect()
|
||||
.get_sink_input_info_list(move |items_result| match items_result {
|
||||
pulse::callbacks::ListResult::Item(item) => {
|
||||
let application_name = item.proplist.get_str("application.name").unwrap();
|
||||
let matches_regex = sink_filter.is_match(&application_name);
|
||||
|
||||
println!("{:?}", application_name);
|
||||
if matches_regex {
|
||||
println!("Setting default sink to: {}", application_name);
|
||||
callback_context
|
||||
.borrow_mut()
|
||||
.introspect()
|
||||
.set_sink_input_mute(item.index, state, Option::None);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
});
|
||||
mainloop.borrow_mut().unlock();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue