Compare commits

...

2 commits

Author SHA1 Message Date
226c8073d4 store some glib future join handles 2024-11-05 11:02:02 +01:00
c25226f7c2 log some more bullshit 2024-11-05 10:52:33 +01:00

View file

@ -4,6 +4,7 @@ mod imp {
use adw::prelude::*;
use adw::subclass::prelude::*;
use glib::subclass::InitializingObject;
use glib::JoinHandle;
use gtk::{gdk, gio, glib};
use std::cell::{Cell, RefCell};
use std::rc::Rc;
@ -54,6 +55,9 @@ mod imp {
_playlist_count: (),
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 {
@ -99,6 +103,9 @@ mod imp {
_playlist_count: (),
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();
let window = self.obj().downgrade();
glib::spawn_future_local(async move {
while let Some(window) = window.upgrade() {
let mpv_event_loop_handle = glib::spawn_future_local(async move {
loop {
let window = window.upgrade().unwrap();
let listener = window.imp().mpv.wakeup_listener();
while let Some(event) = window.imp().mpv.wait_event(0.0) {
use crate::mpv::Event;
@ -246,7 +254,15 @@ mod imp {
// ^ ignore
}
Event::Seek => {
event!(Level::INFO, "seek event");
// TODO: if doing "buffering" progress bar, show it after a timeout here
}
Event::PlaybackRestart => {
event!(Level::INFO, "playback restart event");
// TODO: if doing "buffering" progress bar, hide it here
if let Some(queued_seek) = window.imp().queued_seek.take() {
// a seek was tried before and failed, try again now
event!(Level::INFO, "performing queued seek to {queued_seek}");
@ -255,6 +271,8 @@ mod imp {
}
Event::EndFile(event) => {
event!(Level::INFO, "end file event: {event:?}");
if let Err(err) = event.reason {
event!(Level::ERROR, "end file error: {err}");
}
@ -270,10 +288,11 @@ mod imp {
listener.await;
}
});
self.mpv_event_loop_handle.replace(Some(mpv_event_loop_handle));
// set up mpris
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()
.expect("could not connect to the session bus")
.internal_executor(false)
@ -281,33 +300,33 @@ mod imp {
.await
.expect("could not build connection to the session bus");
// run this in glib's main loop
glib::spawn_future_local(glib::clone!(
#[strong]
conn,
async move {
loop {
conn.executor().tick().await;
}
crate::Mpris::setup(conn.object_server(), &window)
.await
.expect("could not serve mpris");
/*
crate::mpris::Player::setup(conn.object_server(), &window.imp().playbin)
.await
.expect("could not serve mpris player");
FIXME */
// always set up handlers before requesting service name
conn.request_name("org.mpris.MediaPlayer2.audrey")
.await
.expect("could not register name in session bus");
}
));
crate::Mpris::setup(conn.object_server(), &window)
.await
.expect("could not serve mpris");
/*
crate::mpris::Player::setup(conn.object_server(), &window.imp().playbin)
.await
.expect("could not serve mpris player");
FIXME */
drop(window); // don't keep this alive
// always set up handlers before requesting service name
conn.request_name("org.mpris.MediaPlayer2.audrey")
.await
.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));
}
}
@ -459,6 +478,9 @@ mod imp {
impl Drop for Window {
fn drop(&mut self) {
event!(Level::DEBUG, "dropping AudreyUiWindow");
self.mpv_event_loop_handle.take().unwrap().abort();
self.zbus_executor_loop_handle.take().unwrap().abort();
}
}
}