Commit c770271a authored by Nico Alt's avatar Nico Alt

Show notifications in notification bar

Fixes #28.
parent a9c883b4
Pipeline #4841 failed with stage
in 3 minutes and 22 seconds
......@@ -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()
......
......@@ -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
......
......@@ -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):
......@@ -73,7 +75,8 @@ class Window(Gtk.ApplicationWindow):
# pylint: disable=unused-argument
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):
if not Window._size_is_valid(size):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment