2023-07-05 14:38:48 -04:00
|
|
|
mod localize;
|
2023-06-30 16:27:45 -04:00
|
|
|
mod subscriptions;
|
|
|
|
|
|
2023-07-03 14:53:45 -04:00
|
|
|
use cosmic::cosmic_config::{config_subscription, Config, CosmicConfigEntry};
|
2023-06-01 12:23:12 -04:00
|
|
|
use cosmic::iced::wayland::popup::{destroy_popup, get_popup};
|
2023-07-05 18:23:49 -04:00
|
|
|
use cosmic::iced::Limits;
|
2022-12-22 15:16:22 -07:00
|
|
|
use cosmic::iced::{
|
2023-07-11 17:24:03 -04:00
|
|
|
widget::{button, column, row, text, Row},
|
2022-12-22 15:16:22 -07:00
|
|
|
window, Alignment, Application, Color, Command, Length, Subscription,
|
|
|
|
|
};
|
2023-07-05 14:38:48 -04:00
|
|
|
use cosmic::iced_core::alignment::Horizontal;
|
2023-07-05 18:23:49 -04:00
|
|
|
use cosmic::iced_core::image;
|
2023-06-01 12:23:12 -04:00
|
|
|
use cosmic_applet::{applet_button_theme, CosmicAppletHelper};
|
2022-12-22 15:16:22 -07:00
|
|
|
|
|
|
|
|
use cosmic::iced_style::application::{self, Appearance};
|
2023-03-01 10:06:14 -08:00
|
|
|
|
2023-07-11 17:24:03 -04:00
|
|
|
use cosmic::iced_widget::{horizontal_rule, scrollable, Column};
|
2023-07-20 17:55:43 -04:00
|
|
|
use cosmic::theme::Svg;
|
2023-07-11 17:24:03 -04:00
|
|
|
use cosmic::widget::{container, icon};
|
2022-12-22 15:16:22 -07:00
|
|
|
use cosmic::Renderer;
|
|
|
|
|
use cosmic::{Element, Theme};
|
2023-07-03 14:53:45 -04:00
|
|
|
use cosmic_notifications_config::NotificationsConfig;
|
2023-07-20 17:55:43 -04:00
|
|
|
use cosmic_notifications_util::Notification;
|
2023-06-07 13:43:49 -06:00
|
|
|
use cosmic_time::{anim, chain, id, once_cell::sync::Lazy, Instant, Timeline};
|
2023-07-03 14:53:45 -04:00
|
|
|
use std::borrow::Cow;
|
2023-07-05 14:38:48 -04:00
|
|
|
use std::collections::HashMap;
|
2022-12-22 15:16:22 -07:00
|
|
|
use std::process;
|
2023-07-03 14:53:45 -04:00
|
|
|
use tokio::sync::mpsc::Sender;
|
|
|
|
|
use tracing::info;
|
2022-12-22 15:16:22 -07:00
|
|
|
|
2023-07-03 14:53:45 -04:00
|
|
|
#[tokio::main(flavor = "current_thread")]
|
|
|
|
|
pub async fn main() -> cosmic::iced::Result {
|
2023-06-30 16:27:45 -04:00
|
|
|
tracing_subscriber::fmt::init();
|
2023-07-05 14:38:48 -04:00
|
|
|
// Prepare i18n
|
|
|
|
|
localize::localize();
|
2023-06-30 16:27:45 -04:00
|
|
|
|
|
|
|
|
info!("Notifications applet");
|
|
|
|
|
|
2022-12-22 15:16:22 -07:00
|
|
|
let helper = CosmicAppletHelper::default();
|
|
|
|
|
Notifications::run(helper.window_settings())
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-07 13:43:49 -06:00
|
|
|
static DO_NOT_DISTURB: Lazy<id::Toggler> = Lazy::new(id::Toggler::unique);
|
2022-12-22 15:16:22 -07:00
|
|
|
#[derive(Default)]
|
|
|
|
|
struct Notifications {
|
|
|
|
|
applet_helper: CosmicAppletHelper,
|
|
|
|
|
theme: Theme,
|
2023-07-03 14:53:45 -04:00
|
|
|
config: NotificationsConfig,
|
|
|
|
|
config_helper: Option<Config>,
|
2022-12-22 15:16:22 -07:00
|
|
|
icon_name: String,
|
|
|
|
|
popup: Option<window::Id>,
|
2023-06-01 12:23:12 -04:00
|
|
|
id_ctr: u128,
|
2023-07-20 17:55:43 -04:00
|
|
|
// notifications: Vec<Notification>,
|
2023-06-07 13:43:49 -06:00
|
|
|
timeline: Timeline,
|
2023-07-03 14:53:45 -04:00
|
|
|
dbus_sender: Option<Sender<subscriptions::dbus::Input>>,
|
2023-07-20 17:55:43 -04:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-22 15:16:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
enum Message {
|
|
|
|
|
TogglePopup,
|
2023-06-07 13:43:49 -06:00
|
|
|
DoNotDisturb(chain::Toggler, bool),
|
2022-12-22 15:16:22 -07:00
|
|
|
Settings,
|
|
|
|
|
Ignore,
|
2023-06-07 13:43:49 -06:00
|
|
|
Frame(Instant),
|
2023-06-09 16:10:20 -04:00
|
|
|
Theme(Theme),
|
2023-07-20 17:55:43 -04:00
|
|
|
NotificationEvent(Notification),
|
2023-07-03 14:53:45 -04:00
|
|
|
Config(NotificationsConfig),
|
|
|
|
|
DbusEvent(subscriptions::dbus::Output),
|
|
|
|
|
Dismissed(u32),
|
2023-07-20 17:55:43 -04:00
|
|
|
ClearAll(String),
|
|
|
|
|
CardsToggled(String, bool),
|
2022-12-22 15:16:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Application for Notifications {
|
|
|
|
|
type Message = Message;
|
|
|
|
|
type Theme = Theme;
|
2023-01-18 16:51:30 -08:00
|
|
|
type Executor = cosmic::SingleThreadExecutor;
|
2022-12-22 15:16:22 -07:00
|
|
|
type Flags = ();
|
|
|
|
|
|
|
|
|
|
fn new(_flags: ()) -> (Notifications, Command<Message>) {
|
2023-06-09 16:10:20 -04:00
|
|
|
let applet_helper = CosmicAppletHelper::default();
|
|
|
|
|
let theme = applet_helper.theme();
|
2023-07-03 14:53:45 -04:00
|
|
|
let helper = Config::new(
|
|
|
|
|
cosmic_notifications_config::ID,
|
|
|
|
|
NotificationsConfig::version(),
|
|
|
|
|
)
|
|
|
|
|
.ok();
|
|
|
|
|
|
|
|
|
|
let config: NotificationsConfig = helper
|
|
|
|
|
.as_ref()
|
|
|
|
|
.map(|helper| {
|
|
|
|
|
NotificationsConfig::get_entry(helper).unwrap_or_else(|(errors, config)| {
|
|
|
|
|
for err in errors {
|
|
|
|
|
tracing::error!("{:?}", err);
|
|
|
|
|
}
|
|
|
|
|
config
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.unwrap_or_default();
|
2022-12-22 15:16:22 -07:00
|
|
|
(
|
|
|
|
|
Notifications {
|
2023-06-09 16:10:20 -04:00
|
|
|
applet_helper,
|
|
|
|
|
theme,
|
2022-12-22 15:16:22 -07:00
|
|
|
icon_name: "notification-alert-symbolic".to_string(),
|
2023-07-03 14:53:45 -04:00
|
|
|
config_helper: helper,
|
|
|
|
|
config,
|
2022-12-22 15:16:22 -07:00
|
|
|
..Default::default()
|
|
|
|
|
},
|
|
|
|
|
Command::none(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn title(&self) -> String {
|
|
|
|
|
String::from("Notifications")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn theme(&self) -> Theme {
|
2023-06-01 12:23:12 -04:00
|
|
|
self.theme.clone()
|
2022-12-22 15:16:22 -07:00
|
|
|
}
|
|
|
|
|
|
2023-04-05 20:40:22 -04:00
|
|
|
fn close_requested(&self, _id: window::Id) -> Self::Message {
|
2022-12-22 15:16:22 -07:00
|
|
|
Message::Ignore
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
2023-06-01 12:23:12 -04:00
|
|
|
<Self::Theme as application::StyleSheet>::Style::Custom(Box::new(|theme| Appearance {
|
2022-12-22 15:16:22 -07:00
|
|
|
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
|
|
|
|
text_color: theme.cosmic().on_bg_color().into(),
|
2023-06-01 12:23:12 -04:00
|
|
|
}))
|
2022-12-22 15:16:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn subscription(&self) -> Subscription<Message> {
|
2023-06-09 16:10:20 -04:00
|
|
|
Subscription::batch(vec![
|
|
|
|
|
self.applet_helper.theme_subscription(0).map(Message::Theme),
|
2023-07-03 14:53:45 -04:00
|
|
|
config_subscription::<u64, NotificationsConfig>(
|
|
|
|
|
0,
|
|
|
|
|
cosmic_notifications_config::ID.into(),
|
|
|
|
|
NotificationsConfig::version(),
|
|
|
|
|
)
|
|
|
|
|
.map(|(_, res)| match res {
|
|
|
|
|
Ok(config) => Message::Config(config),
|
|
|
|
|
Err((errors, config)) => {
|
|
|
|
|
for err in errors {
|
|
|
|
|
tracing::error!("{:?}", err);
|
|
|
|
|
}
|
|
|
|
|
Message::Config(config)
|
|
|
|
|
}
|
|
|
|
|
}),
|
2023-06-15 15:03:06 -04:00
|
|
|
self.timeline
|
|
|
|
|
.as_subscription()
|
|
|
|
|
.map(|(_, now)| Message::Frame(now)),
|
2023-07-03 14:53:45 -04:00
|
|
|
subscriptions::dbus::proxy().map(Message::DbusEvent),
|
|
|
|
|
subscriptions::notifications::notifications().map(Message::NotificationEvent),
|
2023-06-09 16:10:20 -04:00
|
|
|
])
|
2022-12-22 15:16:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn update(&mut self, message: Message) -> Command<Message> {
|
|
|
|
|
match message {
|
2023-06-09 16:10:20 -04:00
|
|
|
Message::Theme(t) => {
|
|
|
|
|
self.theme = t;
|
|
|
|
|
Command::none()
|
|
|
|
|
}
|
2023-06-07 13:43:49 -06:00
|
|
|
Message::Frame(now) => {
|
|
|
|
|
self.timeline.now(now);
|
|
|
|
|
Command::none()
|
|
|
|
|
}
|
2022-12-22 15:16:22 -07:00
|
|
|
Message::TogglePopup => {
|
|
|
|
|
if let Some(p) = self.popup.take() {
|
|
|
|
|
destroy_popup(p)
|
|
|
|
|
} else {
|
|
|
|
|
self.id_ctr += 1;
|
2023-06-01 12:23:12 -04:00
|
|
|
let new_id = window::Id(self.id_ctr);
|
2022-12-22 15:16:22 -07:00
|
|
|
self.popup.replace(new_id);
|
|
|
|
|
|
2023-07-05 18:23:49 -04:00
|
|
|
let mut popup_settings = self.applet_helper.get_popup_settings(
|
2023-06-01 12:23:12 -04:00
|
|
|
window::Id(0),
|
2022-12-22 15:16:22 -07:00
|
|
|
new_id,
|
2022-12-27 18:35:06 -05:00
|
|
|
None,
|
2022-12-23 15:14:15 -05:00
|
|
|
None,
|
2022-12-22 15:16:22 -07:00
|
|
|
None,
|
|
|
|
|
);
|
2023-07-05 18:23:49 -04:00
|
|
|
popup_settings.positioner.size_limits = Limits::NONE
|
|
|
|
|
.min_width(1.0)
|
2023-07-11 17:24:03 -04:00
|
|
|
.max_width(444.0)
|
2023-07-05 18:23:49 -04:00
|
|
|
.min_height(100.0)
|
2023-07-06 12:55:00 -04:00
|
|
|
.max_height(900.0);
|
2022-12-22 15:16:22 -07:00
|
|
|
get_popup(popup_settings)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-07 13:43:49 -06:00
|
|
|
Message::DoNotDisturb(chain, b) => {
|
|
|
|
|
self.timeline.set_chain(chain).start();
|
2023-07-03 14:53:45 -04:00
|
|
|
self.config.do_not_disturb = b;
|
|
|
|
|
if let Some(helper) = &self.config_helper {
|
|
|
|
|
if let Err(err) = self.config.write_entry(helper) {
|
|
|
|
|
tracing::error!("{:?}", err);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-22 15:16:22 -07:00
|
|
|
Command::none()
|
|
|
|
|
}
|
|
|
|
|
Message::Settings => {
|
|
|
|
|
let _ = process::Command::new("cosmic-settings notifications").spawn();
|
|
|
|
|
Command::none()
|
2022-07-05 14:41:09 -07:00
|
|
|
}
|
2023-07-20 17:55:43 -04:00
|
|
|
Message::NotificationEvent(n) => {
|
|
|
|
|
info!("{}", &n.app_name);
|
|
|
|
|
if let Some(c) = self
|
|
|
|
|
.cards
|
|
|
|
|
.iter_mut()
|
|
|
|
|
.find(|c| c.1.iter().any(|notif| n.app_name == notif.app_name))
|
|
|
|
|
{
|
|
|
|
|
if let Some(notif) = c.1.iter_mut().find(|notif| n.id == notif.id) {
|
|
|
|
|
*notif = n;
|
|
|
|
|
} else {
|
|
|
|
|
c.1.push(n);
|
|
|
|
|
c.3 = fl!(
|
|
|
|
|
"show-more",
|
|
|
|
|
HashMap::from_iter(vec![("more", c.1.len().saturating_sub(1))])
|
|
|
|
|
);
|
2023-07-03 19:48:08 -04:00
|
|
|
}
|
2023-07-20 17:55:43 -04:00
|
|
|
} else {
|
|
|
|
|
self.cards.push((
|
|
|
|
|
id::Cards::new(n.app_name.clone()),
|
|
|
|
|
vec![n],
|
|
|
|
|
false,
|
|
|
|
|
fl!("show-more", HashMap::from_iter(vec![("more", "1")])),
|
|
|
|
|
));
|
2023-07-03 19:48:08 -04:00
|
|
|
}
|
2023-07-20 17:55:43 -04:00
|
|
|
|
2023-06-30 16:27:45 -04:00
|
|
|
Command::none()
|
|
|
|
|
}
|
2022-12-22 15:16:22 -07:00
|
|
|
Message::Ignore => Command::none(),
|
2023-07-03 14:53:45 -04:00
|
|
|
Message::Config(config) => {
|
|
|
|
|
self.config = config;
|
|
|
|
|
Command::none()
|
|
|
|
|
}
|
|
|
|
|
Message::Dismissed(id) => {
|
2023-07-21 12:08:33 -04:00
|
|
|
info!("Dismissed {}", id);
|
2023-07-20 17:55:43 -04:00
|
|
|
for c in &mut self.cards {
|
|
|
|
|
c.1.retain(|n| n.id != id);
|
|
|
|
|
}
|
2023-07-21 12:08:33 -04:00
|
|
|
self.cards.retain(|c| !c.1.is_empty());
|
|
|
|
|
|
2023-07-03 14:53:45 -04:00
|
|
|
if let Some(tx) = &self.dbus_sender {
|
|
|
|
|
let tx = tx.clone();
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
if let Err(err) = tx.send(subscriptions::dbus::Input::Dismiss(id)).await {
|
|
|
|
|
tracing::error!("{:?}", err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
Command::none()
|
|
|
|
|
}
|
|
|
|
|
Message::DbusEvent(e) => match e {
|
|
|
|
|
subscriptions::dbus::Output::Ready(tx) => {
|
|
|
|
|
self.dbus_sender.replace(tx);
|
|
|
|
|
Command::none()
|
|
|
|
|
}
|
2023-07-20 17:55:43 -04:00
|
|
|
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))])
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-07-24 16:54:20 -04:00
|
|
|
self.cards.retain(|c| !c.1.is_empty());
|
|
|
|
|
|
2023-07-20 17:55:43 -04:00
|
|
|
Command::none()
|
|
|
|
|
}
|
2023-07-03 14:53:45 -04:00
|
|
|
},
|
2023-07-20 17:55:43 -04:00
|
|
|
Message::ClearAll(app_name) => {
|
|
|
|
|
if let Some(pos) = self
|
|
|
|
|
.cards
|
|
|
|
|
.iter_mut()
|
|
|
|
|
.position(|c| c.1.iter().any(|notif| app_name == notif.app_name))
|
|
|
|
|
{
|
|
|
|
|
for n in self.cards.remove(pos).1 {
|
|
|
|
|
if let Some(tx) = &self.dbus_sender {
|
|
|
|
|
let tx = tx.clone();
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
if let Err(err) =
|
|
|
|
|
tx.send(subscriptions::dbus::Input::Dismiss(n.id)).await
|
|
|
|
|
{
|
|
|
|
|
tracing::error!("{:?}", err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-05 14:38:48 -04:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-20 17:55:43 -04:00
|
|
|
|
|
|
|
|
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);
|
2023-07-05 14:38:48 -04:00
|
|
|
Command::none()
|
|
|
|
|
}
|
2022-07-05 14:41:09 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-12-22 15:16:22 -07:00
|
|
|
|
2023-04-05 20:40:22 -04:00
|
|
|
fn view(&self, id: window::Id) -> Element<Message> {
|
2023-06-01 12:23:12 -04:00
|
|
|
if id == window::Id(0) {
|
2023-04-05 20:40:22 -04:00
|
|
|
self.applet_helper
|
2022-12-22 15:16:22 -07:00
|
|
|
.icon_button(&self.icon_name)
|
|
|
|
|
.on_press(Message::TogglePopup)
|
2023-04-05 20:40:22 -04:00
|
|
|
.into()
|
|
|
|
|
} else {
|
2023-06-07 13:43:49 -06:00
|
|
|
let do_not_disturb = row![anim!(
|
|
|
|
|
DO_NOT_DISTURB,
|
|
|
|
|
&self.timeline,
|
2023-07-11 17:24:03 -04:00
|
|
|
String::from(fl!("do-not-disturb")),
|
2023-07-03 14:53:45 -04:00
|
|
|
self.config.do_not_disturb,
|
2023-06-07 13:43:49 -06:00
|
|
|
Message::DoNotDisturb
|
|
|
|
|
)
|
|
|
|
|
.width(Length::Fill)]
|
|
|
|
|
.padding([0, 24]);
|
2022-12-22 15:16:22 -07:00
|
|
|
|
2023-07-11 17:24:03 -04:00
|
|
|
let settings = row_button(vec![text(fl!("notification-settings")).into()])
|
|
|
|
|
.on_press(Message::Settings);
|
2023-04-05 20:40:22 -04:00
|
|
|
|
2023-07-20 17:55:43 -04:00
|
|
|
let notifications = if self.cards.is_empty() {
|
2023-07-05 14:38:48 -04:00
|
|
|
row![container(
|
2023-07-24 16:58:48 -04:00
|
|
|
column![
|
|
|
|
|
text_icon(&self.icon_name, 40),
|
|
|
|
|
text(&fl!("no-notifications"))
|
|
|
|
|
]
|
|
|
|
|
.align_items(Alignment::Center)
|
2023-07-05 14:38:48 -04:00
|
|
|
)
|
|
|
|
|
.width(Length::Fill)
|
|
|
|
|
.align_x(Horizontal::Center)]
|
2023-04-05 20:40:22 -04:00
|
|
|
.spacing(12)
|
|
|
|
|
} else {
|
2023-07-20 17:55:43 -04:00
|
|
|
let mut notifs: Vec<Element<_>> = Vec::with_capacity(self.cards.len());
|
2023-07-03 14:53:45 -04:00
|
|
|
|
2023-07-20 17:55:43 -04:00
|
|
|
for c in self.cards.iter().rev() {
|
|
|
|
|
if c.1.is_empty() {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let name = c.1[0].app_name.clone();
|
|
|
|
|
let notif_elems: Vec<_> =
|
|
|
|
|
c.1.iter()
|
|
|
|
|
.rev()
|
|
|
|
|
.map(|n| {
|
|
|
|
|
let app_name = text(if n.app_name.len() > 24 {
|
2023-07-11 17:28:45 -04:00
|
|
|
Cow::from(format!(
|
2023-07-20 17:55:43 -04:00
|
|
|
"{:.26}...",
|
|
|
|
|
n.app_name.lines().next().unwrap_or_default()
|
2023-07-11 17:28:45 -04:00
|
|
|
))
|
|
|
|
|
} else {
|
2023-07-20 17:55:43 -04:00
|
|
|
Cow::from(&n.app_name)
|
2023-07-11 17:28:45 -04:00
|
|
|
})
|
|
|
|
|
.size(12)
|
2023-07-20 17:55:43 -04:00
|
|
|
.width(Length::Fill);
|
|
|
|
|
|
|
|
|
|
let duration_since = text(duration_ago_msg(n)).size(12);
|
|
|
|
|
|
|
|
|
|
let close_notif =
|
|
|
|
|
button(icon("window-close-symbolic", 16).style(Svg::Symbolic))
|
|
|
|
|
.on_press(Message::Dismissed(n.id))
|
|
|
|
|
.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,
|
2023-07-03 14:53:45 -04:00
|
|
|
);
|
2023-07-20 17:55:43 -04:00
|
|
|
notifs.push(card_list.into());
|
2023-07-03 14:53:45 -04:00
|
|
|
}
|
2023-07-20 17:55:43 -04:00
|
|
|
|
2023-07-03 14:53:45 -04:00
|
|
|
row!(scrollable(
|
|
|
|
|
Column::with_children(notifs)
|
|
|
|
|
.spacing(8)
|
|
|
|
|
.height(Length::Shrink),
|
|
|
|
|
)
|
2023-07-05 18:23:49 -04:00
|
|
|
.height(Length::Shrink))
|
2023-04-05 20:40:22 -04:00
|
|
|
};
|
|
|
|
|
|
2023-07-11 17:24:03 -04:00
|
|
|
let main_content = column![horizontal_rule(4), notifications, horizontal_rule(4)]
|
|
|
|
|
.padding([0, 24])
|
|
|
|
|
.spacing(12);
|
2023-04-05 20:40:22 -04:00
|
|
|
|
2023-07-05 18:23:49 -04:00
|
|
|
let content = column![do_not_disturb, main_content, settings]
|
2023-04-05 20:40:22 -04:00
|
|
|
.align_items(Alignment::Start)
|
|
|
|
|
.spacing(12)
|
2023-07-11 17:24:03 -04:00
|
|
|
.padding([16, 0]);
|
2023-04-05 20:40:22 -04:00
|
|
|
|
|
|
|
|
self.applet_helper.popup_container(content).into()
|
2022-12-22 15:16:22 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 17:24:03 -04:00
|
|
|
// todo put into libcosmic doing so will fix the row_button's border radius
|
|
|
|
|
fn row_button(content: Vec<Element<Message>>) -> cosmic::iced::widget::Button<Message, Renderer> {
|
2022-12-22 15:16:22 -07:00
|
|
|
button(
|
|
|
|
|
Row::with_children(content)
|
2023-01-13 19:59:00 -05:00
|
|
|
.spacing(4)
|
2022-12-22 15:16:22 -07:00
|
|
|
.align_items(Alignment::Center),
|
|
|
|
|
)
|
|
|
|
|
.width(Length::Fill)
|
2023-06-01 12:23:12 -04:00
|
|
|
.height(Length::Fixed(36.0))
|
2023-07-11 17:24:03 -04:00
|
|
|
.padding([0, 24])
|
2023-06-01 12:23:12 -04:00
|
|
|
.style(applet_button_theme())
|
2022-12-22 15:16:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn text_icon(name: &str, size: u16) -> cosmic::widget::Icon {
|
2023-03-01 10:06:14 -08:00
|
|
|
icon(name, size).style(Svg::Symbolic)
|
2022-06-10 15:29:45 -07:00
|
|
|
}
|
2023-07-05 14:38:48 -04:00
|
|
|
|
|
|
|
|
fn duration_ago_msg(notification: &Notification) -> String {
|
|
|
|
|
if let Some(d) = notification.duration_since() {
|
|
|
|
|
let min = d.as_secs() / 60;
|
|
|
|
|
let hrs = min / 60;
|
|
|
|
|
if hrs > 0 {
|
|
|
|
|
fl!("hours-ago", HashMap::from_iter(vec![("duration", hrs)]))
|
|
|
|
|
} else {
|
|
|
|
|
fl!("minutes-ago", HashMap::from_iter(vec![("duration", min)]))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
format!("")
|
|
|
|
|
}
|
|
|
|
|
}
|