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::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;
@ -246,7 +254,15 @@ mod imp {
// ^ ignore // ^ ignore
} }
Event::Seek => {
event!(Level::INFO, "seek event");
// TODO: if doing "buffering" progress bar, show it after a timeout here
}
Event::PlaybackRestart => { 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() { if let Some(queued_seek) = window.imp().queued_seek.take() {
// a seek was tried before and failed, try again now // a seek was tried before and failed, try again now
event!(Level::INFO, "performing queued seek to {queued_seek}"); event!(Level::INFO, "performing queued seek to {queued_seek}");
@ -255,6 +271,8 @@ mod imp {
} }
Event::EndFile(event) => { Event::EndFile(event) => {
event!(Level::INFO, "end file event: {event:?}");
if let Err(err) = event.reason { if let Err(err) = event.reason {
event!(Level::ERROR, "end file error: {err}"); event!(Level::ERROR, "end file error: {err}");
} }
@ -270,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)
@ -281,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");
@ -301,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));
} }
} }
@ -459,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();
} }
} }
} }