Add proxy for the Settings portal (dark mode, reduced motion, etc.)

This commit is contained in:
Val Packett 2025-12-12 04:37:46 -03:00
parent 1d931ae191
commit df832a5141
3 changed files with 92 additions and 5 deletions

View file

@ -1,3 +1,4 @@
pub mod documents;
pub mod file_chooser;
pub mod request;
pub mod settings;

View file

@ -0,0 +1,66 @@
use std::collections::HashMap;
use tokio_stream::StreamExt;
use tracing::warn;
use zbus::{Connection, fdo::Result, object_server::SignalEmitter, zvariant};
#[derive(Clone)]
pub struct Settings {
host: SettingsProxy<'static>,
}
#[zbus::interface(
name = "org.freedesktop.portal.Settings",
proxy(
default_service = "org.freedesktop.portal.Desktop",
default_path = "/org/freedesktop/portal/desktop"
)
)]
impl Settings {
async fn read(&self, namespace: &str, key: &str) -> Result<zvariant::OwnedValue> {
self.host.read(namespace, key).await
}
async fn read_all(
&self,
namespaces: Vec<&str>,
) -> Result<HashMap<String, HashMap<String, zvariant::OwnedValue>>> {
self.host.read_all(namespaces).await
}
async fn read_one(&self, namespace: &str, key: &str) -> Result<zvariant::OwnedValue> {
self.host.read_one(namespace, key).await
}
/// SettingChanged signal
#[zbus(signal)]
async fn setting_changed(
signal_emitter: &SignalEmitter<'_>,
namespace: &str,
key: &str,
value: zvariant::Value<'_>,
) -> zbus::Result<()>;
#[zbus(property, name = "version")]
async fn version(&self) -> Result<u32> {
Ok(2)
}
}
impl Settings {
pub(crate) async fn new(host_session_conn: &Connection) -> Result<Self> {
let host = SettingsProxy::builder(host_session_conn).build().await?;
Ok(Self { host })
}
pub async fn forward_changes(&self, signal_emitter: &SignalEmitter<'static>) -> Result<()> {
let mut stream = self.host.receive_setting_changed().await?;
while let Some(x) = stream.next().await {
let args = x.args()?;
Settings::setting_changed(signal_emitter, args.namespace, args.key, args.value).await?;
()
}
warn!("settings change stream end");
Ok(())
}
}