Store notifications
This commit is contained in:
parent
2396ebbaa9
commit
17df83e611
3 changed files with 46 additions and 22 deletions
|
|
@ -1,9 +1,5 @@
|
||||||
use cascade::cascade;
|
use cascade::cascade;
|
||||||
use gtk4::{
|
use gtk4::{glib, prelude::*, subclass::prelude::*};
|
||||||
glib::{self, clone},
|
|
||||||
prelude::*,
|
|
||||||
subclass::prelude::*,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::deref_cell::DerefCell;
|
use crate::deref_cell::DerefCell;
|
||||||
|
|
||||||
|
|
@ -54,4 +50,8 @@ impl NotificationPopover {
|
||||||
fn inner(&self) -> &NotificationPopoverInner {
|
fn inner(&self) -> &NotificationPopoverInner {
|
||||||
NotificationPopoverInner::from_instance(self)
|
NotificationPopoverInner::from_instance(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_body(&self, body: &str) {
|
||||||
|
self.inner().label.set_label(body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,15 @@ use gtk4::{
|
||||||
subclass::prelude::*,
|
subclass::prelude::*,
|
||||||
};
|
};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::{borrow::Cow, cell::Cell, collections::HashMap, fmt, num::NonZeroU32, time::Duration};
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
|
cell::{Cell, RefCell},
|
||||||
|
collections::HashMap,
|
||||||
|
fmt,
|
||||||
|
num::NonZeroU32,
|
||||||
|
rc::Rc,
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
static NOTIFICATIONS_XML: &str = "
|
static NOTIFICATIONS_XML: &str = "
|
||||||
<node name='/org/freedesktop/Notifications'>
|
<node name='/org/freedesktop/Notifications'>
|
||||||
|
|
@ -53,6 +61,7 @@ static NOTIFICATIONS_XML: &str = "
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct NotificationsInner {
|
pub struct NotificationsInner {
|
||||||
next_id: Cell<NotificationId>,
|
next_id: Cell<NotificationId>,
|
||||||
|
notifications: RefCell<HashMap<NotificationId, Rc<Notification>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
|
@ -180,7 +189,7 @@ impl glib::FromVariant for Hints {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Debug, Clone, Copy, Hash, glib::GBoxed)]
|
#[derive(Debug, Clone, Copy, Hash, glib::GBoxed, PartialEq, Eq)]
|
||||||
#[gboxed(type_name = "S76NotificationId")]
|
#[gboxed(type_name = "S76NotificationId")]
|
||||||
pub struct NotificationId(NonZeroU32);
|
pub struct NotificationId(NonZeroU32);
|
||||||
|
|
||||||
|
|
@ -202,7 +211,9 @@ impl NotificationId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Notification {
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct Notification {
|
||||||
id: NotificationId,
|
id: NotificationId,
|
||||||
app_name: String,
|
app_name: String,
|
||||||
app_icon: String, // decode?
|
app_icon: String, // decode?
|
||||||
|
|
@ -252,21 +263,20 @@ impl Notifications {
|
||||||
) -> NotificationId {
|
) -> NotificationId {
|
||||||
let id = replaces_id.unwrap_or_else(|| self.next_id());
|
let id = replaces_id.unwrap_or_else(|| self.next_id());
|
||||||
|
|
||||||
println!(
|
let notification = Rc::new(Notification {
|
||||||
"{:?}",
|
id,
|
||||||
(
|
app_name,
|
||||||
id,
|
app_icon,
|
||||||
app_name,
|
summary,
|
||||||
app_icon,
|
body,
|
||||||
summary,
|
actions,
|
||||||
body,
|
hints,
|
||||||
actions,
|
});
|
||||||
hints,
|
|
||||||
expire_timeout
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO
|
self.inner()
|
||||||
|
.notifications
|
||||||
|
.borrow_mut()
|
||||||
|
.insert(id, notification);
|
||||||
|
|
||||||
if expire_timeout != 0 {
|
if expire_timeout != 0 {
|
||||||
let expire_timeout = if expire_timeout < 0 {
|
let expire_timeout = if expire_timeout < 0 {
|
||||||
|
|
@ -360,6 +370,10 @@ impl Notifications {
|
||||||
|
|
||||||
fn name_lost(&self, _connection: Option<gio::DBusConnection>, _name: &str) {}
|
fn name_lost(&self, _connection: Option<gio::DBusConnection>, _name: &str) {}
|
||||||
|
|
||||||
|
pub fn get(&self, id: NotificationId) -> Option<Rc<Notification>> {
|
||||||
|
self.inner().notifications.borrow().get(&id).cloned()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn connect_notification_recieved<F: Fn(NotificationId) + 'static>(
|
pub fn connect_notification_recieved<F: Fn(NotificationId) + 'static>(
|
||||||
&self,
|
&self,
|
||||||
cb: F,
|
cb: F,
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,16 @@ impl PanelWindow {
|
||||||
|
|
||||||
app.add_window(&obj);
|
app.add_window(&obj);
|
||||||
|
|
||||||
|
let notifications = app.notifications().clone();
|
||||||
|
app.notifications()
|
||||||
|
.connect_notification_recieved(clone!(@weak obj => move |id| {
|
||||||
|
let notification = notifications.get(id);
|
||||||
|
println!(
|
||||||
|
"{:?}",
|
||||||
|
notification
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
obj
|
obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue