1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Display current wifi network name

This commit is contained in:
Chris Cummer 2018-03-31 08:17:57 -07:00 committed by Chris Cummer
parent d82c7692be
commit 42ce7f4353
3 changed files with 72 additions and 3 deletions

58
security/client.go Normal file
View File

@ -0,0 +1,58 @@
package security
import (
"io/ioutil"
"os/exec"
"regexp"
//"runtime"
//"strings"
)
const fwGlobalState = "/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate"
const fwStealthMode = "/usr/libexec/ApplicationFirewall/socketfilterfw --getstealthmode"
// https://github.com/yelinaung/wifi-name/blob/master/wifi-name.go
const osxCmd = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
const osxArgs = "-I"
func Fetch() map[string]string {
data := make(map[string]string)
data["Wifi"] = WifiName()
return data
}
func WifiName() string {
cmd := exec.Command(osxCmd, osxArgs)
stdout, err := cmd.StdoutPipe()
panicIf(err)
// start the command after having set up the pipe
if err := cmd.Start(); err != nil {
panic(err)
}
var str string
if b, err := ioutil.ReadAll(stdout); err == nil {
str += (string(b) + "\n")
}
r := regexp.MustCompile(`s*SSID: (.+)s*`)
name := r.FindAllStringSubmatch(str, -1)
if len(name) <= 1 {
return ""
} else {
return name[1][1]
}
}
func panicIf(err error) {
if err != nil {
panic(err)
}
}

View File

@ -31,15 +31,14 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
//data := Fetch()
data := Fetch()
widget.View.SetTitle(" 🐼 Security")
widget.RefreshedAt = time.Now()
widget.View.Clear()
fmt.Fprintf(widget.View, "%s", "cats and dogs")
//fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
}
/* -------------------- Unexported Functions -------------------- */
@ -54,6 +53,16 @@ func (widget *Widget) addView() {
widget.View = view
}
func (widget *Widget) contentFrom(data map[string]string) string {
str := "\n"
for key, val := range data {
str = str + fmt.Sprintf("%8s: %8s\n", key, val)
}
return str
}
func (widget *Widget) refresher() {
tick := time.NewTicker(time.Duration(widget.RefreshInterval) * time.Second)
quit := make(chan struct{})

View File

@ -87,6 +87,8 @@ func icon(data *owm.CurrentWeatherData) string {
icon = "☁️"
case "clear":
icon = "☀️"
case "clear sky":
icon = "☀️"
case "cloudy":
icon = "⛅️"
case "few clouds":