[+] Implemented cross platform notifications.
This commit is contained in:
parent
e06d8dd4ec
commit
9c21245767
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 NewAllNotifier(iconPath)
|
||||||
|
case "windows":
|
||||||
|
return NewAllNotifier(iconPath)
|
||||||
}
|
}
|
||||||
return NoopNotifier{}
|
return NoopNotifier{}
|
||||||
}
|
}
|
||||||
|
|
32
types.go
32
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,30 @@ func (ln LibNotifier) Notify(title, body string) error {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllNotifier can push notifications to mac, linux and windows.
|
||||||
|
// Icon can be specified via file path.
|
||||||
|
type AllNotifier struct {
|
||||||
|
*notificator.Notificator
|
||||||
|
iconPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAllNotifier constructs an AllNotifier object.
|
||||||
|
func NewAllNotifier(iconPath string) AllNotifier {
|
||||||
|
// 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 AllNotifier{
|
||||||
|
Notificator: notificator.New(notificator.Options{}),
|
||||||
|
iconPath: iconPath,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify sends a notification to the OS.
|
||||||
|
func (n AllNotifier) Notify(title, body string) error {
|
||||||
|
return n.Push(title, body, n.iconPath, notificator.UR_NORMAL)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue