Parse message lvl and menu for setting it.

This commit is contained in:
Marcel Otte 2022-06-08 09:48:26 +02:00
parent cfc37e575f
commit cade8cc379
1 changed files with 57 additions and 19 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net" "net"
"strconv"
"time" "time"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
@ -18,7 +19,7 @@ var (
config backive.Configuration config backive.Configuration
db backive.Database db backive.Database
doNotShowUntil time.Time = time.Unix(0, 0) doNotShowUntil time.Time = time.Unix(0, 0)
c net.Conn c net.Conn
) )
func Init(a fyne.App, w fyne.Window, conf backive.Configuration, d backive.Database) { func Init(a fyne.App, w fyne.Window, conf backive.Configuration, d backive.Database) {
@ -63,16 +64,6 @@ func NotificationRun() {
// we just try again and discard the error // we just try again and discard the error
err = nil err = nil
} }
/*
if doNotShowUntil == time.Unix(0, 0) || time.Now().After(doNotShowUntil) {
ShowNotification()
if doNotShowUntil != time.Unix(0, 0) {
doNotShowUntil = time.Unix(0, 0)
}
}
h, _ := time.ParseDuration("15m")
time.Sleep(h)
//*/
} }
func ShowNotification(data map[string]string) { func ShowNotification(data map[string]string) {
@ -87,21 +78,68 @@ func ShowNotification(data map[string]string) {
} }
func ShallShow(data map[string]string) bool { func ShallShow(data map[string]string) bool {
level, err := strconv.ParseUint(data["level"], 10, 64)
if err != nil {
return false
}
if level <= 10 {
return true
}
return true return true
} }
func SetHideUntil(until time.Time) {
}
func SetMessageLevel(level int) {
}
func makeTray(app fyne.App) { func makeTray(app fyne.App) {
if desk, ok := app.(desktop.App); ok { if desk, ok := app.(desktop.App); ok {
hideReminders := fyne.NewMenuItem(
"Hide Reminders for",
nil,
)
hideReminders.ChildMenu = fyne.NewMenu(
"",
fyne.NewMenuItem("Hide reminder notifications for today", func() {
doNotShowUntil = time.Now().AddDate(0, 0, 1)
SetHideUntil(doNotShowUntil)
}),
fyne.NewMenuItem("Hide reminder notifications for a hour", func() {
doNotShowUntil = time.Now().Add(time.Hour)
SetHideUntil(doNotShowUntil)
}),
)
levelMenu := fyne.NewMenuItem(
"Set notification level", nil,
)
levelMenu.ChildMenu = fyne.NewMenu(
"",
fyne.NewMenuItem(
"Only problems and tasks finished (resets to default with restart)",
func() { SetMessageLevel(10) },
),
fyne.NewMenuItem(
"+ Reminders (default)",
func() { SetMessageLevel(20) },
),
fyne.NewMenuItem(
"+ Informational messages",
func() { SetMessageLevel(30) },
),
fyne.NewMenuItem(
"+ Verbose/Debug messages",
func() { SetMessageLevel(40) },
),
)
menu := fyne.NewMenu( menu := fyne.NewMenu(
"backive", "backive",
fyne.NewMenuItem("Show notifications again", func() { hideReminders,
}), levelMenu,
fyne.NewMenuItem("Hide notifications for today", func() {
doNotShowUntil = time.Now().AddDate(0, 0, 1)
}),
fyne.NewMenuItem("Hide notifications for a hour", func() {
doNotShowUntil = time.Now().Add(time.Hour)
}),
) )
desk.SetSystemTrayMenu(menu) desk.SetSystemTrayMenu(menu)
} }