Merge branch 'JackMordaunt-master'

This commit is contained in:
Kevin Schoon 2018-01-31 07:13:04 -05:00
commit 51aaa9c19f
2 changed files with 48 additions and 4 deletions

10
main.go
View File

@ -2,16 +2,22 @@ package main
import (
"encoding/json"
"github.com/jawher/mow.cli"
"os"
"runtime"
"sort"
"time"
"github.com/jawher/mow.cli"
)
func notifier(iconPath string) Notifier {
if runtime.GOOS == "linux" {
switch runtime.GOOS {
case "linux":
return NewLibNotifier(iconPath)
case "darwin":
return NewDarwinNotifier(iconPath)
case "windows":
return NewWindowsNotifier(iconPath)
}
return NoopNotifier{}
}

View File

@ -3,11 +3,13 @@ package main
import (
"encoding/json"
"fmt"
"github.com/fatih/color"
"io/ioutil"
"os"
"time"
"github.com/0xAX/notificator"
"github.com/fatih/color"
"github.com/kevinschoon/pomo/libnotify"
)
@ -142,7 +144,6 @@ func (p Pomodoro) Duration() time.Duration {
// Notifier implements a system specific
// notification. On Linux this libnotify.
// TODO: OSX, Windows(?)
type Notifier interface {
Notify(string, string) error
}
@ -183,3 +184,40 @@ func (ln LibNotifier) Notify(title, body string) error {
},
)
}
// xnotifier can push notifications to mac, linux and windows.
type xnotifier struct {
*notificator.Notificator
iconPath string
}
func newXnotifier(iconPath string) xnotifier {
// Write the built-in tomato icon if it
// doesn't already exist.
_, err := os.Stat(iconPath)
if os.IsNotExist(err) {
raw := MustAsset("tomato-icon.png")
_ = ioutil.WriteFile(iconPath, raw, 0644)
}
return xnotifier{
Notificator: notificator.New(notificator.Options{}),
iconPath: iconPath,
}
}
// Notify sends a notification to the OS.
func (n xnotifier) Notify(title, body string) error {
return n.Push(title, body, n.iconPath, notificator.UR_NORMAL)
}
type DarwinNotifier = xnotifier
func NewDarwinNotifier(iconPath string) DarwinNotifier {
return newXnotifier(iconPath)
}
type WindowsNotifier = xnotifier
func NewWindowsNotifier(iconPath string) WindowsNotifier {
return newXnotifier(iconPath)
}