Compare commits
No commits in common. "226c8073d476bb1273f199d718199d5dd4e1a88a" and "d3641a6f339e56048d3a090a00be618708e942d5" have entirely different histories.
226c8073d4
...
d3641a6f33
1 changed files with 22 additions and 44 deletions
|
@ -4,7 +4,6 @@ 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;
|
||||||
|
@ -55,9 +54,6 @@ 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 {
|
||||||
|
@ -103,9 +99,6 @@ 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(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,9 +125,8 @@ mod imp {
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
|
|
||||||
let window = self.obj().downgrade();
|
let window = self.obj().downgrade();
|
||||||
let mpv_event_loop_handle = glib::spawn_future_local(async move {
|
glib::spawn_future_local(async move {
|
||||||
loop {
|
while let Some(window) = window.upgrade() {
|
||||||
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;
|
||||||
|
@ -254,15 +246,7 @@ 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}");
|
||||||
|
@ -271,8 +255,6 @@ 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}");
|
||||||
}
|
}
|
||||||
|
@ -288,11 +270,10 @@ 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();
|
||||||
let zbus_executor_loop_handle = glib::spawn_future_local(async move {
|
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)
|
||||||
|
@ -300,10 +281,17 @@ 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");
|
||||||
|
@ -313,20 +301,13 @@ 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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,9 +459,6 @@ 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