Skip to content
Snippets Groups Projects
Commit 00409957 authored by Nico's avatar Nico
Browse files

Show notifications in notification bar

Fixes #28.
parent 4e083f98
No related branches found
No related tags found
1 merge request!73Show notifications in notification bar
...@@ -6,13 +6,15 @@ ...@@ -6,13 +6,15 @@
# https://gitlab.gnome.org/GNOME/fractal/-/tags/4.2.2 # https://gitlab.gnome.org/GNOME/fractal/-/tags/4.2.2
from gettext import gettext as _ 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_wrapper.models.contacts import Contacts
from briar_gtk.container import Container from briar_gtk.container import Container
from briar_gtk.containers.private_chat import PrivateChatContainer 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.about_dialog import AboutDialogWidget
from briar_gtk.widgets.contact_row import ContactRowWidget from briar_gtk.widgets.contact_row import ContactRowWidget
...@@ -259,15 +261,25 @@ class MainWindowContainer(Container): ...@@ -259,15 +261,25 @@ class MainWindowContainer(Container):
# pylint: disable=unused-argument # pylint: disable=unused-argument
def _notify_contact_added(self, message): def _notify_contact_added(self, message):
self._notify() self._notify(
_t("Notification", "Contact added"),
NOTIFICATION_CONTACT_ADDED
)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def _notify_message_received(self, message): def _notify_message_received(self, message):
self._notify() self._notify(
_t("Notification", "New private message"),
NOTIFICATION_PRIVATE_MESSAGE
)
@staticmethod @staticmethod
def _notify(): def _notify(title, identifier):
APP().window.set_urgency_hint(True) 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): def _refresh_contacts(self):
self._save_selected_row() self._save_selected_row()
......
...@@ -16,6 +16,9 @@ APPLICATION_NAME = "Briar" ...@@ -16,6 +16,9 @@ APPLICATION_NAME = "Briar"
RESOURCES_DIR = os.path.join("/app", "briar", "gtk") RESOURCES_DIR = os.path.join("/app", "briar", "gtk")
APPLICATION_STYLING_PATH = "resource:///app/briar/gtk/application.css" 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 APP = Gio.Application.get_default
......
...@@ -10,6 +10,8 @@ from briar_gtk.containers.add_contact import AddContactContainer ...@@ -10,6 +10,8 @@ from briar_gtk.containers.add_contact import AddContactContainer
from briar_gtk.containers.main_window import MainWindowContainer from briar_gtk.containers.main_window import MainWindowContainer
from briar_gtk.containers.startup import StartupContainer from briar_gtk.containers.startup import StartupContainer
from briar_gtk.define import APP, APPLICATION_ID, APPLICATION_NAME 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): class Window(Gtk.ApplicationWindow):
...@@ -73,7 +75,8 @@ class Window(Gtk.ApplicationWindow): ...@@ -73,7 +75,8 @@ class Window(Gtk.ApplicationWindow):
# pylint: disable=unused-argument # pylint: disable=unused-argument
def _on_focus_change(self, widget, event): def _on_focus_change(self, widget, event):
self.set_urgency_hint(False) APP().withdraw_notification(NOTIFICATION_CONTACT_ADDED)
APP().withdraw_notification(NOTIFICATION_PRIVATE_MESSAGE)
def _resize_window(self, size): def _resize_window(self, size):
if not Window._size_is_valid(size): if not Window._size_is_valid(size):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment