Skip to content

Commit

Permalink
Add receive_color_scheme_changed_with_init (#153)
Browse files Browse the repository at this point in the history
* Revert "Cargo fmt"

This reverts commit 1441894.

* Revert "Remove unused"

This reverts commit a1c538d.

* Revert "Remove receive_color_scheme_changed_with_init"

This reverts commit 4ba6336.

* Simplify receive color scheme
  • Loading branch information
d2weber authored Aug 11, 2023
1 parent 230bde9 commit d54d0ef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/desktop/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
//! }
//! ```

use std::future::ready;
use std::{collections::HashMap, convert::TryFrom, fmt::Debug};

use futures_util::Stream;
use futures_util::{Stream, StreamExt};
use serde::{Deserialize, Serialize};
use zbus::zvariant::{OwnedValue, Type, Value};

Expand Down Expand Up @@ -186,6 +187,20 @@ impl<'a> Settings<'a> {
.await
}

/// Listen to changes of the system's preferred color scheme
pub async fn receive_color_scheme_changed(
&self,
) -> Result<impl Stream<Item = ColorScheme>, Error> {
Ok(self
.0
.signal_with_args::<Setting>(
"SettingChanged",
&[(0, APPEARANCE_NAMESPACE), (1, COLOR_SCHEME_KEY)],
)
.await?
.filter_map(|x| ready(ColorScheme::try_from(x).ok())))
}

/// Signal emitted when a setting changes.
///
/// # Specifications
Expand Down
25 changes: 25 additions & 0 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,31 @@ impl<'a> Proxy<'a> {
.map_err(From::from)
}

pub(crate) async fn signal_with_args<I>(
&self,
name: &'static str,
args: &[(u8, &str)],
) -> Result<impl Stream<Item = I>, Error>
where
I: for<'de> Deserialize<'de> + Type + Debug,
{
Ok(self
.0
.receive_signal_with_args(name, args)
.await?
.filter_map({
#[cfg(not(feature = "tracing"))]
{
move |msg| ready(msg.body().ok())
}
#[cfg(feature = "tracing")]
{
let ifc = self.interface().to_owned();
move |msg| ready(trace_body(name, &ifc, msg))
}
}))
}

pub(crate) async fn signal<I>(&self, name: &'static str) -> Result<impl Stream<Item = I>, Error>
where
I: for<'de> Deserialize<'de> + Type + Debug,
Expand Down

0 comments on commit d54d0ef

Please sign in to comment.