Compare commits
2 commits
e1af996482
...
56d4057d87
Author | SHA1 | Date | |
---|---|---|---|
56d4057d87 | |||
62c71dbd26 |
1 changed files with 11 additions and 36 deletions
47
src/mpris.rs
47
src/mpris.rs
|
@ -2,57 +2,31 @@ mod player;
|
|||
pub use player::Player;
|
||||
|
||||
use adw::prelude::*;
|
||||
use async_channel::Sender;
|
||||
use gtk::glib;
|
||||
|
||||
pub struct Mpris {
|
||||
// needs to be Send, so can't store handle to the window...
|
||||
raise_send: Sender<()>,
|
||||
quit_send: Sender<()>,
|
||||
window: glib::SendWeakRef<crate::ui::Window>,
|
||||
}
|
||||
|
||||
impl Mpris {
|
||||
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 {
|
||||
raise_send: raise_send,
|
||||
quit_send: quit_send,
|
||||
window: window.downgrade().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[zbus::interface(name = "org.mpris.MediaPlayer2")]
|
||||
impl Mpris {
|
||||
async fn raise(&self) {
|
||||
// FIXME: don't unwrap
|
||||
self.raise_send.send(()).await.unwrap()
|
||||
fn raise(&self) {
|
||||
self.window.upgrade().expect("main window was finalized").present();
|
||||
}
|
||||
|
||||
async fn quit(&self) {
|
||||
// FIXME: don't unwrap
|
||||
self.quit_send.send(()).await.unwrap()
|
||||
fn quit(&self) {
|
||||
match self.window.upgrade() {
|
||||
None => {}, // guess there's nothing to do
|
||||
Some(window) => window.close(),
|
||||
}
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
|
@ -67,7 +41,8 @@ impl Mpris {
|
|||
|
||||
#[zbus(property)]
|
||||
// TODO: report that if the argument is just _ the attribute panics
|
||||
async fn set_fullscreen(&self, _fullscreen: bool) -> zbus::Result<()> {
|
||||
// TODO: why can't this return zbus::fdo::Result??
|
||||
fn set_fullscreen(&self, _fullscreen: bool) -> zbus::Result<()> {
|
||||
Err(zbus::Error::Unsupported)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue