diff --git a/briar-gtk/briar_gtk/containers/main_window.py b/briar-gtk/briar_gtk/containers/main_window.py index f2e9a8959f32b7736c33d336221172b54a6d7528..394c45dbbafe83a2de4f2a47f1bf446391880f0a 100644 --- a/briar-gtk/briar_gtk/containers/main_window.py +++ b/briar-gtk/briar_gtk/containers/main_window.py @@ -6,13 +6,15 @@ # https://gitlab.gnome.org/GNOME/fractal/-/tags/4.2.2 from gettext import gettext as _ -from gi.repository import GLib, Gtk +from gettext import pgettext as _t +from gi.repository import Gio, GLib, Gtk from briar_wrapper.models.contacts import Contacts from briar_gtk.container import Container from briar_gtk.containers.private_chat import PrivateChatContainer -from briar_gtk.define import APP +from briar_gtk.define import APP, NOTIFICATION_CONTACT_ADDED +from briar_gtk.define import NOTIFICATION_PRIVATE_MESSAGE from briar_gtk.widgets.about_dialog import AboutDialogWidget from briar_gtk.widgets.contact_row import ContactRowWidget @@ -259,15 +261,25 @@ class MainWindowContainer(Container): # pylint: disable=unused-argument def _notify_contact_added(self, message): - self._notify() + self._notify( + _t("Notification", "Contact added"), + NOTIFICATION_CONTACT_ADDED + ) # pylint: disable=unused-argument def _notify_message_received(self, message): - self._notify() + self._notify( + _t("Notification", "New private message"), + NOTIFICATION_PRIVATE_MESSAGE + ) @staticmethod - def _notify(): - APP().window.set_urgency_hint(True) + def _notify(title, identifier): + if APP().window.is_active(): + return + notification = Gio.Notification.new(title) + notification.set_priority(Gio.NotificationPriority.HIGH) + APP().send_notification(identifier, notification) def _refresh_contacts(self): self._save_selected_row() diff --git a/briar-gtk/briar_gtk/define.py b/briar-gtk/briar_gtk/define.py index 6b323f6ed28b676c44037dda4b12239e48e97475..8298a25d22ec2287f16376d3cf1248434199683b 100644 --- a/briar-gtk/briar_gtk/define.py +++ b/briar-gtk/briar_gtk/define.py @@ -16,6 +16,9 @@ APPLICATION_NAME = "Briar" RESOURCES_DIR = os.path.join("/app", "briar", "gtk") APPLICATION_STYLING_PATH = "resource:///app/briar/gtk/application.css" +NOTIFICATION_CONTACT_ADDED = "briar-gtk-contact-added" +NOTIFICATION_PRIVATE_MESSAGE = "briar-gtk-private-message" + APP = Gio.Application.get_default diff --git a/briar-gtk/briar_gtk/window.py b/briar-gtk/briar_gtk/window.py index d52b3d751c30cfa739e9cec664a23e2f32fbbf81..5c17bcb48eae6c832d6d8b79a6806ad4fec93003 100644 --- a/briar-gtk/briar_gtk/window.py +++ b/briar-gtk/briar_gtk/window.py @@ -10,6 +10,8 @@ from briar_gtk.containers.add_contact import AddContactContainer from briar_gtk.containers.main_window import MainWindowContainer from briar_gtk.containers.startup import StartupContainer from briar_gtk.define import APP, APPLICATION_ID, APPLICATION_NAME +from briar_gtk.define import NOTIFICATION_CONTACT_ADDED +from briar_gtk.define import NOTIFICATION_PRIVATE_MESSAGE class Window(Gtk.ApplicationWindow): @@ -72,8 +74,10 @@ class Window(Gtk.ApplicationWindow): self.connect("focus-out-event", self._on_focus_change) # pylint: disable=unused-argument - def _on_focus_change(self, widget, event): - self.set_urgency_hint(False) + @staticmethod + def _on_focus_change(widget, event): + APP().withdraw_notification(NOTIFICATION_CONTACT_ADDED) + APP().withdraw_notification(NOTIFICATION_PRIVATE_MESSAGE) def _resize_window(self, size): if not Window._size_is_valid(size):