reduce notification spam

This commit is contained in:
Jan Delta 2023-05-29 06:41:21 -06:00
parent 39defbd14c
commit e3329ce828
Signed by: jande
SSH Key Fingerprint: SHA256:vq7/hn649YZqsP7GxjkV61SW7nqjNIFEQAvnKR4yGHk
1 changed files with 21 additions and 19 deletions

40
main.go
View File

@ -21,6 +21,8 @@ import (
const iconpath = "/data/drive/jan/hotreload/icon.png"
var enableNotify = os.Getenv("GOHRL_NO_NOTIFY") == ""
func logg(v ...any) {
spr := fmt.Sprintln(v...)
fmt.Print("\x1B[32m", time.Now().Format("15:04:05.000"), " \x1B[93m", spr[:len(spr)-1], "\x1B[0m\n")
@ -68,16 +70,16 @@ func main() {
// build loop
go func() {
var not *notify.NotifyNotification
//var not = notify.NotificationNew("updating", strings.Join(changes, "\n"), iconpath)
change <- struct{}{} // make sure it builds once off the bat
for cont {
<-change
logg("change detected", changes, "building")
not = notify.NotificationNew("updating", strings.Join(changes, "\n"), iconpath)
not.SetTimeout(4000)
not.Show()
//not.Update("updating", strings.Join(changes, "\n"), iconpath)
//not.SetTimeout(500)
//not.Show()
cmd := exec.Command("go", "build", "-o", tdir+"/build", name)
cmd.Stdout = os.Stdout
@ -105,7 +107,7 @@ func main() {
// application run loop
go func() {
var not *notify.NotifyNotification
var not = notify.NotificationNew("app running", "", iconpath)
var rapid = 0
@ -138,8 +140,9 @@ func main() {
exit <- struct{}{}
}()
if not != nil {
not.Update("updated applied", "now running", iconpath)
if not != nil && enableNotify {
not.Update("update applied", strings.Join(changes, "\n"), iconpath)
not.SetTimeout(1000)
not.Show()
}
@ -150,9 +153,9 @@ func main() {
kill()
case <-updated:
logg("restarting to apply update")
not = notify.NotificationNew("restarting to apply updates", strings.Join(changes, "\n"), iconpath)
not.SetTimeout(3000)
not.Show()
//not.Update("restarting to apply updates", strings.Join(changes, "\n"), iconpath)
//not.SetTimeout(1000)
//not.Show()
kill()
case <-exit:
@ -169,14 +172,17 @@ func main() {
if rapid > 2 {
multip := rapid * (rapid / 2)
not := notify.NotificationNew("delaying restart due to rapid exiting", fmt.Sprint(time.Second*time.Duration(multip)), iconpath)
not.Show()
if enableNotify {
not.Update("delaying restart due to rapid exiting", fmt.Sprint(time.Second*time.Duration(multip)), iconpath)
not.Show()
}
timer := time.NewTimer(time.Second * time.Duration(multip))
select {
case <-timer.C:
case <-updated:
case <-sc:
os.Exit(1)
}
}
}
@ -201,6 +207,9 @@ func hash() ([]string, bool) {
var changes = []string{}
err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
logg(err)
}
if !strings.HasSuffix(d.Name(), ".go") {
return nil
}
@ -211,13 +220,6 @@ func hash() ([]string, bool) {
}
defer dat.Close()
var pfx = make([]byte, len("package"))
dat.Read(pfx)
if string(pfx) != "package" {
return nil
}
dat.Seek(0, 0)
h := fnv.New128()
_, err = io.Copy(h, dat)
if err != nil {