audio: Fix double borrow
This commit is contained in:
parent
9b97404fa6
commit
bd3d839f3e
1 changed files with 8 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
use futures::{channel::oneshot, future::poll_fn, task::Poll};
|
use futures::{channel::oneshot, future::poll_fn, task::Poll};
|
||||||
|
use gtk4::glib;
|
||||||
use libpulse_binding::{
|
use libpulse_binding::{
|
||||||
callbacks::ListResult,
|
callbacks::ListResult,
|
||||||
context::{
|
context::{
|
||||||
|
|
@ -47,12 +48,17 @@ impl PA {
|
||||||
|
|
||||||
pub fn set_state_callback<F: Fn(&Self, State) + 'static>(&self, cb: F) {
|
pub fn set_state_callback<F: Fn(&Self, State) + 'static>(&self, cb: F) {
|
||||||
let pa = self.clone(); // TODO: weak ref?
|
let pa = self.clone(); // TODO: weak ref?
|
||||||
|
let cb = Rc::new(cb);
|
||||||
self.0
|
self.0
|
||||||
.context
|
.context
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.set_state_callback(Some(Box::new(move || {
|
.set_state_callback(Some(Box::new(move || {
|
||||||
let state = pa.0.context.borrow().get_state();
|
let pa = pa.clone();
|
||||||
cb(&pa, state);
|
let cb = cb.clone();
|
||||||
|
glib::source::idle_add_local_once(move || {
|
||||||
|
let state = pa.0.context.borrow().get_state();
|
||||||
|
cb(&pa, state);
|
||||||
|
});
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue