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