Skip to content

Commit

Permalink
fix: notify clear together
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Aug 13, 2024
1 parent e39aedd commit 87cd96c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ resolver = "2"
members = ["./lala_bar", "./zbus_notification"]

[workspace.package]
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = ["Decodertalkers <[email protected]>"]
license = "MIT"
repository = "https://github.com/Decodetalkers/lala-bar"
readme = "README.md"

[workspace.dependencies]
zbus_notification = { version = "0.3.0", path = "zbus_notification"}
zbus_notification = { version = "0.3.1", path = "zbus_notification"}
futures = "0.3.30"
serde = { version = "1.0.204", features = ["derive"] }
url = "2.5.2"
Expand Down
2 changes: 1 addition & 1 deletion zbus_notification/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zbus_notification"
version = "0.3.0"
version = "0.3.1"
edition.workspace = true
description = "zbus binding for org.freedesktop.Notification"
authors.workspace = true
Expand Down
33 changes: 30 additions & 3 deletions zbus_notification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ pub const NOTIFICATION_CLOSED_BY_UNKNOWN_REASON: u32 = 4;
static ICON_CACHE: LazyLock<Arc<RwLock<HashMap<String, ImageInfo>>>> =
LazyLock::new(|| Arc::new(RwLock::new(HashMap::new())));

use std::hash::Hash;

use std::sync::atomic::{self, AtomicU32};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
/// The id of the window.
///
/// Internally Iced reserves `window::Id::MAIN` for the first window spawned.
struct Id(u32);

static COUNT: AtomicU32 = AtomicU32::new(0);

impl Id {
/// The reserved window [`Id`] for the first window in an Iced application.
pub const MAIN: Self = Id(0);

/// Creates a new unique window [`Id`].
pub fn unique() -> Id {
Id(COUNT.fetch_add(1, atomic::Ordering::Relaxed))
}
}

/// Describe the image information.
#[derive(Type, Debug, SerializeDict, OwnedValue, Clone)]
struct ImageData {
Expand Down Expand Up @@ -247,14 +269,19 @@ impl<T: From<NotifyMessage> + Send + 'static> LaLaMako<T> {
fn notify(
&mut self,
app_name: &str,
id: u32,
replaced_id: u32,
icon: &str,
summery: &str,
body: &str,
actions: Vec<&str>,
mut hints: std::collections::HashMap<&str, OwnedValue>,
timeout: i32,
) -> zbus::fdo::Result<u32> {
let id = if replaced_id == 0 {
Id::unique()
} else {
Id::MAIN
};
let mut image_data: Option<ImageData> =
hints.remove("image-data").and_then(|v| v.try_into().ok());
if image_data.is_none() {
Expand All @@ -268,7 +295,7 @@ impl<T: From<NotifyMessage> + Send + 'static> LaLaMako<T> {
.try_send(
NotifyMessage::UnitAdd(NotifyUnit {
app_name: app_name.to_string(),
id,
id: id.0,
icon: icon.to_string(),
summery: summery.to_string(),
body: body.to_string(),
Expand All @@ -282,7 +309,7 @@ impl<T: From<NotifyMessage> + Send + 'static> LaLaMako<T> {
.into(),
)
.ok();
Ok(0)
Ok(id.0)
}

/// Invoke Action
Expand Down

0 comments on commit 87cd96c

Please sign in to comment.