Merge branch 'JackMordaunt-master'
This commit is contained in:
commit
51aaa9c19f
10
main.go
10
main.go
|
@ -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{}
|
||||
}
|
||||
|
|
42
types.go
42
types.go
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue