Skip to content

Commit

Permalink
chore(cleanup): cleanup notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
jerdog committed Dec 18, 2024
1 parent cee1e9b commit b70cd80
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/bluesky_notify/core/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os
import platform
import subprocess
import shutil
import tempfile
import webbrowser
from desktop_notifier import DesktopNotifier
Expand Down Expand Up @@ -72,24 +73,31 @@ async def _send_notification_async(self, title: str, message: str, url: str) ->
truncated_message = self._truncate_message(message)

if platform.system() == 'Darwin':
# Check if terminal-notifier is installed
terminal_notifier_path = '/opt/homebrew/bin/terminal-notifier'
if not os.path.exists(terminal_notifier_path):
logger.error("terminal-notifier not found. Installing...")
try:
subprocess.run(['brew', 'install', 'terminal-notifier'], check=True)
except subprocess.CalledProcessError as e:
logger.error(f"Failed to install terminal-notifier: {e}")
return False
# Check both Homebrew paths
possible_paths = [
'/opt/homebrew/bin/terminal-notifier',
'/usr/local/bin/terminal-notifier',
shutil.which('terminal-notifier')
]

terminal_notifier_path = next((path for path in possible_paths if path and os.path.exists(path)), None)

if not terminal_notifier_path:
logger.error("terminal-notifier not found. Please install with: brew install terminal-notifier")
return False

result = subprocess.run([
cmd = [
terminal_notifier_path,
'-title', clean_title,
'-subtitle', "Click to open in browser",
'-message', truncated_message,
'-open', url,
'-sound', 'default'
], capture_output=True, text=True)
'-open', url
]

if self._notification_sound:
cmd.extend(['-sound', 'default'])

result = subprocess.run(cmd, capture_output=True, text=True)

if result.returncode == 0:
logger.info(f"Notification sent with URL: {url}")
Expand Down

0 comments on commit b70cd80

Please sign in to comment.