From b56f905714b6b57eb224ad0523b8c46260419562 Mon Sep 17 00:00:00 2001 From: ac Date: Sat, 4 May 2024 09:01:17 +1000 Subject: [PATCH 1/2] Only mute a notification if the application is focused and the room it relates to is open. Application::focused state is now available in the store. --- src/base.rs | 4 ++++ src/main.rs | 4 ++++ src/notifications.rs | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index f576d34..670e4b4 100644 --- a/src/base.rs +++ b/src/base.rs @@ -1319,6 +1319,9 @@ pub struct ChatStore { /// Whether to ring the terminal bell on the next redraw. pub ring_bell: bool, + + /// Whether the application is currently focused + pub focused: bool, } impl ChatStore { @@ -1341,6 +1344,7 @@ impl ChatStore { sync_info: Default::default(), draw_curr: None, ring_bell: false, + focused: false, } } diff --git a/src/main.rs b/src/main.rs index 2311a3c..4105236 100644 --- a/src/main.rs +++ b/src/main.rs @@ -355,9 +355,13 @@ impl Application { // Do nothing for now. }, Event::FocusGained => { + let mut store = self.store.lock().await; + store.application.focused = true; self.focused = true; }, Event::FocusLost => { + let mut store = self.store.lock().await; + store.application.focused = false; self.focused = false; }, Event::Resize(_, _) => { diff --git a/src/notifications.rs b/src/notifications.rs index 194e6a0..9f86575 100644 --- a/src/notifications.rs +++ b/src/notifications.rs @@ -44,7 +44,7 @@ pub async fn register_notifications( return; } - if is_open(&store, room.room_id()).await { + if is_focused(&store).await && is_open(&store, room.room_id()).await { return; } @@ -139,6 +139,11 @@ async fn is_open(store: &AsyncProgramStore, room_id: &RoomId) -> bool { false } +async fn is_focused(store: &AsyncProgramStore) -> bool { + let locked = store.lock().await; + locked.application.focused +} + pub async fn parse_notification( notification: Notification, room: MatrixRoom, From 20a248e36b6d9c3c673c2c0ad1e923fd996c16b5 Mon Sep 17 00:00:00 2001 From: ac Date: Sat, 25 May 2024 08:54:00 +1000 Subject: [PATCH 2/2] Set default of `focused` in the application store to `true`. --- src/base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index 670e4b4..e08881e 100644 --- a/src/base.rs +++ b/src/base.rs @@ -1344,7 +1344,7 @@ impl ChatStore { sync_info: Default::default(), draw_curr: None, ring_bell: false, - focused: false, + focused: true, } }