You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.1 KiB
Go
99 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
"time"
|
|
|
|
disabledicon "gitea.ronald1985.uk/ronald1985/Eye-Reminder/icons/disabledicon"
|
|
enabledicon "gitea.ronald1985.uk/ronald1985/Eye-Reminder/icons/enabledicon"
|
|
|
|
"github.com/gen2brain/beeep"
|
|
"github.com/getlantern/systray"
|
|
ge "github.com/ronaldr1985/graceful-exit"
|
|
)
|
|
|
|
const (
|
|
TIME_INBETWEEN_NOTIFICATIONS = 20 * time.Minute
|
|
)
|
|
|
|
func SendNotification(title string, message string) bool {
|
|
path, err := exec.LookPath("herbe")
|
|
if err == nil {
|
|
var args []string
|
|
args = append(args, title, message)
|
|
cmd := exec.Command(path, args...)
|
|
out, err := cmd.CombinedOutput()
|
|
if out == nil && err == nil {
|
|
return true
|
|
}
|
|
} else if strings.Contains(err.Error(), "executable file not found in ") {
|
|
err := beeep.Notify(title, message, "assets/Eye-Reminder-Icon.png")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func systrayOnReady() {
|
|
var enabled bool = true
|
|
systray.SetTitle("Eye Reminder")
|
|
systray.SetTooltip("Eye Reminder")
|
|
systray.SetIcon(enabledicon.Data)
|
|
mQuitOrig := systray.AddMenuItem("Quit", "Quit the whole app")
|
|
|
|
go func() {
|
|
<-mQuitOrig.ClickedCh
|
|
fmt.Println("Requesting quit")
|
|
systray.Quit()
|
|
fmt.Println("Finished quitting")
|
|
}()
|
|
|
|
go func() {
|
|
lastTimeNotificationWasSent := time.Now().Add(-20 * time.Minute)
|
|
|
|
for {
|
|
if enabled && time.Since(lastTimeNotificationWasSent) > TIME_INBETWEEN_NOTIFICATIONS {
|
|
SendNotification("Eye Reminder", "Look away for the screen for atleast 20 seconds")
|
|
|
|
lastTimeNotificationWasSent = time.Now()
|
|
}
|
|
}
|
|
}()
|
|
|
|
go func() {
|
|
systray.AddSeparator()
|
|
mEnabled := systray.AddMenuItemCheckbox("Enabled", "Check Me", true)
|
|
|
|
for {
|
|
select {
|
|
case <-mEnabled.ClickedCh:
|
|
if mEnabled.Checked() {
|
|
mEnabled.Uncheck()
|
|
|
|
enabled = false
|
|
|
|
systray.SetIcon(disabledicon.Data)
|
|
} else {
|
|
mEnabled.Check()
|
|
|
|
enabled = true
|
|
|
|
systray.SetIcon(enabledicon.Data)
|
|
}
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
func main() {
|
|
ge.HandleSignals(false)
|
|
|
|
systrayOnExit := func() {
|
|
}
|
|
systray.Run(systrayOnReady, systrayOnExit)
|
|
}
|