create pop ups
parent
4835c24868
commit
874b93f6e0
|
|
@ -1,17 +1,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/everdev/mack"
|
||||
)
|
||||
|
||||
type Typed func(*Timer) string
|
||||
|
||||
type Timer struct {
|
||||
config Config
|
||||
From time.Time
|
||||
Typed Typed
|
||||
paused bool
|
||||
offset time.Duration
|
||||
config Config
|
||||
From time.Time
|
||||
Typed Typed
|
||||
paused bool
|
||||
offset time.Duration
|
||||
displayed bool
|
||||
}
|
||||
|
||||
func NewTimer(config Config) (*Timer, error) {
|
||||
|
|
@ -61,7 +65,17 @@ func (t *Timer) setTyped(config Config) error {
|
|||
}
|
||||
|
||||
func (t *Timer) Remaining() time.Duration {
|
||||
return time.Until(t.Deadline()) + time.Second
|
||||
remaining := time.Until(t.Deadline()) + time.Second
|
||||
if remaining < 0 && !t.displayed {
|
||||
t.displayed = true
|
||||
go func() {
|
||||
_, err := mack.Alert(fmt.Sprintf("Timer for %s done", t.config.Msg))
|
||||
if err == nil {
|
||||
t.Ack()
|
||||
}
|
||||
}()
|
||||
}
|
||||
return remaining
|
||||
}
|
||||
|
||||
func (t *Timer) Deadline() time.Time {
|
||||
|
|
@ -76,9 +90,11 @@ func (t *Timer) Ack() {
|
|||
for t.Done() {
|
||||
t.From = t.From.Add(t.config.Duration)
|
||||
}
|
||||
t.displayed = false
|
||||
}
|
||||
|
||||
func (t *Timer) Reset() {
|
||||
t.Ack()
|
||||
t.From = time.Now()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue