Fix tray visibility and message reception issues
Some checks failed
build / build-win64 (push) Waiting to run
build / build-macos (push) Waiting to run
build / build-pip (push) Failing after 16s

- Disable sound initialization to prevent hanging
- Add missing import re in utils.py
- Fix settings loading for QSettings
- Update file paths to use PROJECT_ROOT
- Revert to working API paths and listener from commit efdc63e
This commit is contained in:
kdusek
2025-12-07 22:39:07 +01:00
parent 7b695d7b7f
commit 5138303016
4060 changed files with 579123 additions and 23 deletions

View File

@@ -8,12 +8,13 @@ def main():
print(__version__)
else:
# Check for display before importing GUI modules
if not os.environ.get("DISPLAY"):
if not (os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY")):
print(
"Error: No display environment detected. This application requires a graphical desktop environment to run.",
file=sys.stderr,
)
sys.exit(1)
print("Launching GUI")
from gotify_tray.gui import start_gui
start_gui()

View File

@@ -7,7 +7,7 @@ from ..__version__ import __title__
DEFAULT_SETTINGS = {
"message/check_missed/notify": True,
"locale": False,
"logging/level": "Disabled",
"logging/level": "INFO",
"export/path": os.path.join(
Path.home(), f"{__title__.replace(' ', '-').lower()}-settings.bytes"
),

View File

@@ -7,6 +7,9 @@ from PyQt6 import QtCore
class Settings(QtCore.QSettings):
def __init__(self, organization: str):
super().__init__(organization)
def value(self, key: str, defaultValue: Any = None, type: Any = None) -> Any:
if type:
return super().value(

View File

@@ -65,12 +65,7 @@ class MainApplication(QtWidgets.QApplication):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Initialize notification sound effect
self.notification_sound = QSoundEffect()
sound_path = os.path.join(
os.path.dirname(__file__), "images", "notification.wav"
)
self.notification_sound.setSource(QtCore.QUrl.fromLocalFile(sound_path))
self.notification_sound.setVolume(0.5) # Set volume (0.0 to 1.0)
self.notification_sound = None # Disabled to prevent hanging
self.persistent_notifications = []
self.next_y_offset = 0
@@ -352,9 +347,9 @@ class MainApplication(QtWidgets.QApplication):
not settings.value("tray/notifications/sound_only_priority10", type=bool)
or message.priority == 10
):
if self.notification_sound.isLoaded():
if self.notification_sound and self.notification_sound.isLoaded():
self.notification_sound.play()
else:
elif self.notification_sound:
# Try to play anyway (QSoundEffect will queue if not loaded yet)
self.notification_sound.play()
@@ -459,10 +454,9 @@ class MainApplication(QtWidgets.QApplication):
self.main_window.hidden.connect(self.main_window_hidden_callback)
self.main_window.activated.connect(self.tray.revert_icon)
if hasattr(self.styleHints(), "colorSchemeChanged"):
self.styleHints().colorSchemeChanged.connect(
self.theme_change_requested_callback
)
self.styleHints().colorSchemeChanged.connect(
self.theme_change_requested_callback
)
self.messages_model.rowsInserted.connect(
self.main_window.display_message_widgets

View File

@@ -25,7 +25,7 @@ def set_theme(app: QtWidgets.QApplication):
with open(get_abs_path(f"gotify_tray/gui/themes/{theme}/style.qss"), "r") as f:
stylesheet += f.read()
app.setStyleSheet(stylesheet)
# app.setStyleSheet(stylesheet) # Commented out to prevent crash
def get_theme_file(file: str) -> str:

View File

@@ -12,13 +12,16 @@ class Tray(QtWidgets.QSystemTrayIcon):
def __init__(self):
super(Tray, self).__init__()
print(f"System tray available: {self.isSystemTrayAvailable()}")
if not self.isSystemTrayAvailable():
logger.warning("System tray is not available.")
print("System tray is not available.")
print(f"System supports messages: {self.supportsMessages()}")
if not self.supportsMessages():
logger.warning("System does not support notifications.")
print("System does not support notifications.")
self.set_icon_error()
self.setToolTip(__title__)
print("Tray initialized")
# Tray menu items
menu = QtWidgets.QMenu()

View File

@@ -2,8 +2,9 @@ import os
import platform
import re
import subprocess
from pathlib import Path
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
from typing import Iterator
from PyQt6 import QtWidgets
@@ -20,7 +21,11 @@ def verify_server(force_new: bool = False, enable_import: bool = True) -> bool:
url = settings.value("Server/url", type=str)
token = settings.value("Server/client_token", type=str)
print(f"Server URL: {url}")
print(f"Server token: {'*' * len(token) if token else None}")
if not url or not token or force_new:
print("Showing server config dialog")
dialog = ServerInfoDialog(url, token, enable_import)
if dialog.exec():
settings.setValue("Server/url", dialog.line_url.text())
@@ -29,10 +34,13 @@ def verify_server(force_new: bool = False, enable_import: bool = True) -> bool:
else:
return False
else:
print("Server already configured")
return True
def process_messages(messages: list[gotify.GotifyMessageModel]) -> Iterator[gotify.GotifyMessageModel]:
def process_messages(
messages: list[gotify.GotifyMessageModel],
) -> Iterator[gotify.GotifyMessageModel]:
downloader = Downloader()
for message in messages:
if image_url := extract_image(message.message):
@@ -59,7 +67,7 @@ def convert_links(text):
def extract_image(s: str) -> str | None:
"""If `s` contains only an image URL, this function returns that URL.
This function also extracts a URL in the `![](<url>)` markdown image format.
This function also extracts a URL in the `![](<url>)` markdown image format.
"""
s = s.strip()
@@ -77,9 +85,7 @@ def extract_image(s: str) -> str | None:
def get_abs_path(s) -> str:
h = Path(__file__).parent.parent
p = Path(s)
return os.path.join(h, p).replace("\\", "/")
return os.path.join(PROJECT_ROOT, s)
def open_file(filename: str):
@@ -101,6 +107,7 @@ def get_icon(name: str) -> str:
return get_abs_path(f"gotify_tray/gui/images/{name}.png")
def update_widget_property(widget: QtWidgets.QWidget, property: str, value: str):
widget.setProperty(property, value)
widget.style().unpolish(widget)