-
Notifications
You must be signed in to change notification settings - Fork 0
/
onpar.go
82 lines (71 loc) · 2.18 KB
/
onpar.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"log"
"os/exec"
"strings"
"time"
)
var (
status = []string{}
)
type Component struct {
path string
Output string
interval int
Channel chan string
}
func NewComponent(path string, interval int) *Component {
return &Component{path: path, interval: interval, Channel: make(chan string)}
}
func (c *Component) Run() {
time.Sleep(time.Duration(c.interval) * time.Second)
response, err := exec.Command(c.path).Output()
if err != nil {
log.Fatal(err)
}
c.Channel <- strings.TrimSpace(string(response))
}
func main() {
dateTimeComponent := NewComponent("date_time_component.sh", 1)
batteryLevelComponent := NewComponent("battery_level_component", 1)
volumeLevelComponent := NewComponent("volume_level_component", 1)
darkSkyWeatherComponent := NewComponent("dark_sky_weather_component", 600)
keyboardLayoutComponent := NewComponent("keyboard_layout_component", 1)
musicComponent := NewComponent("music_component", 2)
// Initialize new components here ...
go dateTimeComponent.Run()
go batteryLevelComponent.Run()
go volumeLevelComponent.Run()
go darkSkyWeatherComponent.Run()
go keyboardLayoutComponent.Run()
go musicComponent.Run()
// Call new components Run() here ...
for {
select {
case dateTimeComponent.Output = <-dateTimeComponent.Channel:
go dateTimeComponent.Run()
case darkSkyWeatherComponent.Output = <-darkSkyWeatherComponent.Channel:
go darkSkyWeatherComponent.Run()
case keyboardLayoutComponent.Output = <-keyboardLayoutComponent.Channel:
go keyboardLayoutComponent.Run()
case batteryLevelComponent.Output = <-batteryLevelComponent.Channel:
go batteryLevelComponent.Run()
case volumeLevelComponent.Output = <-volumeLevelComponent.Channel:
go volumeLevelComponent.Run()
case musicComponent.Output = <-musicComponent.Channel:
go musicComponent.Run()
// Call new components Run() here ...
}
status = []string{
"",
// Add new components here ...
musicComponent.Output,
keyboardLayoutComponent.Output,
darkSkyWeatherComponent.Output,
volumeLevelComponent.Output,
batteryLevelComponent.Output,
dateTimeComponent.Output,
}
exec.Command("xsetroot", "-name", strings.Join(status, " ")).Run()
}
}