-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
46 lines (37 loc) · 1.01 KB
/
main.go
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
39
40
41
42
43
44
45
46
package main
import (
"os"
"time"
)
func DesiredDisplays(displays StringSet, activeDisplays StringSet) StringSet {
if len(displays) == 0 {
return activeDisplays
}
return Intersection(displays, activeDisplays)
}
func tick(watcher *Watcher, params Parameters) {
battery, err := LoadBatteryInfo(params.uevent)
if err != nil {
logWarning("Skipping this cycle due to errors occurred.")
return
}
displays := DesiredDisplays(params.displays, ActiveDisplays())
if !battery.Charging() && battery.Capacity <= params.threshold {
messages := ShowAll(params.message, watcher.MessagesFor(displays))
watcher.Update(messages, battery.Status)
}
if battery.Charging() && battery.Status != watcher.Status() {
messages := watcher.Messages()
CloseAll(messages)
watcher.Update(messages, battery.Status)
watcher.CleanUp(displays)
}
}
func main() {
params := CommandLineParameters(os.Args[1:])
watcher := NewWatcher()
tick(&watcher, params)
for range time.Tick(params.interval) {
tick(&watcher, params)
}
}