From e3329ce828303712936dc9e1c2a6c4af5fe3ba10 Mon Sep 17 00:00:00 2001 From: delta Date: Mon, 29 May 2023 06:41:21 -0600 Subject: [PATCH] reduce notification spam --- main.go | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index 496d4c6..3f3230a 100644 --- a/main.go +++ b/main.go @@ -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 {