-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.go
48 lines (38 loc) · 978 Bytes
/
functions.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
package nordvpn
import (
"fmt"
"github.com/kamushadenes/swayit/common"
"github.com/kamushadenes/swayit/config"
"os/exec"
"strings"
)
func run(w *common.WaybarOutput) error {
cmd := exec.Command(config.SwayItConfig.NordVPN.Command, "status")
output, err := cmd.Output()
if err != nil {
return err
}
nvpnStatus := strings.Replace(string(output), "\r", "", -1)
nvpnStatus = strings.TrimPrefix(nvpnStatus, "-")
nvpnStatus = strings.TrimSuffix(nvpnStatus, "-")
nvpnStatus = strings.TrimSpace(nvpnStatus)
var status string
var city string
statusSlice := statusRegex.FindStringSubmatch(nvpnStatus)
citySlice := cityRegex.FindStringSubmatch(nvpnStatus)
if len(status) == 1 {
status = statusSlice[0]
}
if len(city) == 1 {
city = citySlice[0]
}
if status == "Connected" {
w.Text = fmt.Sprintf("\uf023 %s", city)
w.Class = "connected"
} else {
w.Class = "disconnected"
w.Text = "\uf09c Disconnected"
w.Tooltip = nvpnStatus
}
return nil
}