feat: added desktop notification integration
This commit is contained in:
parent
4daa57de82
commit
38ae9ed082
7 changed files with 81 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ tags
|
|||
bin/*
|
||||
!bin/.gitkeep
|
||||
dist/
|
||||
Pominal
|
||||
|
|
|
@ -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)
|
||||
|
|
62
alerts.go
Normal file
62
alerts.go
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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)
|
||||
}
|
BIN
assets/icon/tomato.png
Normal file
BIN
assets/icon/tomato.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 151 KiB |
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module gitlab.com/dananglin/Pominal
|
||||
|
||||
go 1.12
|
||||
|
||||
require github.com/0xAX/notificator v0.0.0-20181105090803-d81462e38c21
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -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=
|
8
main.go
8
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
|
||||
|
|
Loading…
Reference in a new issue