Merge branch 'master' of github.com:JackMordaunt/pomo into JackMordaunt-master
This commit is contained in:
commit
af9be87671
10
main.go
10
main.go
|
@ -2,16 +2,22 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/jawher/mow.cli"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jawher/mow.cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func notifier(iconPath string) Notifier {
|
func notifier(iconPath string) Notifier {
|
||||||
if runtime.GOOS == "linux" {
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
return NewLibNotifier(iconPath)
|
return NewLibNotifier(iconPath)
|
||||||
|
case "darwin":
|
||||||
|
return NewDarwinNotifier(iconPath)
|
||||||
|
case "windows":
|
||||||
|
return NewWindowsNotifier(iconPath)
|
||||||
}
|
}
|
||||||
return NoopNotifier{}
|
return NoopNotifier{}
|
||||||
}
|
}
|
||||||
|
|
42
types.go
42
types.go
|
@ -3,11 +3,13 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fatih/color"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/0xAX/notificator"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
|
||||||
"github.com/kevinschoon/pomo/libnotify"
|
"github.com/kevinschoon/pomo/libnotify"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -142,7 +144,6 @@ func (p Pomodoro) Duration() time.Duration {
|
||||||
|
|
||||||
// Notifier implements a system specific
|
// Notifier implements a system specific
|
||||||
// notification. On Linux this libnotify.
|
// notification. On Linux this libnotify.
|
||||||
// TODO: OSX, Windows(?)
|
|
||||||
type Notifier interface {
|
type Notifier interface {
|
||||||
Notify(string, string) error
|
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