summaryrefslogtreecommitdiffstats
path: root/ui/src/components
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-01-15 12:36:31 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-01-20 16:03:06 +0200
commitf58ed387ddbb83296ae1bddb3f87affd18b1f78f (patch)
treef1830ab882a8302027dd958a3d9069f019b6c50b /ui/src/components
parent1eb49efb229701e6a4e2a32690d7a26a94abb301 (diff)
ui: add ratelimiting in UI notifications and drawing
Diffstat (limited to 'ui/src/components')
-rw-r--r--ui/src/components/notifications.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/ui/src/components/notifications.rs b/ui/src/components/notifications.rs
index ec4c0ae4..e05646ba 100644
--- a/ui/src/components/notifications.rs
+++ b/ui/src/components/notifications.rs
@@ -22,6 +22,7 @@
/*!
Notification handling components.
*/
+use crate::types::RateLimit;
use notify_rust;
use std::process::{Command, Stdio};
@@ -29,7 +30,9 @@ use super::*;
/// Passes notifications to the OS using the XDG specifications.
#[derive(Debug)]
-pub struct XDGNotifications {}
+pub struct XDGNotifications {
+ rate_limit: RateLimit,
+}
impl fmt::Display for XDGNotifications {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -38,10 +41,22 @@ impl fmt::Display for XDGNotifications {
}
}
+impl XDGNotifications {
+ pub fn new() -> Self {
+ XDGNotifications {
+ rate_limit: RateLimit::new(3, 1000),
+ }
+ }
+}
+
impl Component for XDGNotifications {
fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
if let UIEvent::Notification(ref title, ref body, ref kind) = event {
+ if !self.rate_limit.tick() {
+ return true;
+ }
+
let settings = &context.runtime_settings.notifications;
let mut notification = notify_rust::Notification::new();
notification