pominal/alert.go
Dan Anglin 19eb9b20be
feat: support configuring Pominal with config file
This commit adds a feature to load Pominal
configuration from a JSON configuration file.

A new data type called PominalConfig was created for
the purpose of configuring Pominal.
A new factory function called newPominalConfig was
created which takes the path to the JSON configuration
file and the flag overrides and generates the new
PominalConfig value.

Here, the JSON config is parsed to create the initial
configuration and any flag overrides can override
the corresponding fields in the PominalConfig object.
Currently only the sessions times and the maximum work
sessions per Pominal cycle have flag overrides.

Additionally users can now configure custom notification
messages for each session type from the configuration file.
There are currently no flag overrides for these.

This commit resolves dananglin/Pominal#1
2020-02-13 12:42:55 +00:00

66 lines
1.8 KiB
Go

/*
Pominal
Copyright (C) 2020 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"
// initNotifier initialises the new desktop notifier.
func initNotifier() *notificator.Notificator {
return notificator.New(notificator.Options{
DefaultIcon: getNotificationIconPath(),
AppName: "Pominal",
})
}
// getNotificationIconPath 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 getNotificationIconPath() 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 creates a new desktop notification.
func desktopAlert(label, msg string, notifier *notificator.Notificator) {
if len(msg) == 0 {
msg = fmt.Sprintf(defaultNotificationMsgFmt, label)
}
title := fmt.Sprintf("Pominal session: %s", label)
_ = notifier.Push(title, msg, "", notificator.UR_NORMAL)
}