|
|
|
|
@ -23,6 +23,7 @@ import (
|
|
|
|
|
const (
|
|
|
|
|
DEFAULT_TIME_INBETWEEN_NOTIFICATIONS = 20 * time.Minute
|
|
|
|
|
EYE_REMINDER_ICON_URL = "https://gitea.ronald1985.uk/ronald1985/Eye-Reminder/raw/branch/master/assets/Eye-Reminder-Icon.png"
|
|
|
|
|
DEFAULT_CONFIG_FILE = "Interval: 20"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
|
@ -128,7 +129,7 @@ func systrayOnReady() {
|
|
|
|
|
lastTimeNotificationWasSent := time.Now().Add(time.Duration(-ProgramConfig.Interval) * time.Minute)
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
if enabled && time.Since(lastTimeNotificationWasSent) > time.Duration(ProgramConfig.Interval) {
|
|
|
|
|
if enabled && time.Since(lastTimeNotificationWasSent) > time.Duration(ProgramConfig.Interval)*time.Minute {
|
|
|
|
|
fmt.Println("Sending notification")
|
|
|
|
|
|
|
|
|
|
SendNotification("Eye Reminder", "Look away for the screen for atleast 20 seconds")
|
|
|
|
|
@ -166,66 +167,77 @@ func systrayOnReady() {
|
|
|
|
|
func main() {
|
|
|
|
|
ge.HandleSignals(false)
|
|
|
|
|
|
|
|
|
|
var possibleConfigFileLocations []string
|
|
|
|
|
possibleConfigFileLocations = append(possibleConfigFileLocations, os.Getenv("HOME")+"/.config/Eye-Reminder/config.yaml")
|
|
|
|
|
possibleConfigFileLocations = append(possibleConfigFileLocations, os.Getenv("HOME")+"/.config/Eye-Reminder/config.yml")
|
|
|
|
|
possibleConfigFileLocations = append(possibleConfigFileLocations, os.Getenv("XDG_CONFIG_HOME")+"/Eye-Reminder/config.yaml")
|
|
|
|
|
possibleConfigFileLocations = append(possibleConfigFileLocations, os.Getenv("XDG_CONFIG_HOME")+"/Eye-Reminder/config.yml")
|
|
|
|
|
possibleConfigFileLocations = append(possibleConfigFileLocations, os.Getenv("LOCALAPPDATA")+"/Eye-Reminder/config.yml")
|
|
|
|
|
possibleConfigFileLocations = append(possibleConfigFileLocations, os.Getenv("LOCALAPPDATA")+"/Eye-Reminder/config.yml")
|
|
|
|
|
ProgramConfig.Interval = int(DEFAULT_TIME_INBETWEEN_NOTIFICATIONS)
|
|
|
|
|
|
|
|
|
|
configFileLocation := "not found"
|
|
|
|
|
var possibleAppDirectoryLocations []string
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("HOME")+"/.config/Eye-Reminder/")
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("HOME")+"/.config/Eye-Reminder/")
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("XDG_CONFIG_HOME")+"/Eye-Reminder/")
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("XDG_CONFIG_HOME")+"/Eye-Reminder/")
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("LOCALAPPDATA")+"/Eye-Reminder/")
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("LOCALAPPDATA")+"/Eye-Reminder/")
|
|
|
|
|
|
|
|
|
|
for _, file := range possibleConfigFileLocations {
|
|
|
|
|
if fileExists, err := CheckIfFileExists(file); fileExists {
|
|
|
|
|
configFileLocation = file
|
|
|
|
|
appDirectory := "not found"
|
|
|
|
|
for _, folder := range possibleAppDirectoryLocations {
|
|
|
|
|
if _, err := os.Stat(folder); !os.IsNotExist(err) {
|
|
|
|
|
appDirectory = folder
|
|
|
|
|
break
|
|
|
|
|
} else if err != nil {
|
|
|
|
|
fmt.Fprintln(os.Stderr, "Error checking for config file:", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
appDirectory := "not found"
|
|
|
|
|
if configFileLocation == "not found" {
|
|
|
|
|
ProgramConfig.Interval = int(DEFAULT_TIME_INBETWEEN_NOTIFICATIONS)
|
|
|
|
|
|
|
|
|
|
var possibleAppDirectoryLocations []string
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("HOME")+"/.config/Eye-Reminder/")
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("HOME")+"/.config/Eye-Reminder/")
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("XDG_CONFIG_HOME")+"/Eye-Reminder/")
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("XDG_CONFIG_HOME")+"/Eye-Reminder/")
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("LOCALAPPDATA")+"/Eye-Reminder/")
|
|
|
|
|
possibleAppDirectoryLocations = append(possibleAppDirectoryLocations, os.Getenv("LOCALAPPDATA")+"/Eye-Reminder/")
|
|
|
|
|
|
|
|
|
|
for _, folder := range possibleAppDirectoryLocations {
|
|
|
|
|
if _, err := os.Stat(folder); !os.IsNotExist(err) {
|
|
|
|
|
appDirectory = folder
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
if appDirectory == "not found" {
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
appDirectory = DEFAULT_WINDOWS_DIRECTORY
|
|
|
|
|
} else {
|
|
|
|
|
appDirectory = DEFAULT_UNIX_DIRECTORY
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if appDirectory == "not found" {
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
appDirectory = DEFAULT_WINDOWS_DIRECTORY
|
|
|
|
|
} else {
|
|
|
|
|
appDirectory = DEFAULT_UNIX_DIRECTORY
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("Creating config directory:", appDirectory)
|
|
|
|
|
err := os.Mkdir(appDirectory, 0755)
|
|
|
|
|
fmt.Println("Created folder:", appDirectory)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println("Creating config directory:", appDirectory)
|
|
|
|
|
err := os.Mkdir(appDirectory, 0755)
|
|
|
|
|
fmt.Println("Created folder:", appDirectory)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
configFile := ""
|
|
|
|
|
if fileExists, err := CheckIfFileExists(appDirectory + "config.yaml"); fileExists {
|
|
|
|
|
configFile = appDirectory + "config.yaml"
|
|
|
|
|
} else if !fileExists && err == nil {
|
|
|
|
|
if fileExists, _ := CheckIfFileExists(appDirectory + "config.yml"); fileExists {
|
|
|
|
|
configFile = appDirectory + "config.yml"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
appDirectory = configFileLocation[:strings.IndexByte(configFileLocation, '/')+1]
|
|
|
|
|
ProgramConfig, err = ReadConfig(configFileLocation)
|
|
|
|
|
if configFile != "" {
|
|
|
|
|
fmt.Println("Found config file at", configFile)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if configFile == "" {
|
|
|
|
|
configFile = appDirectory + "config.yaml"
|
|
|
|
|
|
|
|
|
|
fmt.Println("Creating config file:", configFile)
|
|
|
|
|
f, err := os.Create(configFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
print_fatal_error("Failed to create config file")
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("Created config file:", configFile)
|
|
|
|
|
|
|
|
|
|
fmt.Println("Writing default config to", configFile)
|
|
|
|
|
_, err = f.WriteString(DEFAULT_CONFIG_FILE)
|
|
|
|
|
if err != nil {
|
|
|
|
|
f.Close()
|
|
|
|
|
print_fatal_error("Failed to write to config file: ", configFile)
|
|
|
|
|
}
|
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
|
|
fmt.Println("Written default config to ", configFile)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
ProgramConfig, err = ReadConfig(configFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
print_fatal_error("Failed to read config file")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProgramConfig.imageLocation = appDirectory + "Eye-Reminder-Icon.png"
|
|
|
|
|
|