-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
62 lines (56 loc) · 1.19 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
package main
import (
"fmt"
"time"
"github.com/lack/waybar-nmvpn/pkg/nmvpn"
waybar "github.com/lack/gowaybarplug"
)
func loop(interval time.Duration) {
wb := waybar.NewUpdater()
for true {
status := waybar.Status{
Text: "VPN",
}
vpns, err := nmvpn.GetVPNs()
if err == nil && len(vpns) > 0 {
active := false
for _, v := range vpns {
if v.Active {
active = true
break
}
}
if active {
status.Alt = "connected"
status.Class = []string{"connected"}
} else {
status.Alt = "disconnected"
status.Class = []string{"disconnected"}
}
status.Tooltip = ""
for _, v := range vpns {
if status.Tooltip != "" {
status.Tooltip += "\n"
}
state := "down"
if v.Active {
state = "up"
}
status.Tooltip += fmt.Sprintf("%s: %s", v.Name, state)
}
} else if err != nil {
status.Alt = "error"
status.Class = []string{"error"}
status.Tooltip = fmt.Sprintf("Error fetching VPN information: %v", err)
} else {
status.Alt = "none"
status.Class = []string{"unconfigured"}
status.Tooltip = "No VPN connections configured"
}
wb.Status <- &status
time.Sleep(interval)
}
}
func main() {
loop(5 * time.Second)
}