2024-10-30 09:06:10 +00:00
|
|
|
mod player;
|
|
|
|
pub use player::Player;
|
|
|
|
|
2024-11-01 11:11:49 +00:00
|
|
|
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<()>,
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2024-10-30 09:06:10 +00:00
|
|
|
|
2024-11-01 11:11:49 +00:00
|
|
|
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,
|
|
|
|
}
|
2024-10-30 09:06:10 +00:00
|
|
|
}
|
2024-11-01 11:11:49 +00:00
|
|
|
}
|
2024-10-30 09:06:10 +00:00
|
|
|
|
2024-11-01 11:11:49 +00:00
|
|
|
#[zbus::interface(name = "org.mpris.MediaPlayer2")]
|
|
|
|
impl Mpris {
|
|
|
|
async fn raise(&self) {
|
|
|
|
// FIXME: don't unwrap
|
|
|
|
self.raise_send.send(()).await.unwrap()
|
2024-10-30 09:06:10 +00:00
|
|
|
}
|
|
|
|
|
2024-11-01 11:11:49 +00:00
|
|
|
async fn quit(&self) {
|
|
|
|
// FIXME: don't unwrap
|
|
|
|
self.quit_send.send(()).await.unwrap()
|
2024-10-30 09:06:10 +00:00
|
|
|
}
|
|
|
|
|
2024-11-01 11:11:49 +00:00
|
|
|
#[zbus(property)]
|
|
|
|
fn can_quit(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
2024-10-30 09:06:10 +00:00
|
|
|
|
2024-11-01 11:11:49 +00:00
|
|
|
#[zbus(property)]
|
|
|
|
fn fullscreen(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
#[zbus(property)]
|
|
|
|
// TODO: report that if the argument is just _ the attribute panics
|
|
|
|
async fn set_fullscreen(&self, _fullscreen: bool) -> zbus::Result<()> {
|
|
|
|
Err(zbus::Error::Unsupported)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[zbus(property)]
|
|
|
|
fn can_set_fullscreen(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
#[zbus(property)]
|
|
|
|
fn can_raise(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
#[zbus(property)]
|
|
|
|
fn has_track_list(&self) -> bool {
|
|
|
|
false // TODO?
|
|
|
|
}
|
|
|
|
|
|
|
|
#[zbus(property)]
|
|
|
|
fn identity(&self) -> String {
|
|
|
|
"audrey".to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[zbus(property)]
|
|
|
|
fn desktop_entry(&self) -> String {
|
|
|
|
crate::APP_ID.to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[zbus(property)]
|
|
|
|
fn supported_uri_schemes(&self) -> Vec<String> {
|
|
|
|
vec![]
|
|
|
|
}
|
2024-10-30 09:06:10 +00:00
|
|
|
|
2024-11-01 11:11:49 +00:00
|
|
|
#[zbus(property)]
|
|
|
|
fn supported_mime_types(&self) -> Vec<String> {
|
|
|
|
vec![]
|
2024-10-30 09:06:10 +00:00
|
|
|
}
|
|
|
|
}
|