summary refs log tree commit diff stats
path: root/notification
diff options
context:
space:
mode:
Diffstat (limited to 'notification')
-rw-r--r--notification/notif.go8
-rw-r--r--notification/notify_darwin.go25
-rw-r--r--notification/notify_unix.go21
3 files changed, 54 insertions, 0 deletions
diff --git a/notification/notif.go b/notification/notif.go
new file mode 100644
index 0000000..b436c19
--- /dev/null
+++ b/notification/notif.go
@@ -0,0 +1,8 @@
+package notification
+
+// Notif struct holds information about the notification. Other
+// parameters like urgency & timeout could be added when required.
+type Notif struct {
+	Title   string
+	Message string
+}
diff --git a/notification/notify_darwin.go b/notification/notify_darwin.go
new file mode 100644
index 0000000..bddaf9e
--- /dev/null
+++ b/notification/notify_darwin.go
@@ -0,0 +1,25 @@
+// +build darwin
+
+package notification
+
+import (
+	"fmt"
+	"os/exec"
+	"strconv"
+)
+
+// Notify sends a desktop notification to the user using osascript. It
+// handles information in the form of Notif struct. It returns an
+// error (if exists).
+func (n Notif) Notify() error {
+	// This script cuts out parts of notification, this bug was
+	// confirmed on macOS Catalina 10.15.3, fix not yet known.
+	err := exec.Command("osascript", "-e",
+		`display notification `+strconv.Quote(n.Message)+` with title `+strconv.Quote(n.Title)).Run()
+	if err != nil {
+		err = fmt.Errorf("%s\n%s",
+			"notify_darwin.go: failed to sent notification with osascript",
+			err.Error())
+	}
+	return err
+}
diff --git a/notification/notify_unix.go b/notification/notify_unix.go
new file mode 100644
index 0000000..a6fc3ac
--- /dev/null
+++ b/notification/notify_unix.go
@@ -0,0 +1,21 @@
+// +build linux netbsd openbsd freebsd dragonfly
+
+package notification
+
+import (
+	"fmt"
+	"os/exec"
+)
+
+// Notify sends a desktop notification to the user using libnotify. It
+// handles information in the form of Notif struct. It returns an
+// error (if exists).
+func (n Notif) Notify() error {
+	err := exec.Command("notify-send", n.Title, n.Message).Run()
+	if err != nil {
+		err = fmt.Errorf("%s\n%s",
+			"notify_unix.go: failed to sent notification with notify-send",
+			err.Error())
+	}
+	return err
+}
c.html?h=hlt&id=848ebc1e6335cd1a34e07662242a367fefbc5229'>^
0ca56ed8 ^





e5c11a51 ^






















0ca56ed8 ^


e5c11a51 ^
0ca56ed8 ^
204dae92 ^






201458e3 ^
204dae92 ^

201458e3 ^
9e751bb8 ^

204dae92 ^






201458e3 ^
204dae92 ^

0ca56ed8 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87