use serde::Serialize;
use zbus::zvariant;
use crate::{AppID, Error, proxy::Proxy};
#[derive(Debug, Serialize, zvariant::Type, Default)]
#[zvariant(signature = "dict")]
struct RegisterOptions {}
struct RegistryProxy(Proxy<'static>);
impl RegistryProxy {
pub async fn new() -> Result<Self, Error> {
let proxy = Proxy::new_desktop("org.freedesktop.host.portal.Registry").await?;
Ok(Self(proxy))
}
pub async fn with_connection(connection: zbus::Connection) -> Result<Self, Error> {
let proxy =
Proxy::new_desktop_with_connection(connection, "org.freedesktop.host.portal.Registry")
.await?;
Ok(Self(proxy))
}
pub async fn register(&self, app_id: AppID, options: RegisterOptions) -> Result<(), Error> {
self.0.call_method("Register", &(&app_id, &options)).await?;
Ok(())
}
}
impl std::ops::Deref for RegistryProxy {
type Target = zbus::Proxy<'static>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
pub async fn register_host_app(app_id: AppID) -> crate::Result<()> {
if crate::is_sandboxed() {
return Ok(());
}
let proxy = RegistryProxy::new().await?;
proxy.register(app_id, Default::default()).await?;
Ok(())
}
pub async fn register_host_app_with_connection(
connection: zbus::Connection,
app_id: AppID,
) -> crate::Result<()> {
if crate::is_sandboxed() {
return Ok(());
}
let proxy = RegistryProxy::with_connection(connection).await?;
proxy.register(app_id, Default::default()).await?;
Ok(())
}