From 27947a40fa9fdd97f80f0ef48f3bbd9d50f790fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=80=D1=8B=D0=BB=D0=BE=D0=B2=20=D0=90=D0=BB=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Fri, 12 Jul 2024 10:04:26 +0300 Subject: [PATCH] feat: notification with sound --- README.md | 1 + env.sh.example | 3 +++ main.go | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100755 env.sh.example diff --git a/README.md b/README.md index d102f8c..f0d586c 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ killall go - CALDAV_SERVER_OFFSET_HOURS default - same as server - CALDAV_REFRESH_PERIOD_MINUTES default 10 - CALDAV_NOTIFY_BEFORE_MINUTES default 5 +- CALDAV_NOTIFY_WITH_SOUND default no. if not empty - sound will be produced ## for better experience it is useful to create env file with environment variables and source it diff --git a/env.sh.example b/env.sh.example new file mode 100755 index 0000000..dbb0094 --- /dev/null +++ b/env.sh.example @@ -0,0 +1,3 @@ +CALDAV_USERNAME= +CALDAV_PASSWORD= +CALDAV_URL=my.calendar.ru:8080/calendars diff --git a/main.go b/main.go index a011cae..ff7d610 100644 --- a/main.go +++ b/main.go @@ -23,16 +23,22 @@ const ( notifyEnvOffset = "CALDAV_SERVER_OFFSET_HOURS" notifyEnvRefreshPeriod = "CALDAV_REFRESH_PERIOD_MINUTES" notifyEnvTimeBefore = "CALDAV_NOTIFY_BEFORE_MINUTES" + notifyEnvWithSound = "CALDAV_NOTIFY_WITH_SOUND" ) func main() { + // TODO delete on first external contribution notify.Notify("", "https://github.com/Truenya", "notification daemon started", "") events := make(chan event) go planEvents(events) icon := os.Getenv(notifyEnvIcon) for e := range events { - notify.Notify("", e.Summary, e.Description, icon) + if sound := os.Getenv(notifyEnvWithSound); sound != "" { + notify.Alert("", e.Summary, e.Description, icon) + } else { + notify.Notify("", e.Summary, e.Description, icon) + } } }