create pop ups

master
Bel LaPointe 2020-02-18 08:43:42 -07:00
parent 4835c24868
commit 874b93f6e0
10 changed files with 22 additions and 6 deletions

0
basicstopwatch.go Normal file → Executable file
View File

0
basictimer.go Normal file → Executable file
View File

0
config.go Normal file → Executable file
View File

0
keyboard.go Normal file → Executable file
View File

0
keyboard_test.go Normal file → Executable file
View File

0
main.go Normal file → Executable file
View File

0
tickprinter.go Normal file → Executable file
View File

0
tickprinter_test.go Normal file → Executable file
View File

28
timer.go Normal file → Executable file
View 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()
}

0
with.go Normal file → Executable file
View File