Skip to content

Commit

Permalink
desktop/settings: Expose a way to listen to specific settings changes
Browse files Browse the repository at this point in the history
Needed for a use case in bustle
  • Loading branch information
bilelmoussaoui committed Aug 16, 2023
1 parent 2a92f94 commit bae40f3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/desktop/settings.rs
Expand Up @@ -209,4 +209,37 @@ impl<'a> Settings<'a> {
pub async fn receive_setting_changed(&self) -> Result<impl Stream<Item = Setting>, Error> {
self.0.signal("SettingChanged").await
}

/// Similar to (receive_setting_changed)[Self::receive_setting_changed]
/// but allows you to filter specific settings.
///
/// # Example
/// ```rust,no_run
/// use ashpd::desktop::settings::{Settings, ColorScheme};
/// use futures_util::StreamExt;
///
/// async fn run() -> ashpd::Result<()> {
/// let settings = Settings::new().await?;
/// while let Some(setting) = settings
/// .receive_setting_changed_with_args(&[
/// (0, "org.freedesktop.appearance"),
/// (1, "color-scheme"),
/// ])
/// .await?
/// .next().await
/// {
/// assert_eq!(setting.namespace(), "org.freedesktop.appearance");
/// assert_eq!(setting.key(), "color-scheme");
/// assert!(ColorScheme::try_from(setting.value().to_owned()).is_ok());
/// }
/// Ok(())
/// }

/// ```
pub async fn receive_setting_changed_with_args(
&self,
args: &[(u8, &str)],
) -> Result<impl Stream<Item = Setting>, Error> {
self.0.signal_with_args("SettingChanged", args).await
}
}

0 comments on commit bae40f3

Please sign in to comment.