diff options
| author | Yuval Adam <_@yuv.al> | 2022-08-06 12:32:21 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2022-08-06 12:32:21 +0300 |
| commit | 511151d7dcf14a4c3e7f73b9c342dc58f0eff56f (patch) | |
| tree | 85739f883fe63e0a313f7c07348302d2694e22b4 | |
| parent | 8f329424b3d2005b96ac364fe3834e41afe5e657 (diff) | |
Add support for linux notifications
| -rw-r--r-- | alarmpy/alarmpy.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/alarmpy/alarmpy.py b/alarmpy/alarmpy.py index 2ac49a5..3588005 100644 --- a/alarmpy/alarmpy.py +++ b/alarmpy/alarmpy.py @@ -72,11 +72,16 @@ class Alarm: return requests.Session() def init_desktop_notifications(self): - if self.desktop_notifications and not os.path.exists("/usr/bin/osascript"): - self.output_error( - "Desktop notifications are currently only available for MacOS" - ) - self.desktop_notifications = False + if self.desktop_notifications: + if os.path.exists("/usr/bin/notify-send"): + self.desktop_notifications = "linux" + elif os.path.exists("/usr/bin/osascript"): + self.desktop_notifications = "osx" + else: + self.output_error( + "Desktop notifications are currently only available for Linux and MacOS" + ) + self.desktop_notifications = False def init_mqtt(self): try: @@ -197,10 +202,13 @@ class Alarm: click.secho(f"{suffix}", fg="red", nl=False) click.secho("") if self.desktop_notifications: - cities_str = ", ".join(cities) - os.system( - f'/usr/bin/osascript -e \'display notification "{cities_str}" with title "Alarms at {area}"\'' - ) + areas_str = "\U0001f6a8" + ", ".join(areas.keys()) + if self.desktop_notifications == "osx": + os.system( + f'/usr/bin/osascript -e \'display notification "{areas_str}" with title "Alarms at {area}"\'' + ) + else: + os.system(f'/usr/bin/notify-send "{areas_str}"') if self.alarm_id: click.secho(f"({alarm_id})") |
