Compare commits

..

No commits in common. "56d4057d87113370df32e852974adfbae9a16275" and "e1af99648203fd99a1f3418cbbed3f2a479b42e5" have entirely different histories.

View file

@ -2,31 +2,57 @@ mod player;
pub use player::Player; pub use player::Player;
use adw::prelude::*; use adw::prelude::*;
use async_channel::Sender;
use gtk::glib; use gtk::glib;
pub struct Mpris { pub struct Mpris {
window: glib::SendWeakRef<crate::ui::Window>, // needs to be Send, so can't store handle to the window...
raise_send: Sender<()>,
quit_send: Sender<()>,
} }
impl Mpris { impl Mpris {
pub fn new(window: &crate::ui::Window) -> Self { pub fn new(window: &crate::ui::Window) -> Self {
let (raise_send, raise_recv) = async_channel::bounded(1);
let (quit_send, quit_recv) = async_channel::bounded(1);
glib::spawn_future_local(glib::clone!(
#[weak]
window,
async move {
while let Ok(()) = raise_recv.recv().await {
window.present();
}
}
));
glib::spawn_future_local(glib::clone!(
#[weak]
window,
async move {
while let Ok(()) = quit_recv.recv().await {
window.close();
}
}
));
Self { Self {
window: window.downgrade().into(), raise_send: raise_send,
quit_send: quit_send,
} }
} }
} }
#[zbus::interface(name = "org.mpris.MediaPlayer2")] #[zbus::interface(name = "org.mpris.MediaPlayer2")]
impl Mpris { impl Mpris {
fn raise(&self) { async fn raise(&self) {
self.window.upgrade().expect("main window was finalized").present(); // FIXME: don't unwrap
self.raise_send.send(()).await.unwrap()
} }
fn quit(&self) { async fn quit(&self) {
match self.window.upgrade() { // FIXME: don't unwrap
None => {}, // guess there's nothing to do self.quit_send.send(()).await.unwrap()
Some(window) => window.close(),
}
} }
#[zbus(property)] #[zbus(property)]
@ -41,8 +67,7 @@ impl Mpris {
#[zbus(property)] #[zbus(property)]
// TODO: report that if the argument is just _ the attribute panics // TODO: report that if the argument is just _ the attribute panics
// TODO: why can't this return zbus::fdo::Result?? async fn set_fullscreen(&self, _fullscreen: bool) -> zbus::Result<()> {
fn set_fullscreen(&self, _fullscreen: bool) -> zbus::Result<()> {
Err(zbus::Error::Unsupported) Err(zbus::Error::Unsupported)
} }