[*] Added wrappers around type notificator to indicate which OS are supported by it.
This commit is contained in:
parent
9c21245767
commit
18d97db12a
4
main.go
4
main.go
|
@ -15,9 +15,9 @@ func notifier(iconPath string) Notifier {
|
||||||
case "linux":
|
case "linux":
|
||||||
return NewLibNotifier(iconPath)
|
return NewLibNotifier(iconPath)
|
||||||
case "darwin":
|
case "darwin":
|
||||||
return NewAllNotifier(iconPath)
|
return NewDarwinNotifier(iconPath)
|
||||||
case "windows":
|
case "windows":
|
||||||
return NewAllNotifier(iconPath)
|
return NewWindowsNotifier(iconPath)
|
||||||
}
|
}
|
||||||
return NoopNotifier{}
|
return NoopNotifier{}
|
||||||
}
|
}
|
||||||
|
|
25
types.go
25
types.go
|
@ -7,7 +7,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/0xAX/notificator"
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
|
|
||||||
"github.com/kevinschoon/pomo/libnotify"
|
"github.com/kevinschoon/pomo/libnotify"
|
||||||
|
@ -185,15 +184,13 @@ func (ln LibNotifier) Notify(title, body string) error {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllNotifier can push notifications to mac, linux and windows.
|
// notificator can push notifications to mac, linux and windows.
|
||||||
// Icon can be specified via file path.
|
type notificator struct {
|
||||||
type AllNotifier struct {
|
|
||||||
*notificator.Notificator
|
*notificator.Notificator
|
||||||
iconPath string
|
iconPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAllNotifier constructs an AllNotifier object.
|
func newNotificator(iconPath string) notificator {
|
||||||
func NewAllNotifier(iconPath string) AllNotifier {
|
|
||||||
// Write the built-in tomato icon if it
|
// Write the built-in tomato icon if it
|
||||||
// doesn't already exist.
|
// doesn't already exist.
|
||||||
_, err := os.Stat(iconPath)
|
_, err := os.Stat(iconPath)
|
||||||
|
@ -201,13 +198,25 @@ func NewAllNotifier(iconPath string) AllNotifier {
|
||||||
raw := MustAsset("tomato-icon.png")
|
raw := MustAsset("tomato-icon.png")
|
||||||
_ = ioutil.WriteFile(iconPath, raw, 0644)
|
_ = ioutil.WriteFile(iconPath, raw, 0644)
|
||||||
}
|
}
|
||||||
return AllNotifier{
|
return notificator{
|
||||||
Notificator: notificator.New(notificator.Options{}),
|
Notificator: notificator.New(notificator.Options{}),
|
||||||
iconPath: iconPath,
|
iconPath: iconPath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify sends a notification to the OS.
|
// Notify sends a notification to the OS.
|
||||||
func (n AllNotifier) Notify(title, body string) error {
|
func (n notificator) Notify(title, body string) error {
|
||||||
return n.Push(title, body, n.iconPath, notificator.UR_NORMAL)
|
return n.Push(title, body, n.iconPath, notificator.UR_NORMAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DarwinNotifier = notificator
|
||||||
|
|
||||||
|
func NewDarwinNotifier(iconPath string) DarwinNotifier {
|
||||||
|
return newNotificator(iconPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
type WindowsNotifier = notificator
|
||||||
|
|
||||||
|
func NewWindowsNotifier(iconPath string) WindowsNotifier {
|
||||||
|
return newNotificator(iconPath)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue