change the tray icon to show there are unread notifications

This commit is contained in:
dries.k
2022-11-02 20:19:02 +01:00
parent a8a854ce6b
commit ac15d079ef
5 changed files with 25 additions and 0 deletions

View File

@@ -266,6 +266,10 @@ class MainApplication(QtWidgets.QApplication):
def new_message_callback(self, message: gotify.GotifyMessageModel):
self.add_message_to_model(message)
# Change the tray icon to show there are unread notifications
if not self.main_window.isActiveWindow():
self.tray.set_icon_unread()
# Show a notification
if (
message.priority < settings.value("tray/notifications/priority", type=int)
@@ -385,6 +389,7 @@ class MainApplication(QtWidgets.QApplication):
self.main_window.delete_message.connect(self.delete_message_callback)
self.main_window.image_popup.connect(self.image_popup_callback)
self.main_window.hidden.connect(self.main_window_hidden_callback)
self.main_window.activated.connect(self.tray.revert_icon)
self.watchdog.closed.connect(lambda: self.listener_closed_callback(None, None))

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -23,6 +23,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
application_selection_changed = QtCore.pyqtSignal(QtGui.QStandardItem)
image_popup = QtCore.pyqtSignal(str, QtCore.QPoint)
hidden = QtCore.pyqtSignal()
activated = QtCore.pyqtSignal()
def __init__(
self, application_model: ApplicationModel, messages_model: MessagesModel
@@ -30,6 +31,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
super(MainWindow, self).__init__()
self.setupUi(self)
self.installEventFilter(self)
self.setWindowTitle(__title__)
self.application_model = application_model
@@ -177,3 +180,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def closeEvent(self, e: QtGui.QCloseEvent) -> None:
self.hide()
self.hidden.emit()
def eventFilter(self, object: QtCore.QObject, event: QtCore.QEvent) -> bool:
if event.type() == QtCore.QEvent.Type.WindowActivate:
self.activated.emit()
return super().eventFilter(object, event)

View File

@@ -44,7 +44,18 @@ class Tray(QtWidgets.QSystemTrayIcon):
self.setContextMenu(menu)
def set_icon_ok(self):
self.icon_error = False
self.setIcon(QtGui.QIcon(get_icon("tray")))
def set_icon_error(self):
self.icon_error = True
self.setIcon(QtGui.QIcon(get_icon("tray-error")))
def set_icon_unread(self):
self.setIcon(QtGui.QIcon(get_icon("tray-unread")))
def revert_icon(self):
if self.icon_error:
self.set_icon_error()
else:
self.set_icon_ok()