1 Commits

Author SHA1 Message Date
a6e88d8e42 push notification when window inactive 2026-08-01 17:50:00 +07:00
2 changed files with 42 additions and 24 deletions

View File

@@ -11,8 +11,9 @@ use gpui::{
AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle, AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle,
Focusable, InteractiveElement, IntoElement, ListAlignment, ListOffset, ListState, MouseButton, Focusable, InteractiveElement, IntoElement, ListAlignment, ListOffset, ListState, MouseButton,
ObjectFit, ParentElement, PathPromptOptions, Render, SharedString, SharedUri, ObjectFit, ParentElement, PathPromptOptions, Render, SharedString, SharedUri,
StatefulInteractiveElement, Styled, StyledImage, Subscription, Task, WeakEntity, Window, div, StatefulInteractiveElement, Styled, StyledImage, Subscription, SystemNotification,
img, list, px, red, relative, svg, white, SystemNotificationAction, Task, WeakEntity, Window, div, img, list, px, red, relative, svg,
white,
}; };
use itertools::Itertools; use itertools::Itertools;
use nostr_sdk::prelude::*; use nostr_sdk::prelude::*;
@@ -275,7 +276,10 @@ impl ChatPanel {
/// Subscribe to room events /// Subscribe to room events
fn subscribe_room_events(&mut self, window: &mut Window, cx: &mut Context<Self>) { fn subscribe_room_events(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if let Some(room) = self.room.upgrade() { let Some(room) = self.room.upgrade() else {
return;
};
self.subscriptions.push(cx.subscribe_in( self.subscriptions.push(cx.subscribe_in(
&room, &room,
window, window,
@@ -286,6 +290,18 @@ impl ChatPanel {
this.insert_reaction(&message.rumor, cx); this.insert_reaction(&message.rumor, cx);
} else { } else {
this.insert_message(message, false, cx); this.insert_message(message, false, cx);
if !window.is_window_active() {
cx.show_system_notification(SystemNotification {
tag: "message".into(),
title: "New Message".into(),
body: "You have a new message.".into(),
actions: vec![SystemNotificationAction {
id: "open".into(),
label: "Open".into(),
}],
});
}
} }
} }
RoomEvent::Reload => { RoomEvent::Reload => {
@@ -299,7 +315,6 @@ impl ChatPanel {
}, },
)); ));
} }
}
/// Load all messages belonging to this room /// Load all messages belonging to this room
fn get_messages(&mut self, _window: &mut Window, cx: &mut Context<Self>) { fn get_messages(&mut self, _window: &mut Window, cx: &mut Context<Self>) {

View File

@@ -24,6 +24,9 @@ fn main() {
// Load embedded fonts in assets/fonts // Load embedded fonts in assets/fonts
load_embedded_fonts(cx); load_embedded_fonts(cx);
// Set app identity
cx.set_app_identity(APP_ID, CLIENT_NAME);
// Register the `quit` function // Register the `quit` function
cx.on_action(quit); cx.on_action(quit);