-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (71 loc) · 1.97 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
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 (
"fmt"
"os"
"runtime"
"github.com/afreakk/go-i3"
"github.com/afreakk/i3statusbear/internal/activewindow"
"github.com/afreakk/i3statusbear/internal/command"
"github.com/afreakk/i3statusbear/internal/config"
"github.com/afreakk/i3statusbear/internal/cpu"
"github.com/afreakk/i3statusbear/internal/datetime"
"github.com/afreakk/i3statusbear/internal/memory"
"github.com/afreakk/i3statusbear/internal/protocol"
"github.com/afreakk/i3statusbear/internal/pulseaudio"
"github.com/afreakk/i3statusbear/internal/readfile"
"github.com/robfig/cron"
)
func errorExit(str string, code int) {
fmt.Fprintln(os.Stderr, str)
os.Exit(code)
}
func main() {
osArgsLen := len(os.Args)
if osArgsLen < 2 {
errorExit("Please provide config as argument", 1)
}
configFilePath := os.Args[1]
cfg, err := config.GetConfigFromPath(configFilePath)
if err != nil {
panic(err)
}
if osArgsLen > 2 {
cfg.WMClient = os.Args[2]
}
// not implemented, havent really had the use for it
//go protocol.HandleInput()
if cfg.WMClient == "sway" {
i3.WMClient = i3.WMTypeSway
}
output := protocol.Output{}
err = output.Init(cfg)
if err != nil {
panic(err)
}
c := cron.New()
for _, module := range cfg.Modules {
var err error
switch module.Name {
case "datetime":
err = c.AddFunc(module.Cron, datetime.Datetime(&output, module))
case "pulseaudio":
err = pulseaudio.Pulseaudio(&output, module)
case "readfile":
err = c.AddFunc(module.Cron, readfile.Readfile(&output, module))
case "memory":
err = c.AddFunc(module.Cron, memory.Memory(&output, module))
case "cpu":
err = c.AddFunc(module.Cron, cpu.Cpu(&output, module))
case "command":
err = c.AddFunc(module.Cron, command.Command(&output, module))
case "activewindow":
activewindow.ActiveWindow(&output, module)
}
if err != nil {
fmt.Fprintf(os.Stderr, "\nError when initializing module: %s, \nerror: %s\n", module.Name, err.Error())
}
}
output.PrintMsgs()
c.Start()
runtime.Goexit()
}