Compare commits
2 Commits
572f129ddb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf9f50f583 | ||
|
|
d17993453e |
13
gcal.go
13
gcal.go
@@ -71,11 +71,18 @@ func (gcal *GCal) EventsToday(ctx context.Context) ([]Event, error) {
|
||||
d = t2.Sub(t)
|
||||
}
|
||||
|
||||
result = append(result, Event{
|
||||
Name: events.Items[i].Summary,
|
||||
result = append(result,
|
||||
Event{
|
||||
Name: "Soon: " + events.Items[i].Summary,
|
||||
Time: t.Add(-2 * time.Minute),
|
||||
Duration: 0,
|
||||
},
|
||||
Event{
|
||||
Name: "Now: " + events.Items[i].Summary,
|
||||
Time: t,
|
||||
Duration: d,
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
14
main.go
14
main.go
@@ -70,9 +70,17 @@ func alertsAfter(ctx context.Context, dur time.Duration, msg string) (chan strin
|
||||
deadline := time.Now().Add(dur)
|
||||
go func() {
|
||||
defer close(ch)
|
||||
var prev string
|
||||
for ctx.Err() == nil && time.Now().Before(deadline) {
|
||||
seconds := int(time.Until(deadline).Seconds())
|
||||
fmt.Printf("\r%v ", time.Duration(seconds)*time.Second)
|
||||
|
||||
cur := fmt.Sprintf("%v", time.Duration(seconds)*time.Second)
|
||||
if prev != "" {
|
||||
fmt.Printf("\r%s\r", strings.Repeat(" ", len(prev)))
|
||||
}
|
||||
fmt.Printf("%s", cur)
|
||||
prev = cur
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-time.After(time.Second):
|
||||
@@ -122,10 +130,11 @@ func alertsGCal(ctx context.Context) (chan string, error) {
|
||||
if err := refresh(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
case <-time.After(time.Until(events[0].Time.Add(-2 * time.Minute))):
|
||||
case <-time.After(time.Until(events[0].Time)):
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case ch <- events[0].Name:
|
||||
if events[0].Duration > 0 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-time.After(events[0].Duration):
|
||||
@@ -135,6 +144,7 @@ func alertsGCal(ctx context.Context) (chan string, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
events = events[1:]
|
||||
case <-ctx.Done():
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user