main
parent
4e85f48d9e
commit
ca20b2a052
11
main.go
11
main.go
|
|
@ -14,7 +14,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/gen2brain/beeep"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -74,24 +73,22 @@ func alertAfter(ctx context.Context, ntfy string, duration string) error {
|
|||
}
|
||||
|
||||
func alertAt(ctx context.Context, ntfy string, deadline time.Time, title, msg string) error {
|
||||
n := int64(time.Until(deadline) / time.Second)
|
||||
bar := progressbar.Default(n)
|
||||
// n := int64(time.Until(deadline) / time.Second)
|
||||
c := time.NewTicker(time.Second)
|
||||
defer c.Stop()
|
||||
func() {
|
||||
ctx, can := context.WithDeadline(ctx, deadline)
|
||||
defer can()
|
||||
for {
|
||||
for ctx.Err() == nil {
|
||||
select {
|
||||
case <-c.C:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
bar.Add(1)
|
||||
fmt.Printf("\r%s ", deadline.Sub(time.Now()))
|
||||
}
|
||||
}()
|
||||
bar.Finish()
|
||||
bar.Exit()
|
||||
fmt.Println()
|
||||
|
||||
if err := ctx.Err(); err == nil {
|
||||
beeep.Alert(title, msg, "/dev/null")
|
||||
|
|
|
|||
Loading…
Reference in New Issue