Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: set a new icon icon when there are new messages #16

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gotify_tray/gui/MainApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def insert_message(
message: gotify.GotifyMessageModel,
application: gotify.GotifyApplicationModel,
):
self.tray.set_icon_unread()
self.update_last_id(message.id)
message_item = MessagesModelItem(message)
self.messages_model.insertRow(row, message_item)
Expand Down Expand Up @@ -278,6 +279,7 @@ def new_message_callback(self, message: gotify.GotifyMessageModel):
else:
icon = QtWidgets.QSystemTrayIcon.MessageIcon.Information

self.tray.set_icon_unread()
self.tray.showMessage(
message.title,
message.message,
Expand Down Expand Up @@ -375,6 +377,7 @@ def link_callbacks(self):
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.discard_icon_unread)

self.watchdog.closed.connect(lambda: self.listener_closed_callback(None, None))

Expand Down
Binary file added gotify_tray/gui/images/tray-unread.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions gotify_tray/gui/widgets/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ 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
):
super(MainWindow, self).__init__()
self.setupUi(self)

self.installEventFilter(self)

self.setWindowTitle(__title__)

Expand Down Expand Up @@ -179,3 +182,9 @@ def restore_state(self):
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)
6 changes: 6 additions & 0 deletions gotify_tray/gui/widgets/Tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ def __init__(self):

self.setContextMenu(menu)

def set_icon_unread(self):
self.setIcon(QtGui.QIcon(get_icon("tray-unread")))

def set_icon_ok(self):
self.setIcon(QtGui.QIcon(get_icon("tray")))

def set_icon_error(self):
self.setIcon(QtGui.QIcon(get_icon("tray-error")))

def discard_icon_unread(self):
self.set_icon_ok()