use super::DESTINATION;
use crate::{
helpers::{call_method, receive_signal},
Error, WindowIdentifier,
};
use serde_repr::{Deserialize_repr, Serialize_repr};
use zvariant::ObjectPath;
use zvariant_derive::{DeserializeDict, SerializeDict, Type, TypeDict};
#[derive(SerializeDict, DeserializeDict, TypeDict, Debug, Default)]
struct UpdateOptions {}
#[derive(SerializeDict, DeserializeDict, TypeDict, Debug)]
pub struct UpdateInfo {
#[zvariant(rename = "running-commit")]
pub running_commit: String,
#[zvariant(rename = "local-commit")]
pub local_commit: String,
#[zvariant(rename = "remote-commit")]
pub remote_commit: String,
}
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Copy, Clone, Debug, Type)]
#[repr(u32)]
pub enum UpdateStatus {
Running = 0,
Empty = 1,
Done = 2,
Failed = 3,
}
#[derive(SerializeDict, DeserializeDict, TypeDict, Debug)]
pub struct UpdateProgress {
pub n_ops: Option<u32>,
pub op: Option<u32>,
pub progress: Option<u32>,
pub status: Option<UpdateStatus>,
pub error: Option<String>,
pub error_message: Option<String>,
}
#[derive(Debug)]
#[doc(alias = "org.freedesktop.portal.Flatpak.UpdateMonitor")]
pub struct UpdateMonitorProxy<'a>(zbus::azync::Proxy<'a>);
impl<'a> UpdateMonitorProxy<'a> {
pub(crate) async fn new(
connection: &zbus::azync::Connection,
path: ObjectPath<'a>,
) -> Result<UpdateMonitorProxy<'a>, Error> {
let proxy = zbus::ProxyBuilder::new_bare(connection)
.interface("org.freedesktop.portal.Flatpak.UpdateMonitor")
.path(path)?
.destination(DESTINATION)
.build_async()
.await?;
Ok(Self(proxy))
}
pub fn inner(&self) -> &zbus::azync::Proxy<'_> {
&self.0
}
#[doc(alias = "Progress")]
pub async fn receive_progress(&self) -> Result<UpdateProgress, Error> {
receive_signal(&self.0, "Progress").await
}
#[doc(alias = "UpdateAvailable")]
pub async fn receive_update_available(&self) -> Result<UpdateInfo, Error> {
receive_signal(&self.0, "UpdateAvailable").await
}
#[doc(alias = "Update")]
pub async fn update(&self, identifier: WindowIdentifier) -> Result<(), Error> {
let options = UpdateOptions::default();
call_method(&self.0, "Update", &(identifier, options)).await
}
#[doc(alias = "Close")]
pub async fn close(&self) -> Result<(), Error> {
call_method(&self.0, "Close", &()).await
}
}