change the tray icon to show there are unread notifications
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
BIN
gotify_tray/gui/images/tray-unread-macos.png
Normal file
BIN
gotify_tray/gui/images/tray-unread-macos.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 333 KiB |
BIN
gotify_tray/gui/images/tray-unread.png
Normal file
BIN
gotify_tray/gui/images/tray-unread.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user