holy fruck there's actually a way
im sorry i ever doubted u gtkrs
This commit is contained in:
parent
e1af996482
commit
62c71dbd26
1 changed files with 6 additions and 33 deletions
39
src/mpris.rs
39
src/mpris.rs
|
@ -2,43 +2,16 @@ 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 {
|
||||||
// needs to be Send, so can't store handle to the window...
|
window: glib::SendWeakRef<crate::ui::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 {
|
||||||
raise_send: raise_send,
|
window: window.downgrade().into(),
|
||||||
quit_send: quit_send,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,13 +19,13 @@ impl Mpris {
|
||||||
#[zbus::interface(name = "org.mpris.MediaPlayer2")]
|
#[zbus::interface(name = "org.mpris.MediaPlayer2")]
|
||||||
impl Mpris {
|
impl Mpris {
|
||||||
async fn raise(&self) {
|
async fn raise(&self) {
|
||||||
// FIXME: don't unwrap
|
// TODO: don't unwrap
|
||||||
self.raise_send.send(()).await.unwrap()
|
self.window.upgrade().unwrap().present();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn quit(&self) {
|
async fn quit(&self) {
|
||||||
// FIXME: don't unwrap
|
// TODO: don't unwrap
|
||||||
self.quit_send.send(()).await.unwrap()
|
self.window.upgrade().unwrap().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
|
|
Loading…
Reference in a new issue