chore: updates after iced-rebase

This commit is contained in:
Ashley Wulber 2026-03-31 16:34:59 -04:00 committed by GitHub
parent bd0d180482
commit 71d9d6d5bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 1786 additions and 2396 deletions

View file

@ -16,18 +16,17 @@ use cosmic::{
Alignment, Length, Subscription,
advanced::text::{Ellipsize, EllipsizeHeightLimit},
platform_specific::shell::wayland::commands::popup::{destroy_popup, get_popup},
widget::{column, row},
widget::{self, column, row},
window,
},
surface, theme,
widget::{Column, button, container, divider, icon, scrollable, text},
widget::{Column, button, cards, container, divider, icon, scrollable, space, text, toggler},
};
use cosmic::iced_futures::futures::executor::block_on;
use cosmic_notifications_config::NotificationsConfig;
use cosmic_notifications_util::{ActionId, Image, Notification};
use cosmic_time::{Instant, Timeline, anim, chain, id};
use std::{borrow::Cow, collections::HashMap, path::PathBuf, sync::LazyLock};
use subscriptions::notifications::{self, NotificationsAppletProxy};
use tokio::sync::mpsc::Sender;
@ -38,8 +37,6 @@ pub fn run() -> cosmic::iced::Result {
cosmic::applet::run::<Notifications>(())
}
static DO_NOT_DISTURB: LazyLock<id::Toggler> = LazyLock::new(id::Toggler::unique);
struct Notifications {
core: cosmic::app::Core,
config: NotificationsConfig,
@ -47,27 +44,14 @@ struct Notifications {
icon_name: String,
popup: Option<window::Id>,
// notifications: Vec<Notification>,
timeline: Timeline,
dbus_sender: Option<Sender<subscriptions::dbus::Input>>,
cards: Vec<(id::Cards, Vec<Notification>, bool, String, String, String)>,
cards: Vec<(widget::Id, Vec<Notification>, bool, String, String, String)>,
token_tx: Option<calloop::channel::Sender<TokenRequest>>,
proxy: NotificationsAppletProxy<'static>,
notifications_tx: Option<Sender<notifications::Input>>,
}
impl Notifications {
fn update_cards(&mut self, id: id::Cards) {
if let Some((id, _, card_value, ..)) = self.cards.iter().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();
}
}
fn update_icon(&mut self) {
self.icon_name = if self.config.do_not_disturb {
"cosmic-applet-notification-disabled-symbolic"
@ -84,8 +68,7 @@ impl Notifications {
enum Message {
TogglePopup,
CloseRequested(window::Id),
DoNotDisturb(chain::Toggler, bool),
Frame(Instant),
DoNotDisturb(bool),
NotificationEvent(notifications::Output),
Config(NotificationsConfig),
DbusEvent(subscriptions::dbus::Output),
@ -128,7 +111,6 @@ impl cosmic::Application for Notifications {
config,
icon_name: String::default(),
popup: None,
timeline: Timeline::default(),
dbus_sender: Option::default(),
cards: Vec::new(),
token_tx: Option::default(),
@ -148,7 +130,7 @@ impl cosmic::Application for Notifications {
&mut self.core
}
fn style(&self) -> Option<cosmic::iced_runtime::Appearance> {
fn style(&self) -> Option<cosmic::iced::theme::Style> {
Some(cosmic::applet::style())
}
@ -162,9 +144,6 @@ impl cosmic::Application for Notifications {
}
Message::Config(res.config)
}),
self.timeline
.as_subscription()
.map(|(_, now)| Message::Frame(now)),
subscriptions::dbus::proxy().map(Message::DbusEvent),
subscriptions::notifications::notifications(self.proxy.clone())
.map(Message::NotificationEvent),
@ -174,16 +153,12 @@ impl cosmic::Application for Notifications {
fn update(&mut self, message: Self::Message) -> app::Task<Self::Message> {
match message {
Message::Frame(now) => {
self.timeline.now(now);
}
Message::TogglePopup => {
if let Some(p) = self.popup.take() {
return destroy_popup(p);
} else {
let new_id = window::Id::unique();
self.popup.replace(new_id);
self.timeline = Timeline::new();
let popup_settings = self.core.applet.get_popup_settings(
self.core.main_window_id().unwrap(),
@ -196,8 +171,7 @@ impl cosmic::Application for Notifications {
return get_popup(popup_settings);
}
}
Message::DoNotDisturb(chain, b) => {
self.timeline.set_chain(chain).start();
Message::DoNotDisturb(b) => {
self.config.do_not_disturb = b;
if let Some(helper) = &self.config_helper {
if let Err(err) = self.config.write_entry(helper) {
@ -223,7 +197,7 @@ impl cosmic::Application for Notifications {
}
} else {
self.cards.push((
id::Cards::new(n.app_name.clone()),
widget::Id::new(n.app_name.clone()),
vec![n],
false,
fl!("show-more", HashMap::from([("more", "1")])),
@ -315,7 +289,6 @@ impl cosmic::Application for Notifications {
} else {
return Task::none();
};
self.update_cards(id);
}
Message::CloseRequested(id) => {
if Some(id) == self.popup {
@ -412,15 +385,11 @@ impl cosmic::Application for Notifications {
} = theme::active().cosmic().spacing;
let do_not_disturb = padded_control(row![
anim!(
DO_NOT_DISTURB,
&self.timeline,
fl!("do-not-disturb"),
self.config.do_not_disturb,
Message::DoNotDisturb
)
.text_size(14)
.width(Length::Fill)
toggler(self.config.do_not_disturb)
.on_toggle(Message::DoNotDisturb)
.text_size(14)
.width(Length::Fill)
.label(fl!("do-not-disturb"))
]);
let notifications = if self.cards.is_empty() {
@ -522,13 +491,12 @@ impl cosmic::Application for Notifications {
Some(cosmic::widget::icon::from_name(n.app_icon.as_str()).handle())
}
});
let card_list = anim!(
let card_list = cards(
//cards
c.0.clone(),
&self.timeline,
notif_elems,
Message::ClearAll(Some(name.clone())),
Some(move |_, e| Message::CardsToggled(name.clone(), e)),
Some(move |e| Message::CardsToggled(name.clone(), e)),
Some(move |id| Message::ActivateNotification(ids[id])),
&c.3,
&c.4,
@ -536,6 +504,7 @@ impl cosmic::Application for Notifications {
show_more_icon,
c.2,
);
// let card_list = space::horizontal().width(Length::Fixed(10.));
notifs.push(card_list.into());
}