create pop ups
parent
4835c24868
commit
874b93f6e0
|
|
@ -1,17 +1,21 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/everdev/mack"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Typed func(*Timer) string
|
type Typed func(*Timer) string
|
||||||
|
|
||||||
type Timer struct {
|
type Timer struct {
|
||||||
config Config
|
config Config
|
||||||
From time.Time
|
From time.Time
|
||||||
Typed Typed
|
Typed Typed
|
||||||
paused bool
|
paused bool
|
||||||
offset time.Duration
|
offset time.Duration
|
||||||
|
displayed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTimer(config Config) (*Timer, error) {
|
func NewTimer(config Config) (*Timer, error) {
|
||||||
|
|
@ -61,7 +65,17 @@ func (t *Timer) setTyped(config Config) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Timer) Remaining() time.Duration {
|
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 {
|
func (t *Timer) Deadline() time.Time {
|
||||||
|
|
@ -76,9 +90,11 @@ func (t *Timer) Ack() {
|
||||||
for t.Done() {
|
for t.Done() {
|
||||||
t.From = t.From.Add(t.config.Duration)
|
t.From = t.From.Add(t.config.Duration)
|
||||||
}
|
}
|
||||||
|
t.displayed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Timer) Reset() {
|
func (t *Timer) Reset() {
|
||||||
|
t.Ack()
|
||||||
t.From = time.Now()
|
t.From = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue