Skip to content
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
22 changes: 17 additions & 5 deletions src/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ def __init__(self, app_name="Claude Code Usage Monitor",
session_thresholds: List of threshold percentages for session (default [50, 75, 90])
weekly_thresholds: List of threshold percentages for weekly (default to session_thresholds)
"""
# Initialize desktop-notifier
self.notifier = DesktopNotifier(
app_name=app_name,
notification_limit=10
)
self.app_name = app_name
self.notifier = None
self._notifier_init_attempted = False

# Configure thresholds
self.session_thresholds = session_thresholds if session_thresholds is not None else [50, 75, 90]
Expand Down Expand Up @@ -248,6 +246,20 @@ async def _send_notification(self, title: str, body: str, urgency: Urgency):
body: Notification body text
urgency: Urgency level
"""
if not self._notifier_init_attempted:
self._notifier_init_attempted = True
try:
self.notifier = DesktopNotifier(
app_name=self.app_name,
notification_limit=10
)
except Exception as e:
print(f"Warning: Failed to initialize desktop notifications: {e}", file=sys.stderr)
self.notifier = None

if self.notifier is None:
return

try:
await self.notifier.send(
title=title,
Expand Down
14 changes: 14 additions & 0 deletions src/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@

import pystray

# Monkey patch pystray's internal Notifier to prevent DBus timeout on Linux
# pystray's gtk and appindicator backends instantiate a synchronous DBus connection
# to org.freedesktop.Notifications, which can hang for 25s and crash on KDE/headless setups.
# We don't use pystray's notify() anyway since we use desktop_notifier.
try:
from pystray._util import notify_dbus
class DummyNotifier:
def __init__(self): pass
def notify(self, title, message, icon): pass
def hide(self): pass
notify_dbus.Notifier = DummyNotifier
except ImportError:
pass

from src.icon_generator import generate_gauge_icon
from src.utils import format_time_until
from src.config import get_access_token, UserConfig, get_config_path
Expand Down