-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlistener_activity.go
More file actions
38 lines (30 loc) · 864 Bytes
/
listener_activity.go
File metadata and controls
38 lines (30 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"time"
"github.com/prashantgupta24/mac-sleep-notifier/notifier"
)
func (a *app) activityListener() {
for {
activity := <-a.notifierCh
fmt.Printf("(%v) new event: %v\n", time.Now(), activity.Type)
switch activity.Type {
case notifier.Sleep:
fmt.Println("Sleeping")
a.isSleeping = true
case notifier.Awake:
now := time.Now()
totalIdleTime := calculateDuration(a.lastActiveTime, now)
fmt.Println("##########")
fmt.Printf("totalIdleTime = %v, now = %v, lastActiveTime = %v.\n", totalIdleTime, now, a.lastActiveTime)
fmt.Println("##########")
if totalIdleTime > a.maxAllowedIdleTime {
a.addActivePeriodEntry(a.lastIdleTime, a.lastActiveTime)
a.addBreakEntry(a.lastActiveTime, now)
a.lastIdleTime = time.Now()
}
a.checkAndCleanExpiredTimeLogs()
a.isSleeping = false
}
}
}