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
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user