store some glib future join handles
This commit is contained in:
parent
c25226f7c2
commit
226c8073d4
1 changed files with 34 additions and 22 deletions
|
@ -4,6 +4,7 @@ mod imp {
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
use glib::subclass::InitializingObject;
|
use glib::subclass::InitializingObject;
|
||||||
|
use glib::JoinHandle;
|
||||||
use gtk::{gdk, gio, glib};
|
use gtk::{gdk, gio, glib};
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -54,6 +55,9 @@ mod imp {
|
||||||
_playlist_count: (),
|
_playlist_count: (),
|
||||||
|
|
||||||
pub(super) queued_seek: Cell<Option<f64>>,
|
pub(super) queued_seek: Cell<Option<f64>>,
|
||||||
|
|
||||||
|
mpv_event_loop_handle: RefCell<Option<JoinHandle<()>>>, // really !, not ()
|
||||||
|
zbus_executor_loop_handle: RefCell<Option<JoinHandle<()>>>, // same
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Window {
|
impl Default for Window {
|
||||||
|
@ -99,6 +103,9 @@ mod imp {
|
||||||
_playlist_count: (),
|
_playlist_count: (),
|
||||||
|
|
||||||
queued_seek: Cell::new(None),
|
queued_seek: Cell::new(None),
|
||||||
|
|
||||||
|
mpv_event_loop_handle: Default::default(),
|
||||||
|
zbus_executor_loop_handle: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,8 +132,9 @@ mod imp {
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
|
|
||||||
let window = self.obj().downgrade();
|
let window = self.obj().downgrade();
|
||||||
glib::spawn_future_local(async move {
|
let mpv_event_loop_handle = glib::spawn_future_local(async move {
|
||||||
while let Some(window) = window.upgrade() {
|
loop {
|
||||||
|
let window = window.upgrade().unwrap();
|
||||||
let listener = window.imp().mpv.wakeup_listener();
|
let listener = window.imp().mpv.wakeup_listener();
|
||||||
while let Some(event) = window.imp().mpv.wait_event(0.0) {
|
while let Some(event) = window.imp().mpv.wait_event(0.0) {
|
||||||
use crate::mpv::Event;
|
use crate::mpv::Event;
|
||||||
|
@ -280,10 +288,11 @@ mod imp {
|
||||||
listener.await;
|
listener.await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
self.mpv_event_loop_handle.replace(Some(mpv_event_loop_handle));
|
||||||
|
|
||||||
// set up mpris
|
// set up mpris
|
||||||
let window = self.obj().clone();
|
let window = self.obj().clone();
|
||||||
glib::spawn_future_local(async move {
|
let zbus_executor_loop_handle = glib::spawn_future_local(async move {
|
||||||
let conn = zbus::connection::Builder::session()
|
let conn = zbus::connection::Builder::session()
|
||||||
.expect("could not connect to the session bus")
|
.expect("could not connect to the session bus")
|
||||||
.internal_executor(false)
|
.internal_executor(false)
|
||||||
|
@ -291,17 +300,10 @@ mod imp {
|
||||||
.await
|
.await
|
||||||
.expect("could not build connection to the session bus");
|
.expect("could not build connection to the session bus");
|
||||||
|
|
||||||
// run this in glib's main loop
|
|
||||||
glib::spawn_future_local(glib::clone!(
|
glib::spawn_future_local(glib::clone!(
|
||||||
#[strong]
|
#[strong]
|
||||||
conn,
|
conn,
|
||||||
async move {
|
async move {
|
||||||
loop {
|
|
||||||
conn.executor().tick().await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
crate::Mpris::setup(conn.object_server(), &window)
|
crate::Mpris::setup(conn.object_server(), &window)
|
||||||
.await
|
.await
|
||||||
.expect("could not serve mpris");
|
.expect("could not serve mpris");
|
||||||
|
@ -311,13 +313,20 @@ mod imp {
|
||||||
.expect("could not serve mpris player");
|
.expect("could not serve mpris player");
|
||||||
FIXME */
|
FIXME */
|
||||||
|
|
||||||
drop(window); // don't keep this alive
|
|
||||||
|
|
||||||
// always set up handlers before requesting service name
|
// always set up handlers before requesting service name
|
||||||
conn.request_name("org.mpris.MediaPlayer2.audrey")
|
conn.request_name("org.mpris.MediaPlayer2.audrey")
|
||||||
.await
|
.await
|
||||||
.expect("could not register name in session bus");
|
.expect("could not register name in session bus");
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
// run this in glib's main loop
|
||||||
|
loop {
|
||||||
|
conn.executor().tick().await;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
self.zbus_executor_loop_handle
|
||||||
|
.replace(Some(zbus_executor_loop_handle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,6 +478,9 @@ mod imp {
|
||||||
impl Drop for Window {
|
impl Drop for Window {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
event!(Level::DEBUG, "dropping AudreyUiWindow");
|
event!(Level::DEBUG, "dropping AudreyUiWindow");
|
||||||
|
|
||||||
|
self.mpv_event_loop_handle.take().unwrap().abort();
|
||||||
|
self.zbus_executor_loop_handle.take().unwrap().abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue