This commit is contained in:
dries.k
2022-02-02 17:36:46 +01:00
parent d14f2992a5
commit 63c47c470c
2 changed files with 14 additions and 15 deletions

View File

@@ -23,18 +23,17 @@ from .Tray import Tray
settings = Settings("gotify-tray")
logger = logging.getLogger("gotify-tray")
downloader = Downloader()
if (level := settings.value("logging/level", type=str)) != "Disabled":
logger.setLevel(level)
else:
logging.disable()
title = __title__.replace(" ", "-")
def init_logger():
def init_logger(logger: logging.Logger):
if (level := settings.value("logging/level", type=str)) != "Disabled":
logger.setLevel(level)
else:
logging.disable()
logdir = QtCore.QStandardPaths.standardLocations(
QtCore.QStandardPaths.StandardLocation.AppDataLocation
)[0]
@@ -52,13 +51,13 @@ class MainApplication(QtWidgets.QApplication):
self.shutting_down = False
def init_ui(self):
init_logger()
self.gotify_client = gotify.GotifyClient(
settings.value("Server/url", type=str),
settings.value("Server/client_token", type=str),
)
self.downloader = Downloader()
self.application_model = ApplicationModel()
self.refresh_applications()
@@ -85,7 +84,7 @@ class MainApplication(QtWidgets.QApplication):
):
for i, application in enumerate(applications):
icon = QtGui.QIcon(
downloader.get_filename(
self.downloader.get_filename(
f"{self.gotify_client.url}/{application.image}"
)
)
@@ -121,7 +120,7 @@ class MainApplication(QtWidgets.QApplication):
if settings.value("tray/notifications/icon/show", type=bool):
if application_item := self.application_model.itemFromId(message.appid):
image_url = f"{self.gotify_client.url}/{application_item.data(ApplicationItemDataRole.ApplicationRole).image}"
icon = QtGui.QIcon(downloader.get_filename(image_url))
icon = QtGui.QIcon(self.downloader.get_filename(image_url))
else:
logger.error(
f"MainWindow.new_message_callback: App id {message.appid} could not be found. Refreshing applications."
@@ -140,7 +139,7 @@ class MainApplication(QtWidgets.QApplication):
)
def settings_callback(self):
settings_dialog = SettingsDialog(self)
settings_dialog = SettingsDialog()
accepted = settings_dialog.exec()
if accepted and settings_dialog.settings_changed:
@@ -192,6 +191,8 @@ def start_gui():
app.setWindowIcon(QtGui.QIcon("gotify_tray/gui/images/gotify-small.png"))
app.setStyle("fusion")
init_logger(logger)
# prevent multiple instances
if (app.acquire_lock() or "--no-lock" in sys.argv) and verify_server():
app.init_ui()