create pop ups
This commit is contained in:
0
basicstopwatch.go
Normal file → Executable file
0
basicstopwatch.go
Normal file → Executable file
0
basictimer.go
Normal file → Executable file
0
basictimer.go
Normal file → Executable file
0
keyboard.go
Normal file → Executable file
0
keyboard.go
Normal file → Executable file
0
keyboard_test.go
Normal file → Executable file
0
keyboard_test.go
Normal file → Executable file
0
tickprinter.go
Normal file → Executable file
0
tickprinter.go
Normal file → Executable file
0
tickprinter_test.go
Normal file → Executable file
0
tickprinter_test.go
Normal file → Executable file
28
timer.go
Normal file → Executable file
28
timer.go
Normal file → Executable file
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user