From 84495caf4343fe7df6e8fb87e0766aafde6cd9b2 Mon Sep 17 00:00:00 2001 From: "dries.k" Date: Sun, 9 Jul 2023 15:03:10 +0200 Subject: [PATCH] add option to toggle server watchdog thread --- gotify_tray/database/default_settings.py | 1 + gotify_tray/gui/MainApplication.py | 3 +- gotify_tray/gui/designs/widget_settings.py | 41 ++++++++++++---- gotify_tray/gui/designs/widget_settings.ui | 55 +++++++++++++++++++++- gotify_tray/gui/widgets/SettingsDialog.py | 6 +++ 5 files changed, 96 insertions(+), 10 deletions(-) diff --git a/gotify_tray/database/default_settings.py b/gotify_tray/database/default_settings.py index b488416..9bd7d1f 100644 --- a/gotify_tray/database/default_settings.py +++ b/gotify_tray/database/default_settings.py @@ -17,6 +17,7 @@ DEFAULT_SETTINGS = { "tray/notifications/icon/show": True, "tray/notifications/click": True, "tray/icon/unread": False, + "watchdog/enabled": True, "watchdog/interval/s": 60, "MessageWidget/height/min": 100, "MessageWidget/image/size": 33, diff --git a/gotify_tray/gui/MainApplication.py b/gotify_tray/gui/MainApplication.py index 365fd1f..3ebffb6 100644 --- a/gotify_tray/gui/MainApplication.py +++ b/gotify_tray/gui/MainApplication.py @@ -94,7 +94,8 @@ class MainApplication(QtWidgets.QApplication): self.link_callbacks() self.init_shortcuts() - self.watchdog.start() + if settings.value("watchdog/enabled", type=bool): + self.watchdog.start() def set_theme(self): set_theme(self) diff --git a/gotify_tray/gui/designs/widget_settings.py b/gotify_tray/gui/designs/widget_settings.py index 5dffb29..6230206 100644 --- a/gotify_tray/gui/designs/widget_settings.py +++ b/gotify_tray/gui/designs/widget_settings.py @@ -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.5.0 +# Created by: PyQt6 UI code generator 6.5.1 # # 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. @@ -12,7 +12,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") - Dialog.resize(415, 420) + Dialog.resize(415, 426) self.gridLayout = QtWidgets.QGridLayout(Dialog) self.gridLayout.setObjectName("gridLayout") self.buttonBox = QtWidgets.QDialogButtonBox(parent=Dialog) @@ -166,6 +166,28 @@ class Ui_Dialog(object): self.horizontalLayout_4.addItem(spacerItem4) self.gridLayout_2.addLayout(self.horizontalLayout_4, 0, 0, 1, 1) self.verticalLayout.addWidget(self.groupbox_image_popup) + self.groupbox_watchdog = QtWidgets.QGroupBox(parent=self.tab_advanced) + self.groupbox_watchdog.setCheckable(True) + self.groupbox_watchdog.setObjectName("groupbox_watchdog") + self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.groupbox_watchdog) + self.verticalLayout_3.setObjectName("verticalLayout_3") + self.horizontalLayout_3 = QtWidgets.QHBoxLayout() + self.horizontalLayout_3.setObjectName("horizontalLayout_3") + self.label_watchdog_interval = QtWidgets.QLabel(parent=self.groupbox_watchdog) + self.label_watchdog_interval.setObjectName("label_watchdog_interval") + self.horizontalLayout_3.addWidget(self.label_watchdog_interval) + self.spin_watchdog_interval = QtWidgets.QSpinBox(parent=self.groupbox_watchdog) + self.spin_watchdog_interval.setMinimum(1) + self.spin_watchdog_interval.setMaximum(100000) + self.spin_watchdog_interval.setObjectName("spin_watchdog_interval") + self.horizontalLayout_3.addWidget(self.spin_watchdog_interval) + self.label_watchdog_interval_s = QtWidgets.QLabel(parent=self.groupbox_watchdog) + self.label_watchdog_interval_s.setObjectName("label_watchdog_interval_s") + self.horizontalLayout_3.addWidget(self.label_watchdog_interval_s) + spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) + self.horizontalLayout_3.addItem(spacerItem5) + self.verticalLayout_3.addLayout(self.horizontalLayout_3) + self.verticalLayout.addWidget(self.groupbox_watchdog) self.groupBox_cache = QtWidgets.QGroupBox(parent=self.tab_advanced) self.groupBox_cache.setObjectName("groupBox_cache") self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.groupBox_cache) @@ -179,8 +201,8 @@ class Ui_Dialog(object): self.label_cache = QtWidgets.QLabel(parent=self.groupBox_cache) self.label_cache.setObjectName("label_cache") self.horizontalLayout_6.addWidget(self.label_cache) - spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) - self.horizontalLayout_6.addItem(spacerItem5) + spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) + self.horizontalLayout_6.addItem(spacerItem6) self.verticalLayout.addWidget(self.groupBox_cache) self.groupBox_logging = QtWidgets.QGroupBox(parent=self.tab_advanced) self.groupBox_logging.setObjectName("groupBox_logging") @@ -189,8 +211,8 @@ class Ui_Dialog(object): self.combo_logging = QtWidgets.QComboBox(parent=self.groupBox_logging) self.combo_logging.setObjectName("combo_logging") self.gridLayout_6.addWidget(self.combo_logging, 0, 1, 1, 1) - spacerItem6 = QtWidgets.QSpacerItem(190, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) - self.gridLayout_6.addItem(spacerItem6, 0, 3, 1, 1) + spacerItem7 = QtWidgets.QSpacerItem(190, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) + self.gridLayout_6.addItem(spacerItem7, 0, 3, 1, 1) self.pb_open_log = QtWidgets.QPushButton(parent=self.groupBox_logging) self.pb_open_log.setMaximumSize(QtCore.QSize(30, 16777215)) self.pb_open_log.setObjectName("pb_open_log") @@ -199,8 +221,8 @@ class Ui_Dialog(object): self.label_logging.setObjectName("label_logging") self.gridLayout_6.addWidget(self.label_logging, 0, 0, 1, 1) self.verticalLayout.addWidget(self.groupBox_logging) - spacerItem7 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) - self.verticalLayout.addItem(spacerItem7) + spacerItem8 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) + self.verticalLayout.addItem(spacerItem8) self.tabWidget.addTab(self.tab_advanced, "") self.gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1) @@ -252,6 +274,9 @@ class Ui_Dialog(object): self.label_2.setToolTip(_translate("Dialog", "Maximum pop-up height")) self.label_2.setText(_translate("Dialog", "Height")) self.spin_popup_h.setToolTip(_translate("Dialog", "Maximum pop-up height")) + self.groupbox_watchdog.setTitle(_translate("Dialog", "Server watchdog thread (requires restart)")) + self.label_watchdog_interval.setText(_translate("Dialog", "Interval:")) + self.label_watchdog_interval_s.setText(_translate("Dialog", "s")) self.groupBox_cache.setTitle(_translate("Dialog", "Cache")) self.pb_clear_cache.setText(_translate("Dialog", "Clear")) self.pb_open_cache_dir.setText(_translate("Dialog", "Open")) diff --git a/gotify_tray/gui/designs/widget_settings.ui b/gotify_tray/gui/designs/widget_settings.ui index 62e3a45..4908dad 100644 --- a/gotify_tray/gui/designs/widget_settings.ui +++ b/gotify_tray/gui/designs/widget_settings.ui @@ -7,7 +7,7 @@ 0 0 415 - 420 + 426 @@ -391,6 +391,59 @@ + + + + Server watchdog thread (requires restart) + + + true + + + + + + + + Interval: + + + + + + + 1 + + + 100000 + + + + + + + s + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + diff --git a/gotify_tray/gui/widgets/SettingsDialog.py b/gotify_tray/gui/widgets/SettingsDialog.py index 5f8c1af..462f4e1 100644 --- a/gotify_tray/gui/widgets/SettingsDialog.py +++ b/gotify_tray/gui/widgets/SettingsDialog.py @@ -82,6 +82,8 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog): self.spin_popup_h.setValue(settings.value("ImagePopup/h", type=int)) self.label_cache.setText("0 MB") self.compute_cache_size() + self.groupbox_watchdog.setChecked(settings.value("watchdog/enabled", type=bool)) + self.spin_watchdog_interval.setValue(settings.value("watchdog/interval/s", type=int)) def add_message_widget(self): self.message_widget = MessageWidget( @@ -215,6 +217,8 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog): self.spin_popup_h.valueChanged.connect(self.settings_changed_callback) self.pb_clear_cache.clicked.connect(self.clear_cache_callback) self.pb_open_cache_dir.clicked.connect(lambda: open_file(Cache().directory())) + self.groupbox_watchdog.toggled.connect(self.settings_changed_callback) + self.spin_watchdog_interval.valueChanged.connect(self.settings_changed_callback) def apply_settings(self): # Priority @@ -246,6 +250,8 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog): settings.setValue("ImagePopup/enabled", self.groupbox_image_popup.isChecked()) settings.setValue("ImagePopup/w", self.spin_popup_w.value()) settings.setValue("ImagePopup/h", self.spin_popup_h.value()) + settings.setValue("watchdog/enabled", self.groupbox_watchdog.isChecked()) + settings.setValue("watchdog/interval/s", self.spin_watchdog_interval.value()) self.settings_changed = False self.buttonBox.button(