diff --git a/.gitignore b/.gitignore index 0fda4a0..635c063 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ tags bin/* !bin/.gitkeep dist/ +Pominal diff --git a/README.md b/README.md index 84e650c..d9d8302 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # Pominal Pominal is a Pomodoro application for the terminal. Pominal is written in Go. + +## Assets + +Icon [image](https://pixabay.com/vectors/eat-edible-food-fruit-red-tomato-1299904/) from [OpenClipart-Vectors](https://pixabay.com/users/openclipart-vectors-30363/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1299904) from [Pixabay](https://pixabay.com/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1299904) diff --git a/alerts.go b/alerts.go new file mode 100644 index 0000000..6ae4176 --- /dev/null +++ b/alerts.go @@ -0,0 +1,62 @@ +/* + Pominal + Copyright (C) 2019 Daniel Anglin + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package main + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/0xAX/notificator" +) + +const iconPath string = "assets/icon/tomato.png" + +var notifier *notificator.Notificator + +// initNotifier initialises the new desktop notifier. +func initNotifier() { + notifier = notificator.New(notificator.Options{ + DefaultIcon: getIconPath(), + AppName: "Pominal", + }) +} + +// getIconPath returns the absolute path of the tomoato icon +// used for desktop notifications. +// If there is an error getting the path to the executing program +// then an empty string is returned. +func getIconPath() string { + + var result string + exe, err := os.Executable() + if err != nil { + fmt.Printf("ERROR: Unable to determine path to this executable. %s", err.Error()) + return result + } + result = filepath.Dir(exe) + "/" + iconPath + return result +} + +// alert pushes a desktop notification +func alert(oldLabel, newLabel string) { + title := oldLabel + " timer has stopped" + text := newLabel + " timer has started" + notifier.Push(title, text, "", notificator.UR_NORMAL) +} diff --git a/assets/icon/tomato.png b/assets/icon/tomato.png new file mode 100644 index 0000000..c9214b8 Binary files /dev/null and b/assets/icon/tomato.png differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2fabc46 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module gitlab.com/dananglin/Pominal + +go 1.12 + +require github.com/0xAX/notificator v0.0.0-20181105090803-d81462e38c21 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b4a5680 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/0xAX/notificator v0.0.0-20181105090803-d81462e38c21 h1:moSC7ACaTejHmVRRwfDTMgByRSwjg2vZooncdWLj7o8= +github.com/0xAX/notificator v0.0.0-20181105090803-d81462e38c21/go.mod h1:NtXa9WwQsukMHZpjNakTTz0LArxvGYdPA9CjIcUSZ6s= diff --git a/main.go b/main.go index 4b36d6b..0da4410 100644 --- a/main.go +++ b/main.go @@ -70,6 +70,8 @@ func main() { os.Exit(0) } + initNotifier() + workTimeDuration, err := time.ParseDuration(workTimer) if err != nil { fmt.Printf("ERROR: Unable to set the work timer. %s", err.Error()) @@ -128,7 +130,8 @@ infinite: fmt.Printf("\n%s timer has finished\n", p.label) p.timer.Stop() t.Stop() - time.Sleep(2 * time.Second) + time.Sleep(1 * time.Second) + oldLabel := p.label switch p.label { case workTimerLabel: if workCycleCount >= p.maxWorkCycles { @@ -145,6 +148,8 @@ infinite: p.Start(workTimerLabel, workCycleCount) } t = time.NewTicker(1 * time.Second) + newLabel := p.label + alert(oldLabel, newLabel) } } } @@ -195,6 +200,7 @@ func printScreen(remaining float64, pominalCount, workCycle, maxWorkCycle int, l } // clearScreen clears the terminal screen +// TODO: To be removed when TUI is implemented func clearScreen() { cmd := exec.Command("clear") cmd.Stdout = os.Stdout