-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (47 loc) · 1.09 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
package main
import (
"bytes"
"fmt"
"github.com/dirkarnez/wait2die"
"github.com/play175/wifiNotifier"
"log"
"os/exec"
)
var previousSSID = ""
func main() {
wifiNotify(func(ssid string) {
if ssid == "Default"{
Chrome()
}
})
wait2die.WaitToDie(nil)
}
type subscriber func(ssid string)
func wifiNotify(subscribers... subscriber) {
var dispatcher = func(ssid string) {
for _, s := range subscribers {
s(ssid)
}
}
wifiNotifier.SetWifiNotifier(func(ssid string) {
if previousSSID == ssid {
return
}
dispatcher(ssid)
log.Println("onWifiChanged, current ssid:" + ssid)
previousSSID = ssid
})
dispatcher(wifiNotifier.GetCurrentSSID())
}
func Chrome() {
cmd := exec.Command("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe","--chrome-frame", "--app=https://google.com")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
fmt.Printf("out:\n%s\nerr:\n%s\n", outStr, errStr)
}