aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-12 11:28:08 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-12 11:28:08 +0200
commit106174c833e799ac89261a56d3a44f2dbb145353 (patch)
treefbdf62124c6afca434ac11849c0f050b309960d9
parentf00cb4ada824714c238e6f78fe5f932b1c010f00 (diff)
Runtime OS switcher for notifications
-rw-r--r--main.go29
-rw-r--r--notify_osx.go13
-rw-r--r--notify_x11.go9
3 files changed, 29 insertions, 22 deletions
diff --git a/main.go b/main.go
index a03a67d..592f770 100644
--- a/main.go
+++ b/main.go
@@ -5,7 +5,9 @@ import (
"flag"
"fmt"
"os"
+ "os/exec"
"os/signal"
+ "runtime"
"strings"
"time"
)
@@ -128,3 +130,30 @@ func main() {
for s := o.doWork; s != nil; s = s(ctx) {
}
}
+
+const title = "Pomodoro timer"
+
+func notifyX11(s string) error {
+ msg := fmt.Sprintf("%s\n\n%s", title, s)
+ return exec.Command("xmessage", "-center", "-timeout", "5", msg).Run()
+}
+
+func notifyOSX(s string) error {
+ msg := fmt.Sprintf("display notification %q with title %q", s, title)
+ return exec.Command("osascript", "-e", msg).Run()
+}
+
+func notifyLnx(s string) error {
+ return exec.Command("notify-send", title, s).Run()
+}
+
+func notify(s string) error {
+ switch runtime.GOOS {
+ case "darwin":
+ return notifyOSX(s)
+ case "linux":
+ return notifyLnx(s)
+ default: // *BSD
+ return notifyX11(s)
+ }
+}
diff --git a/notify_osx.go b/notify_osx.go
deleted file mode 100644
index 2e427e9..0000000
--- a/notify_osx.go
+++ /dev/null
@@ -1,13 +0,0 @@
-// +build darwin
-
-package main
-
-import (
- "fmt"
- "os/exec"
-)
-
-func notify(s string) error {
- cmd := fmt.Sprintf("display notification %q with title %q", s, "Pomodoro")
- return exec.Command("osascript", "-e", cmd).Run()
-}
diff --git a/notify_x11.go b/notify_x11.go
deleted file mode 100644
index f698be1..0000000
--- a/notify_x11.go
+++ /dev/null
@@ -1,9 +0,0 @@
-// +build !darwin
-
-package main
-
-import "os/exec"
-
-func notify(s string) error {
- return exec.Command("xmessage", "-center", "-timeout", "5", s).Run()
-}