refactor: use the cards widget and use peer to peer dbus
This commit is contained in:
parent
c8273f0b4d
commit
c8891c8af9
9 changed files with 357 additions and 269 deletions
51
Cargo.lock
generated
51
Cargo.lock
generated
|
|
@ -880,7 +880,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config"
|
name = "cosmic-config"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomicwrites",
|
"atomicwrites",
|
||||||
"cosmic-config-derive",
|
"cosmic-config-derive",
|
||||||
|
|
@ -894,7 +894,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config-derive"
|
name = "cosmic-config-derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
|
|
@ -916,7 +916,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-notifications-config"
|
name = "cosmic-notifications-config"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/cosmic-notifications#5691ae9f999990b2c37f7dc38d8c04a0178c1dca"
|
source = "git+https://github.com/pop-os/cosmic-notifications#b0566b96b39d636f7228eb9daf2f3ec2ab2fa362"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
@ -925,10 +925,13 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-notifications-util"
|
name = "cosmic-notifications-util"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/cosmic-notifications#5691ae9f999990b2c37f7dc38d8c04a0178c1dca"
|
source = "git+https://github.com/pop-os/cosmic-notifications#b0566b96b39d636f7228eb9daf2f3ec2ab2fa362"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
"fast_image_resize",
|
||||||
"serde",
|
"serde",
|
||||||
|
"tracing",
|
||||||
|
"zbus",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -989,7 +992,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-theme"
|
name = "cosmic-theme"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
|
|
@ -1004,8 +1007,8 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-time"
|
name = "cosmic-time"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/pop-os/cosmic-time?rev=39c96ac#39c96ac8b3c11aeb5a4fe8bc962a89013f3f27b7"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"float-cmp",
|
||||||
"libcosmic",
|
"libcosmic",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
]
|
]
|
||||||
|
|
@ -1549,6 +1552,16 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1"
|
checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fast_image_resize"
|
||||||
|
version = "2.7.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cc789a40040e11bbe4ba31ca319406805a12fe3f8d71314bbc4bd076602ad55a"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
|
|
@ -2285,7 +2298,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced"
|
name = "iced"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2300,7 +2313,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_accessibility"
|
name = "iced_accessibility"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"accesskit",
|
"accesskit",
|
||||||
"accesskit_unix",
|
"accesskit_unix",
|
||||||
|
|
@ -2309,7 +2322,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_core"
|
name = "iced_core"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
|
|
@ -2324,7 +2337,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_futures"
|
name = "iced_futures"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2337,7 +2350,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_graphics"
|
name = "iced_graphics"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2354,7 +2367,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_renderer"
|
name = "iced_renderer"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
"iced_tiny_skia",
|
"iced_tiny_skia",
|
||||||
|
|
@ -2366,7 +2379,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_runtime"
|
name = "iced_runtime"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2378,7 +2391,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_sctk"
|
name = "iced_sctk"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"enum-repr",
|
"enum-repr",
|
||||||
"float-cmp",
|
"float-cmp",
|
||||||
|
|
@ -2400,7 +2413,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_style"
|
name = "iced_style"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_core",
|
"iced_core",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
@ -2410,7 +2423,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_tiny_skia"
|
name = "iced_tiny_skia"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cosmic-text",
|
"cosmic-text",
|
||||||
|
|
@ -2428,7 +2441,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_wgpu"
|
name = "iced_wgpu"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2449,7 +2462,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_widget"
|
name = "iced_widget"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_renderer",
|
"iced_renderer",
|
||||||
"iced_runtime",
|
"iced_runtime",
|
||||||
|
|
@ -2715,7 +2728,7 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libcosmic"
|
name = "libcosmic"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic/#56d24b2372ed699115fee777b4811c60419e2f66"
|
source = "git+https://github.com/pop-os/libcosmic/#f17d52f37f06f4d35c2feb65a5da03516d374acf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"apply",
|
"apply",
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,10 @@ libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = fa
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = "thin"
|
lto = "thin"
|
||||||
# lto = "fat"
|
# lto = "fat"
|
||||||
|
|
||||||
|
# [patch."https://github.com/pop-os/cosmic-time"]
|
||||||
|
# cosmic-time = { path = "../cosmic-time" }
|
||||||
|
# [patch."https://github.com/pop-os/libcosmic"]
|
||||||
|
# libcosmic = { path = "../libcosmic" }
|
||||||
|
# [patch."https://github.com/pop-os/cosmic-config"]
|
||||||
|
# cosmic-config = { path = "../libcosmic/cosmic-config" }
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,14 @@ nix = "0.26"
|
||||||
tokio = { version = "1.24.1", features = ["sync", "rt", "tracing", "macros", "net", "io-util", "io-std"] }
|
tokio = { version = "1.24.1", features = ["sync", "rt", "tracing", "macros", "net", "io-util", "io-std"] }
|
||||||
cosmic-notifications-util = { git = "https://github.com/pop-os/cosmic-notifications" }
|
cosmic-notifications-util = { git = "https://github.com/pop-os/cosmic-notifications" }
|
||||||
cosmic-notifications-config = { git = "https://github.com/pop-os/cosmic-notifications" }
|
cosmic-notifications-config = { git = "https://github.com/pop-os/cosmic-notifications" }
|
||||||
|
# cosmic-notifications-util = { path = "../../cosmic-notifications-daemon/cosmic-notifications-util" }
|
||||||
|
# cosmic-notifications-config = { path = "../../cosmic-notifications-daemon/cosmic-notifications-config" }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
ron = "0.8"
|
ron = "0.8"
|
||||||
sendfd = { version = "0.4", features = [ "tokio" ] }
|
sendfd = { version = "0.4", features = [ "tokio" ] }
|
||||||
bytemuck = "1"
|
bytemuck = "1"
|
||||||
tracing-subscriber = "0.3"
|
tracing-subscriber = "0.3"
|
||||||
zbus = "3.14"
|
zbus = {version = "3.14", features = [ "tokio" ]}
|
||||||
# Application i18n
|
# Application i18n
|
||||||
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
|
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
|
||||||
i18n-embed-fl = "0.6.4"
|
i18n-embed-fl = "0.6.4"
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ minutes-ago = { NUMBER($duration) ->
|
||||||
[1] 1 Minute Ago
|
[1] 1 Minute Ago
|
||||||
*[other] {$duration} Minutes Ago
|
*[other] {$duration} Minutes Ago
|
||||||
}
|
}
|
||||||
|
show-more = Show {$more} More
|
||||||
clear-all = Clear All Notifications
|
clear-all = Clear All Notifications
|
||||||
do-not-disturb = Do Not Disturb
|
do-not-disturb = Do Not Disturb
|
||||||
notification-settings = Notification Settings...
|
notification-settings = Notification Settings...
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,17 @@ use cosmic::iced::{
|
||||||
};
|
};
|
||||||
use cosmic::iced_core::alignment::Horizontal;
|
use cosmic::iced_core::alignment::Horizontal;
|
||||||
use cosmic::iced_core::image;
|
use cosmic::iced_core::image;
|
||||||
use cosmic::iced_widget::button::StyleSheet;
|
|
||||||
use cosmic_applet::{applet_button_theme, CosmicAppletHelper};
|
use cosmic_applet::{applet_button_theme, CosmicAppletHelper};
|
||||||
|
|
||||||
use cosmic::iced_style::application::{self, Appearance};
|
use cosmic::iced_style::application::{self, Appearance};
|
||||||
|
|
||||||
use cosmic::iced_widget::{horizontal_rule, scrollable, Column};
|
use cosmic::iced_widget::{horizontal_rule, scrollable, Column};
|
||||||
use cosmic::theme::{Button, Svg};
|
use cosmic::theme::Svg;
|
||||||
use cosmic::widget::{container, icon};
|
use cosmic::widget::{container, icon};
|
||||||
use cosmic::Renderer;
|
use cosmic::Renderer;
|
||||||
use cosmic::{Element, Theme};
|
use cosmic::{Element, Theme};
|
||||||
use cosmic_notifications_config::NotificationsConfig;
|
use cosmic_notifications_config::NotificationsConfig;
|
||||||
use cosmic_notifications_util::{AppletEvent, Notification};
|
use cosmic_notifications_util::Notification;
|
||||||
use cosmic_time::{anim, chain, id, once_cell::sync::Lazy, Instant, Timeline};
|
use cosmic_time::{anim, chain, id, once_cell::sync::Lazy, Instant, Timeline};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
@ -51,9 +50,24 @@ struct Notifications {
|
||||||
icon_name: String,
|
icon_name: String,
|
||||||
popup: Option<window::Id>,
|
popup: Option<window::Id>,
|
||||||
id_ctr: u128,
|
id_ctr: u128,
|
||||||
notifications: Vec<Notification>,
|
// notifications: Vec<Notification>,
|
||||||
timeline: Timeline,
|
timeline: Timeline,
|
||||||
dbus_sender: Option<Sender<subscriptions::dbus::Input>>,
|
dbus_sender: Option<Sender<subscriptions::dbus::Input>>,
|
||||||
|
cards: Vec<(id::Cards, Vec<Notification>, bool, String)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Notifications {
|
||||||
|
fn update_cards(&mut self, id: id::Cards) {
|
||||||
|
if let Some((id, _, card_value, _)) = self.cards.iter_mut().find(|c| c.0 == id) {
|
||||||
|
let chain = if *card_value {
|
||||||
|
chain::Cards::on(id.clone(), 1.)
|
||||||
|
} else {
|
||||||
|
chain::Cards::off(id.clone(), 1.)
|
||||||
|
};
|
||||||
|
self.timeline.set_chain(chain);
|
||||||
|
self.timeline.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
@ -64,11 +78,12 @@ enum Message {
|
||||||
Ignore,
|
Ignore,
|
||||||
Frame(Instant),
|
Frame(Instant),
|
||||||
Theme(Theme),
|
Theme(Theme),
|
||||||
NotificationEvent(AppletEvent),
|
NotificationEvent(Notification),
|
||||||
Config(NotificationsConfig),
|
Config(NotificationsConfig),
|
||||||
DbusEvent(subscriptions::dbus::Output),
|
DbusEvent(subscriptions::dbus::Output),
|
||||||
Dismissed(u32),
|
Dismissed(u32),
|
||||||
ClearAll,
|
ClearAll(String),
|
||||||
|
CardsToggled(String, bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for Notifications {
|
impl Application for Notifications {
|
||||||
|
|
@ -201,20 +216,31 @@ impl Application for Notifications {
|
||||||
let _ = process::Command::new("cosmic-settings notifications").spawn();
|
let _ = process::Command::new("cosmic-settings notifications").spawn();
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
Message::NotificationEvent(e) => {
|
Message::NotificationEvent(n) => {
|
||||||
match e {
|
info!("{}", &n.app_name);
|
||||||
AppletEvent::Notification(n) => {
|
if let Some(c) = self
|
||||||
self.notifications.push(n);
|
.cards
|
||||||
}
|
.iter_mut()
|
||||||
AppletEvent::Replace(n) => {
|
.find(|c| c.1.iter().any(|notif| n.app_name == notif.app_name))
|
||||||
if let Some(old) = self.notifications.iter_mut().find(|n| n.id == n.id) {
|
{
|
||||||
*old = n;
|
if let Some(notif) = c.1.iter_mut().find(|notif| n.id == notif.id) {
|
||||||
}
|
*notif = n;
|
||||||
}
|
} else {
|
||||||
AppletEvent::Closed(id) => {
|
c.1.push(n);
|
||||||
self.notifications.retain(|n| n.id != id);
|
c.3 = fl!(
|
||||||
|
"show-more",
|
||||||
|
HashMap::from_iter(vec![("more", c.1.len().saturating_sub(1))])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
self.cards.push((
|
||||||
|
id::Cards::new(n.app_name.clone()),
|
||||||
|
vec![n],
|
||||||
|
false,
|
||||||
|
fl!("show-more", HashMap::from_iter(vec![("more", "1")])),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
Message::Ignore => Command::none(),
|
Message::Ignore => Command::none(),
|
||||||
|
|
@ -223,7 +249,10 @@ impl Application for Notifications {
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
Message::Dismissed(id) => {
|
Message::Dismissed(id) => {
|
||||||
self.notifications.retain(|n| n.id != id);
|
info!("dismissed {}", id);
|
||||||
|
for c in &mut self.cards {
|
||||||
|
c.1.retain(|n| n.id != id);
|
||||||
|
}
|
||||||
if let Some(tx) = &self.dbus_sender {
|
if let Some(tx) = &self.dbus_sender {
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
|
@ -239,20 +268,51 @@ impl Application for Notifications {
|
||||||
self.dbus_sender.replace(tx);
|
self.dbus_sender.replace(tx);
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
|
subscriptions::dbus::Output::CloseEvent(id) => {
|
||||||
|
for c in &mut self.cards {
|
||||||
|
c.1.retain(|n| n.id != id);
|
||||||
|
c.3 = fl!(
|
||||||
|
"show-more",
|
||||||
|
HashMap::from_iter(vec![("more", c.1.len().saturating_sub(1))])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Command::none()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Message::ClearAll => {
|
Message::ClearAll(app_name) => {
|
||||||
for n in self.notifications.drain(..) {
|
if let Some(pos) = self
|
||||||
if let Some(tx) = &self.dbus_sender {
|
.cards
|
||||||
let tx = tx.clone();
|
.iter_mut()
|
||||||
tokio::spawn(async move {
|
.position(|c| c.1.iter().any(|notif| app_name == notif.app_name))
|
||||||
if let Err(err) =
|
{
|
||||||
tx.send(subscriptions::dbus::Input::Dismiss(n.id)).await
|
for n in self.cards.remove(pos).1 {
|
||||||
{
|
if let Some(tx) = &self.dbus_sender {
|
||||||
tracing::error!("{:?}", err);
|
let tx = tx.clone();
|
||||||
}
|
tokio::spawn(async move {
|
||||||
});
|
if let Err(err) =
|
||||||
|
tx.send(subscriptions::dbus::Input::Dismiss(n.id)).await
|
||||||
|
{
|
||||||
|
tracing::error!("{:?}", err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Command::none()
|
||||||
|
}
|
||||||
|
Message::CardsToggled(name, expanded) => {
|
||||||
|
let id = if let Some((id, _, n_expanded, _)) = self
|
||||||
|
.cards
|
||||||
|
.iter_mut()
|
||||||
|
.find(|c| c.1.iter().any(|notif| name == notif.app_name))
|
||||||
|
{
|
||||||
|
*n_expanded = expanded;
|
||||||
|
id.clone()
|
||||||
|
} else {
|
||||||
|
return Command::none();
|
||||||
|
};
|
||||||
|
self.update_cards(id);
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +338,7 @@ impl Application for Notifications {
|
||||||
let settings = row_button(vec![text(fl!("notification-settings")).into()])
|
let settings = row_button(vec![text(fl!("notification-settings")).into()])
|
||||||
.on_press(Message::Settings);
|
.on_press(Message::Settings);
|
||||||
|
|
||||||
let notifications = if self.notifications.len() == 0 {
|
let notifications = if self.cards.is_empty() {
|
||||||
row![container(
|
row![container(
|
||||||
column![text_icon(&self.icon_name, 40), "No Notifications"]
|
column![text_icon(&self.icon_name, 40), "No Notifications"]
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
|
|
@ -287,109 +347,110 @@ impl Application for Notifications {
|
||||||
.align_x(Horizontal::Center)]
|
.align_x(Horizontal::Center)]
|
||||||
.spacing(12)
|
.spacing(12)
|
||||||
} else {
|
} else {
|
||||||
let mut notifs: Vec<Element<_>> = Vec::with_capacity(self.notifications.len());
|
let mut notifs: Vec<Element<_>> = Vec::with_capacity(self.cards.len());
|
||||||
notifs.push(
|
|
||||||
column![cosmic::widget::button(Button::Text)
|
|
||||||
.custom(vec![text(fl!("clear-all")).size(14).into()])
|
|
||||||
.on_press(Message::ClearAll)]
|
|
||||||
.align_items(Alignment::End)
|
|
||||||
.width(Length::Fill)
|
|
||||||
.into(),
|
|
||||||
);
|
|
||||||
for n in self.notifications.iter().rev() {
|
|
||||||
let app_name = text(if n.app_name.len() > 24 {
|
|
||||||
Cow::from(format!(
|
|
||||||
"{:.26}...",
|
|
||||||
n.app_name.lines().next().unwrap_or_default()
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
Cow::from(&n.app_name)
|
|
||||||
})
|
|
||||||
.size(12)
|
|
||||||
.width(Length::Fill);
|
|
||||||
let urgency = n.urgency();
|
|
||||||
|
|
||||||
let duration_since = text(duration_ago_msg(n)).size(12);
|
for c in self.cards.iter().rev() {
|
||||||
|
if c.1.is_empty() {
|
||||||
notifs.push(
|
continue;
|
||||||
cosmic::widget::button(Button::Custom {
|
}
|
||||||
active: Box::new(move |t| {
|
let name = c.1[0].app_name.clone();
|
||||||
let style = if urgency > 1 {
|
let notif_elems: Vec<_> =
|
||||||
Button::Primary
|
c.1.iter()
|
||||||
} else {
|
.rev()
|
||||||
Button::Secondary
|
.map(|n| {
|
||||||
};
|
let app_name = text(if n.app_name.len() > 24 {
|
||||||
let mut a = t.active(&style);
|
|
||||||
a.border_radius = 8.0.into();
|
|
||||||
a
|
|
||||||
}),
|
|
||||||
hover: Box::new(move |t| {
|
|
||||||
let style = if urgency > 1 {
|
|
||||||
Button::Primary
|
|
||||||
} else {
|
|
||||||
Button::Secondary
|
|
||||||
};
|
|
||||||
let mut a = t.hovered(&style);
|
|
||||||
a.border_radius = 8.0.into();
|
|
||||||
a
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
.custom(vec![column!(
|
|
||||||
match n.image() {
|
|
||||||
Some(cosmic_notifications_util::Image::File(path)) => {
|
|
||||||
row![icon(path.as_path(), 16), app_name, duration_since]
|
|
||||||
.spacing(8)
|
|
||||||
.align_items(Alignment::Center)
|
|
||||||
}
|
|
||||||
Some(cosmic_notifications_util::Image::Name(name)) => {
|
|
||||||
row![icon(name.as_str(), 16), app_name, duration_since]
|
|
||||||
.spacing(8)
|
|
||||||
.align_items(Alignment::Center)
|
|
||||||
}
|
|
||||||
Some(cosmic_notifications_util::Image::Data {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
data,
|
|
||||||
}) => {
|
|
||||||
let handle =
|
|
||||||
image::Handle::from_pixels(*width, *height, data.clone());
|
|
||||||
row![icon(handle, 16), app_name, duration_since]
|
|
||||||
.spacing(8)
|
|
||||||
.align_items(Alignment::Center)
|
|
||||||
}
|
|
||||||
None => row![app_name, duration_since],
|
|
||||||
},
|
|
||||||
column![
|
|
||||||
text(if n.summary.len() > 77 {
|
|
||||||
Cow::from(format!(
|
Cow::from(format!(
|
||||||
"{:.80}...",
|
"{:.26}...",
|
||||||
n.summary.lines().next().unwrap_or_default()
|
n.app_name.lines().next().unwrap_or_default()
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Cow::from(&n.summary)
|
Cow::from(&n.app_name)
|
||||||
})
|
})
|
||||||
.width(Length::Fill)
|
|
||||||
.size(14),
|
|
||||||
text(if n.body.len() > 77 {
|
|
||||||
Cow::from(format!(
|
|
||||||
"{:.80}...",
|
|
||||||
n.body.lines().next().unwrap_or_default()
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
Cow::from(&n.body)
|
|
||||||
})
|
|
||||||
.width(Length::Fill)
|
|
||||||
.size(12)
|
.size(12)
|
||||||
]
|
.width(Length::Fill);
|
||||||
)
|
|
||||||
.spacing(8)
|
let duration_since = text(duration_ago_msg(n)).size(12);
|
||||||
.into()])
|
|
||||||
.padding(16)
|
let close_notif =
|
||||||
.on_press(Message::Dismissed(n.id))
|
button(icon("window-close-symbolic", 16).style(Svg::Symbolic))
|
||||||
.width(Length::Fill)
|
.on_press(Message::Dismissed(n.id))
|
||||||
.into(),
|
.style(cosmic::theme::Button::Text);
|
||||||
|
Element::from(
|
||||||
|
column!(
|
||||||
|
match n.image() {
|
||||||
|
Some(cosmic_notifications_util::Image::File(path)) => {
|
||||||
|
row![
|
||||||
|
icon(path.as_path(), 16),
|
||||||
|
app_name,
|
||||||
|
duration_since,
|
||||||
|
close_notif
|
||||||
|
]
|
||||||
|
.spacing(8)
|
||||||
|
.align_items(Alignment::Center)
|
||||||
|
}
|
||||||
|
Some(cosmic_notifications_util::Image::Name(name)) => {
|
||||||
|
row![
|
||||||
|
icon(name.as_str(), 16),
|
||||||
|
app_name,
|
||||||
|
duration_since,
|
||||||
|
close_notif
|
||||||
|
]
|
||||||
|
.spacing(8)
|
||||||
|
.align_items(Alignment::Center)
|
||||||
|
}
|
||||||
|
Some(cosmic_notifications_util::Image::Data {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
data,
|
||||||
|
}) => {
|
||||||
|
let handle = image::Handle::from_pixels(
|
||||||
|
*width,
|
||||||
|
*height,
|
||||||
|
data.clone(),
|
||||||
|
);
|
||||||
|
row![
|
||||||
|
icon(handle, 16),
|
||||||
|
app_name,
|
||||||
|
duration_since,
|
||||||
|
close_notif
|
||||||
|
]
|
||||||
|
.spacing(8)
|
||||||
|
.align_items(Alignment::Center)
|
||||||
|
}
|
||||||
|
None => row![app_name, duration_since, close_notif]
|
||||||
|
.spacing(8)
|
||||||
|
.align_items(Alignment::Center),
|
||||||
|
},
|
||||||
|
column![
|
||||||
|
text(n.summary.lines().next().unwrap_or_default())
|
||||||
|
.width(Length::Fill)
|
||||||
|
.size(14),
|
||||||
|
text(n.body.lines().next().unwrap_or_default())
|
||||||
|
.width(Length::Fill)
|
||||||
|
.size(12)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
.width(Length::Fill),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let card_list = anim!(
|
||||||
|
//cards
|
||||||
|
c.0.clone(),
|
||||||
|
&self.timeline,
|
||||||
|
notif_elems,
|
||||||
|
Message::ClearAll(name.clone()),
|
||||||
|
move |_, e| Message::CardsToggled(name.clone(), e),
|
||||||
|
&c.3,
|
||||||
|
"Show Less",
|
||||||
|
// &format!("Show {} More", c.1.len().saturating_sub(1)),
|
||||||
|
"Clear All",
|
||||||
|
None,
|
||||||
|
c.2,
|
||||||
);
|
);
|
||||||
|
notifs.push(card_list.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
row!(scrollable(
|
row!(scrollable(
|
||||||
Column::with_children(notifs)
|
Column::with_children(notifs)
|
||||||
.spacing(8)
|
.spacing(8)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::subscriptions::dbus_proxy::NotificationsProxy;
|
use crate::subscriptions::freedesktop_proxy::NotificationsProxy;
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::{
|
iced::{
|
||||||
futures::{self, SinkExt},
|
futures::{self, SinkExt},
|
||||||
|
|
@ -8,23 +8,25 @@ use cosmic::{
|
||||||
};
|
};
|
||||||
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
use zbus::Connection;
|
use zbus::{export::futures_util::StreamExt, Connection};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum State {
|
pub enum State {
|
||||||
Ready,
|
Ready,
|
||||||
WaitingForNotificationEvent(Connection, Receiver<Input>),
|
WaitingForNotificationEvent(NotificationsProxy<'static>, Receiver<Input>),
|
||||||
Finished,
|
Finished,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum Input {
|
pub enum Input {
|
||||||
Dismiss(u32),
|
Dismiss(u32),
|
||||||
|
CloseEvent(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Output {
|
pub enum Output {
|
||||||
Ready(Sender<Input>),
|
Ready(Sender<Input>),
|
||||||
|
CloseEvent(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn proxy() -> Subscription<Output> {
|
pub fn proxy() -> Subscription<Output> {
|
||||||
|
|
@ -45,34 +47,54 @@ pub fn proxy() -> Subscription<Output> {
|
||||||
state = State::Finished;
|
state = State::Finished;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if let Err(err) = output.send(Output::Ready(sender)).await {
|
|
||||||
error!("Failed to send sender: {}", err);
|
|
||||||
state = State::Finished;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
state = State::WaitingForNotificationEvent(conn, receiver);
|
|
||||||
}
|
|
||||||
State::WaitingForNotificationEvent(conn, rx) => {
|
|
||||||
let Ok(proxy) = NotificationsProxy::new(&conn).await else {
|
let Ok(proxy) = NotificationsProxy::new(&conn).await else {
|
||||||
error!("Failed to create proxy from session connection");
|
error!("Failed to create proxy from session connection");
|
||||||
state = State::Finished;
|
state = State::Finished;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
let tx = sender.clone();
|
||||||
match rx.recv().await {
|
if let Err(err) = output.send(Output::Ready(sender)).await {
|
||||||
Some(Input::Dismiss(id)) => {
|
error!("Failed to send sender: {}", err);
|
||||||
if let Err(err) = proxy.close_notification(id).await {
|
state = State::Finished;
|
||||||
error!("Failed to close notification: {}", err);
|
continue;
|
||||||
}
|
}
|
||||||
|
state = match proxy.receive_notification_closed().await {
|
||||||
|
Ok(mut s) => {
|
||||||
|
tokio::spawn(async move {
|
||||||
|
while let Some(msg) = s.next().await {
|
||||||
|
let Ok(id) = msg.args().map(|args| args.id) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
_ = tx.send(Input::CloseEvent(id)).await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
State::WaitingForNotificationEvent(proxy, receiver)
|
||||||
}
|
}
|
||||||
None => {
|
Err(err) => {
|
||||||
warn!("Notification event channel closed");
|
error!(
|
||||||
state = State::Finished;
|
"failed to get a stream of signals for notifications. {}",
|
||||||
continue;
|
err
|
||||||
|
);
|
||||||
|
State::Finished
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
State::WaitingForNotificationEvent(proxy, rx) => match rx.recv().await {
|
||||||
|
Some(Input::Dismiss(id)) => {
|
||||||
|
if let Err(err) = proxy.close_notification(id).await {
|
||||||
|
error!("Failed to close notification: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Some(Input::CloseEvent(id)) => {
|
||||||
|
_ = output.send(Output::CloseEvent(id)).await;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
warn!("Notification event channel closed");
|
||||||
|
state = State::Finished;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
},
|
||||||
State::Finished => {
|
State::Finished => {
|
||||||
let () = futures::future::pending().await;
|
let () = futures::future::pending().await;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
pub mod dbus;
|
pub mod dbus;
|
||||||
mod dbus_proxy;
|
mod freedesktop_proxy;
|
||||||
pub mod notifications;
|
pub mod notifications;
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,28 @@
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::{
|
iced::{futures, subscription},
|
||||||
futures::{self, SinkExt},
|
|
||||||
subscription,
|
|
||||||
},
|
|
||||||
iced_futures::Subscription,
|
iced_futures::Subscription,
|
||||||
};
|
};
|
||||||
use cosmic_notifications_util::AppletEvent;
|
use cosmic_notifications_util::Notification;
|
||||||
use sendfd::RecvWithFd;
|
use std::{
|
||||||
use std::os::unix::io::{FromRawFd, RawFd};
|
collections::HashMap,
|
||||||
use tokio::{
|
os::unix::io::{FromRawFd, RawFd},
|
||||||
io::{self, AsyncBufReadExt, BufReader},
|
};
|
||||||
net::UnixStream,
|
|
||||||
|
use tracing::{error, info};
|
||||||
|
use zbus::{
|
||||||
|
dbus_proxy,
|
||||||
|
export::futures_util::{SinkExt, StreamExt},
|
||||||
|
ConnectionBuilder,
|
||||||
};
|
};
|
||||||
use tracing::{error, info, warn};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum State {
|
pub enum State {
|
||||||
Ready,
|
Ready,
|
||||||
WaitingForDaemon(UnixStream),
|
WaitingForNotificationEvent(NotificationsAppletProxy<'static>),
|
||||||
WaitingForNotificationEvent(UnixStream),
|
|
||||||
Finished,
|
Finished,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notifications() -> Subscription<AppletEvent> {
|
pub fn notifications() -> Subscription<Notification> {
|
||||||
struct SomeWorker;
|
struct SomeWorker;
|
||||||
|
|
||||||
subscription::channel(
|
subscription::channel(
|
||||||
|
|
@ -34,97 +34,45 @@ pub fn notifications() -> Subscription<AppletEvent> {
|
||||||
loop {
|
loop {
|
||||||
match &mut state {
|
match &mut state {
|
||||||
State::Ready => {
|
State::Ready => {
|
||||||
info!("Reading COSMIC_NOTIFICATIONS env var");
|
state = match get_proxy().await {
|
||||||
let Ok(Some(raw_fd)) = std::env::var("COSMIC_NOTIFICATIONS")
|
Ok(p) => State::WaitingForNotificationEvent(p),
|
||||||
.map(|fd| fd.parse::<RawFd>().ok()) else
|
|
||||||
{
|
|
||||||
error!("Failed to parse COSMIC_NOTIFICATIONS env var");
|
|
||||||
state = State::Finished;
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
let stream = unsafe { std::os::unix::net::UnixStream::from_raw_fd(raw_fd) };
|
|
||||||
let Ok(stream) = UnixStream::from_std(stream) else {
|
|
||||||
error!("Failed to convert std stream to unix stream");
|
|
||||||
state = State::Finished;
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
state = State::WaitingForDaemon(stream);
|
|
||||||
|
|
||||||
}
|
|
||||||
State::WaitingForDaemon(stream) => {
|
|
||||||
info!("Waiting for panel to send us a stream");
|
|
||||||
if let Err(err) = stream.readable().await {
|
|
||||||
error!("Failed to wait for stream to be readable {}", err);
|
|
||||||
state = State::Finished;
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
// we are expecting a single RawFd from the panel on this stream and the applet id
|
|
||||||
let mut buf = [0u8; 4];
|
|
||||||
let mut fd_buf = [0i32; 1];
|
|
||||||
|
|
||||||
match stream.recv_with_fd(&mut buf, &mut fd_buf) {
|
|
||||||
Ok((data_cnt, fd_cnt)) => {
|
|
||||||
if data_cnt == 0 && fd_cnt == 0 {
|
|
||||||
warn!("Received EOF from panel");
|
|
||||||
state = State::Finished;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if data_cnt != 4 || fd_cnt != 1 {
|
|
||||||
error!(
|
|
||||||
"Invalid data received from panel {} {}",
|
|
||||||
data_cnt, fd_cnt
|
|
||||||
);
|
|
||||||
state = State::Finished;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let notif_stream = unsafe {
|
|
||||||
std::os::unix::net::UnixStream::from_raw_fd(fd_buf[0])
|
|
||||||
};
|
|
||||||
let Ok(notif_stream) = UnixStream::from_std(notif_stream) else {
|
|
||||||
error!("Failed to convert raw fd to unix stream");
|
|
||||||
state = State::Finished;
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
state = State::WaitingForNotificationEvent(notif_stream);
|
|
||||||
}
|
|
||||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Failed to receive fd from panel: {}", err);
|
error!("Failed to connect to notifications daemon {}", err);
|
||||||
state = State::Finished;
|
State::Finished
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
State::WaitingForNotificationEvent(proxy) => {
|
||||||
|
info!("Waiting for notification events...");
|
||||||
|
let mut signal = match proxy.receive_notify().await {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(err) => {
|
||||||
|
error!(
|
||||||
|
"failed to get a stream of signals for notifications. {}",
|
||||||
|
err
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
while let Some(msg) = signal.next().await {
|
||||||
|
info!("Notification event");
|
||||||
|
let Some(args) = msg.args().into_iter().next() else {
|
||||||
|
error!("Failed to get arguments from notification signal.");
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
let notification = Notification::new(
|
||||||
|
args.app_name,
|
||||||
|
args.id,
|
||||||
|
args.app_icon,
|
||||||
|
args.summary,
|
||||||
|
args.body,
|
||||||
|
args.actions,
|
||||||
|
args.hints,
|
||||||
|
args.expire_timeout,
|
||||||
|
);
|
||||||
|
_ = output.send(notification).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
State::WaitingForNotificationEvent(stream) => {
|
|
||||||
info!("Waiting for notification event");
|
|
||||||
let reader = BufReader::new(stream);
|
|
||||||
// todo read messages
|
|
||||||
|
|
||||||
let mut lines = reader.lines();
|
|
||||||
while let Ok(Some(line)) = lines.next_line().await {
|
|
||||||
if line.is_empty() {
|
|
||||||
warn!("Received empty line from notification stream. The notification daemon probably crashed, so we will exit.");
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
if let Ok(event) = ron::de::from_str::<AppletEvent>(line.as_str()) {
|
|
||||||
if let Err(_err) = output.send(event).await {
|
|
||||||
error!("Error sending event");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error!("Failed to deserialize event from notification stream");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
warn!("Notification stream closed. The notification daemon probably crashed, so we will exit.");
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
State::Finished => {
|
State::Finished => {
|
||||||
let () = futures::future::pending().await;
|
let () = futures::future::pending().await;
|
||||||
}
|
}
|
||||||
|
|
@ -133,3 +81,37 @@ pub fn notifications() -> Subscription<AppletEvent> {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[dbus_proxy(
|
||||||
|
default_service = "com.system76.NotificationsApplet",
|
||||||
|
interface = "com.system76.NotificationsApplet",
|
||||||
|
default_path = "/com/system76/NotificationsApplet"
|
||||||
|
)]
|
||||||
|
trait NotificationsApplet {
|
||||||
|
#[dbus_proxy(signal)]
|
||||||
|
fn notify(
|
||||||
|
&self,
|
||||||
|
app_name: &str,
|
||||||
|
id: u32,
|
||||||
|
app_icon: &str,
|
||||||
|
summary: &str,
|
||||||
|
body: &str,
|
||||||
|
actions: Vec<&str>,
|
||||||
|
hints: HashMap<&str, zbus::zvariant::Value<'_>>,
|
||||||
|
expire_timeout: i32,
|
||||||
|
) -> zbus::Result<()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_proxy() -> anyhow::Result<NotificationsAppletProxy<'static>> {
|
||||||
|
let raw_fd = std::env::var("COSMIC_NOTIFICATIONS")?;
|
||||||
|
let raw_fd = raw_fd.parse::<RawFd>()?;
|
||||||
|
|
||||||
|
let stream = unsafe { std::os::unix::net::UnixStream::from_raw_fd(raw_fd) };
|
||||||
|
stream.set_nonblocking(true)?;
|
||||||
|
let stream = tokio::net::UnixStream::from_std(stream)?;
|
||||||
|
let conn = ConnectionBuilder::socket(stream).p2p().build().await?;
|
||||||
|
info!("Applet connection created");
|
||||||
|
let proxy = NotificationsAppletProxy::new(&conn).await?;
|
||||||
|
|
||||||
|
Ok(proxy)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue