audrey/src/mpris.rs
2024-11-06 13:10:39 +01:00

102 lines
2.1 KiB
Rust

mod player;
pub use player::Player;
use adw::prelude::*;
use gtk::glib;
use tracing::{event, Level};
pub struct Mpris {
window: glib::SendWeakRef<crate::ui::Window>,
}
impl Mpris {
pub async fn setup(
object_server: &zbus::ObjectServer,
window: &crate::ui::Window,
) -> Result<(), zbus::Error> {
let mpris = Self {
window: window.downgrade().into(),
};
object_server.at("/org/mpris/MediaPlayer2", mpris).await?;
//let _mpris = object_server.interface::<_, Self>("/org/mpris/MediaPlayer2").await?;
Ok(())
}
}
#[zbus::interface(name = "org.mpris.MediaPlayer2")]
impl Mpris {
fn raise(&self) {
self.window
.upgrade()
.expect("main window was finalized")
.present();
}
fn quit(&self) {
match self.window.upgrade() {
None => {} // guess there's nothing to do
Some(window) => window.close(),
}
}
#[zbus(property)]
fn can_quit(&self) -> bool {
true
}
#[zbus(property)]
fn fullscreen(&self) -> bool {
false
}
#[zbus(property)]
// TODO: report that if the argument is just _ the attribute panics
// TODO: why can't this return zbus::fdo::Result??
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![]
}
#[zbus(property)]
fn supported_mime_types(&self) -> Vec<String> {
vec![]
}
}
impl Drop for Mpris {
fn drop(&mut self) {
event!(Level::DEBUG, "dropping Mpris");
}
}