only use libnotify on Linux
This commit is contained in:
parent
3389d46410
commit
70fa81c663
11
main.go
11
main.go
|
@ -4,10 +4,18 @@ import (
|
|||
"encoding/json"
|
||||
"github.com/jawher/mow.cli"
|
||||
"os"
|
||||
"runtime"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
func notifier() Notifier {
|
||||
if runtime.GOOS == "linux" {
|
||||
return NewLibNotifier()
|
||||
}
|
||||
return NoopNotifier{}
|
||||
}
|
||||
|
||||
func start(path *string) func(*cli.Cmd) {
|
||||
return func(cmd *cli.Cmd) {
|
||||
cmd.Spec = "[OPTIONS] MESSAGE"
|
||||
|
@ -29,11 +37,10 @@ func start(path *string) func(*cli.Cmd) {
|
|||
NPomodoros: *pomodoros,
|
||||
Duration: parsed,
|
||||
}
|
||||
runner, err := NewTaskRunner(task, db)
|
||||
runner, err := NewTaskRunner(task, db, notifier())
|
||||
maybe(err)
|
||||
runner.Start()
|
||||
startUI(runner)
|
||||
//maybe(runner.Run())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
6
task.go
6
task.go
|
@ -19,7 +19,7 @@ type TaskRunner struct {
|
|||
duration time.Duration
|
||||
}
|
||||
|
||||
func NewTaskRunner(task *Task, store *Store) (*TaskRunner, error) {
|
||||
func NewTaskRunner(task *Task, store *Store, notifier Notifier) (*TaskRunner, error) {
|
||||
taskID, err := store.CreateTask(*task)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -33,7 +33,7 @@ func NewTaskRunner(task *Task, store *Store) (*TaskRunner, error) {
|
|||
state: State(0),
|
||||
pause: make(chan bool),
|
||||
toggle: make(chan bool),
|
||||
notifier: NewLibNotifier(),
|
||||
notifier: notifier,
|
||||
duration: task.Duration,
|
||||
}
|
||||
return tr, nil
|
||||
|
@ -97,6 +97,8 @@ func (t *TaskRunner) run() error {
|
|||
if t.count == t.nPomodoros {
|
||||
break
|
||||
}
|
||||
|
||||
t.notifier.Notify("Pomo", "It is time to take a break!")
|
||||
// Reset the duration incase it
|
||||
// was paused.
|
||||
t.duration = t.origDuration
|
||||
|
|
|
@ -21,7 +21,7 @@ func TestTaskRunner(t *testing.T) {
|
|||
Duration: time.Second * 2,
|
||||
NPomodoros: 2,
|
||||
Message: fmt.Sprint("Test Task"),
|
||||
}, store)
|
||||
}, store, NoopNotifier{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue