Merge branch 'develop'
This commit is contained in:
@@ -19,9 +19,14 @@ logger = logging.getLogger("gotify-tray")
|
||||
|
||||
class GotifySession(object):
|
||||
def __init__(self, url: str, token: str):
|
||||
self.url = url.rstrip("/")
|
||||
|
||||
self.session = requests.Session()
|
||||
self.update_auth(url.rstrip("/"), token)
|
||||
|
||||
def update_auth(self, url: str = None, token: str = None):
|
||||
if url:
|
||||
self.url = url
|
||||
if token:
|
||||
self.token = token
|
||||
self.session.headers.update({"X-Gotify-Key": token})
|
||||
|
||||
def _get(self, endpoint: str = "/", **kwargs) -> requests.Response:
|
||||
@@ -67,9 +72,6 @@ class GotifyApplication(GotifySession):
|
||||
|
||||
|
||||
class GotifyClient(GotifySession):
|
||||
def __init__(self, url: str, client_token: str):
|
||||
super(GotifyClient, self).__init__(url, client_token)
|
||||
self.listener = Listener(url, client_token)
|
||||
|
||||
"""
|
||||
Application
|
||||
@@ -180,6 +182,7 @@ class GotifyClient(GotifySession):
|
||||
def dummy(*args):
|
||||
...
|
||||
|
||||
self.listener = Listener(self.url, self.token)
|
||||
self.listener.opened.connect(lambda: self.opened_callback(opened_callback))
|
||||
self.listener.closed.connect(closed_callback or dummy)
|
||||
self.listener.new_message.connect(new_message_callback or dummy)
|
||||
@@ -195,6 +198,9 @@ class GotifyClient(GotifySession):
|
||||
if not self.is_listening():
|
||||
self.listener.start()
|
||||
|
||||
def stop_final(self):
|
||||
self.listener.stop_final()
|
||||
|
||||
def stop(self, reset_wait: bool = False):
|
||||
if reset_wait:
|
||||
self.reset_wait_time()
|
||||
|
||||
@@ -63,6 +63,14 @@ class Listener(QtCore.QThread):
|
||||
):
|
||||
self.closed.emit(close_status_code, close_msg)
|
||||
|
||||
def stop_final(self):
|
||||
def dummy(*args):
|
||||
...
|
||||
|
||||
self.ws.on_close = dummy
|
||||
self.ws.close()
|
||||
self.running = False
|
||||
|
||||
def stop(self):
|
||||
logger.debug("Listener: stopping.")
|
||||
self.ws.close()
|
||||
|
||||
@@ -58,10 +58,6 @@ def init_logger(logger: logging.Logger):
|
||||
|
||||
|
||||
class MainApplication(QtWidgets.QApplication):
|
||||
def __init__(self, argv: List):
|
||||
super(MainApplication, self).__init__(argv)
|
||||
self.shutting_down = False
|
||||
|
||||
def init_ui(self):
|
||||
self.gotify_client = gotify.GotifyClient(
|
||||
settings.value("Server/url", type=str),
|
||||
@@ -162,7 +158,6 @@ class MainApplication(QtWidgets.QApplication):
|
||||
def listener_closed_callback(self, close_status_code: int, close_msg: str):
|
||||
self.main_window.set_connecting()
|
||||
self.tray.set_icon_error()
|
||||
if not self.shutting_down:
|
||||
self.gotify_client.increase_wait_time()
|
||||
QtCore.QTimer.singleShot(
|
||||
self.gotify_client.get_wait_time() * 1000, self.gotify_client.reconnect
|
||||
@@ -322,17 +317,17 @@ class MainApplication(QtWidgets.QApplication):
|
||||
settings_dialog.apply_settings()
|
||||
|
||||
if settings_dialog.server_changed:
|
||||
mb = QtWidgets.QMessageBox(
|
||||
QtWidgets.QMessageBox.Icon.Information,
|
||||
"Restart",
|
||||
"Restart to apply server changes",
|
||||
QtWidgets.QMessageBox.StandardButton.Yes
|
||||
| QtWidgets.QMessageBox.StandardButton.Cancel,
|
||||
# Restart the listener
|
||||
self.gotify_client.stop_final()
|
||||
self.gotify_client.update_auth(
|
||||
settings.value("Server/url", type=str),
|
||||
settings.value("Server/client_token", type=str),
|
||||
)
|
||||
self.gotify_client.listen(
|
||||
new_message_callback=self.new_message_callback,
|
||||
opened_callback=self.listener_opened_callback,
|
||||
closed_callback=self.listener_closed_callback,
|
||||
)
|
||||
|
||||
r = mb.exec()
|
||||
if r == QtWidgets.QMessageBox.StandardButton.Yes:
|
||||
self.quit()
|
||||
|
||||
def tray_activated_callback(
|
||||
self, reason: QtWidgets.QSystemTrayIcon.ActivationReason
|
||||
@@ -380,8 +375,7 @@ class MainApplication(QtWidgets.QApplication):
|
||||
|
||||
self.lock_file.unlock()
|
||||
|
||||
self.shutting_down = True
|
||||
self.gotify_client.stop()
|
||||
self.gotify_client.stop_final()
|
||||
super(MainApplication, self).quit()
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Form implementation generated from reading ui file 'gotify_tray/gui/designs\widget_settings.ui'
|
||||
#
|
||||
# Created by: PyQt6 UI code generator 6.1.0
|
||||
# Created by: PyQt6 UI code generator 6.3.0
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
@@ -26,47 +26,47 @@ class Ui_Dialog(object):
|
||||
self.tab_general.setObjectName("tab_general")
|
||||
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.tab_general)
|
||||
self.verticalLayout_4.setObjectName("verticalLayout_4")
|
||||
self.groupBox_5 = QtWidgets.QGroupBox(self.tab_general)
|
||||
self.groupBox_5.setObjectName("groupBox_5")
|
||||
self.gridLayout_4 = QtWidgets.QGridLayout(self.groupBox_5)
|
||||
self.groupBox_notifications = QtWidgets.QGroupBox(self.tab_general)
|
||||
self.groupBox_notifications.setObjectName("groupBox_notifications")
|
||||
self.gridLayout_4 = QtWidgets.QGridLayout(self.groupBox_notifications)
|
||||
self.gridLayout_4.setObjectName("gridLayout_4")
|
||||
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
|
||||
self.gridLayout_4.addItem(spacerItem, 0, 2, 1, 1)
|
||||
self.label_6 = QtWidgets.QLabel(self.groupBox_5)
|
||||
self.label_6.setObjectName("label_6")
|
||||
self.gridLayout_4.addWidget(self.label_6, 1, 2, 1, 1)
|
||||
self.label_4 = QtWidgets.QLabel(self.groupBox_5)
|
||||
self.label_4.setObjectName("label_4")
|
||||
self.gridLayout_4.addWidget(self.label_4, 0, 0, 1, 1)
|
||||
self.label_5 = QtWidgets.QLabel(self.groupBox_5)
|
||||
self.label_5.setObjectName("label_5")
|
||||
self.gridLayout_4.addWidget(self.label_5, 1, 0, 1, 1)
|
||||
self.spin_duration = QtWidgets.QSpinBox(self.groupBox_5)
|
||||
self.label_notification_duration_ms = QtWidgets.QLabel(self.groupBox_notifications)
|
||||
self.label_notification_duration_ms.setObjectName("label_notification_duration_ms")
|
||||
self.gridLayout_4.addWidget(self.label_notification_duration_ms, 1, 2, 1, 1)
|
||||
self.label_notification_priority = QtWidgets.QLabel(self.groupBox_notifications)
|
||||
self.label_notification_priority.setObjectName("label_notification_priority")
|
||||
self.gridLayout_4.addWidget(self.label_notification_priority, 0, 0, 1, 1)
|
||||
self.label_notification_duration = QtWidgets.QLabel(self.groupBox_notifications)
|
||||
self.label_notification_duration.setObjectName("label_notification_duration")
|
||||
self.gridLayout_4.addWidget(self.label_notification_duration, 1, 0, 1, 1)
|
||||
self.spin_duration = QtWidgets.QSpinBox(self.groupBox_notifications)
|
||||
self.spin_duration.setMinimum(500)
|
||||
self.spin_duration.setMaximum(30000)
|
||||
self.spin_duration.setSingleStep(100)
|
||||
self.spin_duration.setObjectName("spin_duration")
|
||||
self.gridLayout_4.addWidget(self.spin_duration, 1, 1, 1, 1)
|
||||
self.spin_priority = QtWidgets.QSpinBox(self.groupBox_5)
|
||||
self.spin_priority = QtWidgets.QSpinBox(self.groupBox_notifications)
|
||||
self.spin_priority.setMinimum(1)
|
||||
self.spin_priority.setMaximum(10)
|
||||
self.spin_priority.setProperty("value", 5)
|
||||
self.spin_priority.setObjectName("spin_priority")
|
||||
self.gridLayout_4.addWidget(self.spin_priority, 0, 1, 1, 1)
|
||||
self.cb_notify = QtWidgets.QCheckBox(self.groupBox_5)
|
||||
self.cb_notify = QtWidgets.QCheckBox(self.groupBox_notifications)
|
||||
self.cb_notify.setObjectName("cb_notify")
|
||||
self.gridLayout_4.addWidget(self.cb_notify, 2, 0, 1, 3)
|
||||
self.verticalLayout_4.addWidget(self.groupBox_5)
|
||||
self.groupBox_4 = QtWidgets.QGroupBox(self.tab_general)
|
||||
self.groupBox_4.setObjectName("groupBox_4")
|
||||
self.gridLayout_3 = QtWidgets.QGridLayout(self.groupBox_4)
|
||||
self.verticalLayout_4.addWidget(self.groupBox_notifications)
|
||||
self.groupBox_server_info = QtWidgets.QGroupBox(self.tab_general)
|
||||
self.groupBox_server_info.setObjectName("groupBox_server_info")
|
||||
self.gridLayout_3 = QtWidgets.QGridLayout(self.groupBox_server_info)
|
||||
self.gridLayout_3.setObjectName("gridLayout_3")
|
||||
self.pb_change_server_info = QtWidgets.QPushButton(self.groupBox_4)
|
||||
self.pb_change_server_info = QtWidgets.QPushButton(self.groupBox_server_info)
|
||||
self.pb_change_server_info.setObjectName("pb_change_server_info")
|
||||
self.gridLayout_3.addWidget(self.pb_change_server_info, 0, 0, 1, 1)
|
||||
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
|
||||
self.gridLayout_3.addItem(spacerItem1, 0, 1, 1, 1)
|
||||
self.verticalLayout_4.addWidget(self.groupBox_4)
|
||||
self.verticalLayout_4.addWidget(self.groupBox_server_info)
|
||||
spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
|
||||
self.verticalLayout_4.addItem(spacerItem2)
|
||||
self.tabWidget.addTab(self.tab_general, "")
|
||||
@@ -74,25 +74,25 @@ class Ui_Dialog(object):
|
||||
self.tab_fonts.setObjectName("tab_fonts")
|
||||
self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.tab_fonts)
|
||||
self.verticalLayout_5.setObjectName("verticalLayout_5")
|
||||
self.groupBox_2 = QtWidgets.QGroupBox(self.tab_fonts)
|
||||
self.groupBox_2.setObjectName("groupBox_2")
|
||||
self.layout_fonts_message = QtWidgets.QVBoxLayout(self.groupBox_2)
|
||||
self.groupBox_fonts_message = QtWidgets.QGroupBox(self.tab_fonts)
|
||||
self.groupBox_fonts_message.setObjectName("groupBox_fonts_message")
|
||||
self.layout_fonts_message = QtWidgets.QVBoxLayout(self.groupBox_fonts_message)
|
||||
self.layout_fonts_message.setContentsMargins(4, 4, 4, 4)
|
||||
self.layout_fonts_message.setSpacing(6)
|
||||
self.layout_fonts_message.setObjectName("layout_fonts_message")
|
||||
self.horizontalLayout = QtWidgets.QHBoxLayout()
|
||||
self.horizontalLayout.setObjectName("horizontalLayout")
|
||||
self.pb_font_message_title = QtWidgets.QPushButton(self.groupBox_2)
|
||||
self.pb_font_message_title = QtWidgets.QPushButton(self.groupBox_fonts_message)
|
||||
self.pb_font_message_title.setObjectName("pb_font_message_title")
|
||||
self.horizontalLayout.addWidget(self.pb_font_message_title)
|
||||
self.pb_font_message_date = QtWidgets.QPushButton(self.groupBox_2)
|
||||
self.pb_font_message_date = QtWidgets.QPushButton(self.groupBox_fonts_message)
|
||||
self.pb_font_message_date.setObjectName("pb_font_message_date")
|
||||
self.horizontalLayout.addWidget(self.pb_font_message_date)
|
||||
self.pb_font_message_content = QtWidgets.QPushButton(self.groupBox_2)
|
||||
self.pb_font_message_content = QtWidgets.QPushButton(self.groupBox_fonts_message)
|
||||
self.pb_font_message_content.setObjectName("pb_font_message_content")
|
||||
self.horizontalLayout.addWidget(self.pb_font_message_content)
|
||||
self.layout_fonts_message.addLayout(self.horizontalLayout)
|
||||
self.verticalLayout_5.addWidget(self.groupBox_2)
|
||||
self.verticalLayout_5.addWidget(self.groupBox_fonts_message)
|
||||
spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
|
||||
self.verticalLayout_5.addItem(spacerItem3)
|
||||
self.tabWidget.addTab(self.tab_fonts, "")
|
||||
@@ -114,23 +114,23 @@ class Ui_Dialog(object):
|
||||
self.pb_reset.setObjectName("pb_reset")
|
||||
self.verticalLayout_2.addWidget(self.pb_reset)
|
||||
self.verticalLayout.addWidget(self.groupBox)
|
||||
self.groupBox_7 = QtWidgets.QGroupBox(self.tab_advanced)
|
||||
self.groupBox_7.setObjectName("groupBox_7")
|
||||
self.gridLayout_6 = QtWidgets.QGridLayout(self.groupBox_7)
|
||||
self.groupBox_logging = QtWidgets.QGroupBox(self.tab_advanced)
|
||||
self.groupBox_logging.setObjectName("groupBox_logging")
|
||||
self.gridLayout_6 = QtWidgets.QGridLayout(self.groupBox_logging)
|
||||
self.gridLayout_6.setObjectName("gridLayout_6")
|
||||
self.label_7 = QtWidgets.QLabel(self.groupBox_7)
|
||||
self.label_7.setObjectName("label_7")
|
||||
self.gridLayout_6.addWidget(self.label_7, 0, 0, 1, 1)
|
||||
self.combo_logging = QtWidgets.QComboBox(self.groupBox_7)
|
||||
self.label_logging = QtWidgets.QLabel(self.groupBox_logging)
|
||||
self.label_logging.setObjectName("label_logging")
|
||||
self.gridLayout_6.addWidget(self.label_logging, 0, 0, 1, 1)
|
||||
self.combo_logging = QtWidgets.QComboBox(self.groupBox_logging)
|
||||
self.combo_logging.setObjectName("combo_logging")
|
||||
self.gridLayout_6.addWidget(self.combo_logging, 0, 1, 1, 1)
|
||||
self.pb_open_log = QtWidgets.QPushButton(self.groupBox_7)
|
||||
self.pb_open_log = QtWidgets.QPushButton(self.groupBox_logging)
|
||||
self.pb_open_log.setMaximumSize(QtCore.QSize(30, 16777215))
|
||||
self.pb_open_log.setObjectName("pb_open_log")
|
||||
self.gridLayout_6.addWidget(self.pb_open_log, 0, 2, 1, 1)
|
||||
spacerItem4 = QtWidgets.QSpacerItem(190, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
|
||||
self.gridLayout_6.addItem(spacerItem4, 0, 3, 1, 1)
|
||||
self.verticalLayout.addWidget(self.groupBox_7)
|
||||
self.verticalLayout.addWidget(self.groupBox_logging)
|
||||
spacerItem5 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
|
||||
self.verticalLayout.addItem(spacerItem5)
|
||||
self.tabWidget.addTab(self.tab_advanced, "")
|
||||
@@ -152,15 +152,15 @@ class Ui_Dialog(object):
|
||||
def retranslateUi(self, Dialog):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
|
||||
self.groupBox_5.setTitle(_translate("Dialog", "Notifications"))
|
||||
self.label_6.setText(_translate("Dialog", "ms"))
|
||||
self.label_4.setText(_translate("Dialog", "Minimum priority to show notifications:"))
|
||||
self.label_5.setText(_translate("Dialog", "Notification duration:"))
|
||||
self.groupBox_notifications.setTitle(_translate("Dialog", "Notifications"))
|
||||
self.label_notification_duration_ms.setText(_translate("Dialog", "ms"))
|
||||
self.label_notification_priority.setText(_translate("Dialog", "Minimum priority to show notifications:"))
|
||||
self.label_notification_duration.setText(_translate("Dialog", "<html><head/><body><p>Notification duration <span style=\" font-weight:600; color:#0000ff;\">[?]</span>:</p></body></html>"))
|
||||
self.cb_notify.setText(_translate("Dialog", "Show a notification for missed messages after reconnecting"))
|
||||
self.groupBox_4.setTitle(_translate("Dialog", "Server info"))
|
||||
self.groupBox_server_info.setTitle(_translate("Dialog", "Server info"))
|
||||
self.pb_change_server_info.setText(_translate("Dialog", "Change server info"))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_general), _translate("Dialog", "General"))
|
||||
self.groupBox_2.setTitle(_translate("Dialog", "Message"))
|
||||
self.groupBox_fonts_message.setTitle(_translate("Dialog", "Message"))
|
||||
self.pb_font_message_title.setText(_translate("Dialog", "Title"))
|
||||
self.pb_font_message_date.setText(_translate("Dialog", "Date"))
|
||||
self.pb_font_message_content.setText(_translate("Dialog", "Message"))
|
||||
@@ -169,8 +169,8 @@ class Ui_Dialog(object):
|
||||
self.pb_export.setText(_translate("Dialog", "Export"))
|
||||
self.pb_import.setText(_translate("Dialog", "Import"))
|
||||
self.pb_reset.setText(_translate("Dialog", "Reset"))
|
||||
self.groupBox_7.setTitle(_translate("Dialog", "Logging"))
|
||||
self.label_7.setText(_translate("Dialog", "Level"))
|
||||
self.groupBox_logging.setTitle(_translate("Dialog", "Logging"))
|
||||
self.label_logging.setText(_translate("Dialog", "Level"))
|
||||
self.pb_open_log.setToolTip(_translate("Dialog", "Open logfile"))
|
||||
self.pb_open_log.setText(_translate("Dialog", "..."))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_advanced), _translate("Dialog", "Advanced"))
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_5">
|
||||
<widget class="QGroupBox" name="groupBox_notifications">
|
||||
<property name="title">
|
||||
<string>Notifications</string>
|
||||
</property>
|
||||
@@ -54,23 +54,23 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<widget class="QLabel" name="label_notification_duration_ms">
|
||||
<property name="text">
|
||||
<string>ms</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<widget class="QLabel" name="label_notification_priority">
|
||||
<property name="text">
|
||||
<string>Minimum priority to show notifications:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<widget class="QLabel" name="label_notification_duration">
|
||||
<property name="text">
|
||||
<string>Notification duration:</string>
|
||||
<string><html><head/><body><p>Notification duration <span style=" font-weight:600; color:#0000ff;">[?]</span>:</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -111,7 +111,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<widget class="QGroupBox" name="groupBox_server_info">
|
||||
<property name="title">
|
||||
<string>Server info</string>
|
||||
</property>
|
||||
@@ -160,7 +160,7 @@
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<widget class="QGroupBox" name="groupBox_fonts_message">
|
||||
<property name="title">
|
||||
<string>Message</string>
|
||||
</property>
|
||||
@@ -259,13 +259,13 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_7">
|
||||
<widget class="QGroupBox" name="groupBox_logging">
|
||||
<property name="title">
|
||||
<string>Logging</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<widget class="QLabel" name="label_logging">
|
||||
<property name="text">
|
||||
<string>Level</string>
|
||||
</property>
|
||||
|
||||
@@ -46,6 +46,9 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.spin_duration.setValue(
|
||||
settings.value("tray/notifications/duration_ms", type=int)
|
||||
)
|
||||
self.label_notification_duration.setToolTip(
|
||||
"This setting is ignored on Windows."
|
||||
)
|
||||
|
||||
self.cb_notify.setChecked(
|
||||
settings.value("message/check_missed/notify", type=bool)
|
||||
|
||||
Reference in New Issue
Block a user