1. updated peers

This commit is contained in:
vadym 2021-09-12 00:19:58 +03:00
parent aff2a69b71
commit 09193f11d2
2 changed files with 37 additions and 8 deletions

View file

@ -181,7 +181,7 @@
<div class="container-ip">
<div class="item">Peers</div>
<div class="item over">
<div id="peers" class="item over">
23123123123
123123123123
123123123123

View file

@ -40,13 +40,15 @@ func run(w webview.WebView){
if exists {
fmt.Println("Program path: %s", path)
riv_ctrl_path := fmt.Sprintf("%s\\RiV-mesh\\meshctl.exe", path)
get_self(w, riv_ctrl_path, "getSelf")
get_self(w, riv_ctrl_path)
get_peers(w, riv_ctrl_path)
} else {
fmt.Println("could not find Program Files path")
}
} else {
riv_ctrl_path := fmt.Sprintf("meshctl")
get_self(w, riv_ctrl_path, "getSelf")
get_self(w, riv_ctrl_path)
get_peers(w, riv_ctrl_path)
}
}
@ -61,15 +63,14 @@ func run_command(riv_ctrl_path string, command string) []string{
return lines
}
func get_self(w webview.WebView, riv_ctrl_path string, command string){
func get_self(w webview.WebView, riv_ctrl_path string){
lines := run_command(riv_ctrl_path, command)
lines := run_command(riv_ctrl_path, "getSelf")
m := make(map[string]string)
for i, s := range lines {
for _, s := range lines {
p := strings.SplitN(s, ":", 2)
if len(p)>1 {
m[p[0]]=strings.TrimSpace(p[1])
fmt.Println(i)
}
}
if val, ok := m["IPv6 address"]; ok {
@ -82,7 +83,35 @@ func get_self(w webview.WebView, riv_ctrl_path string, command string){
fmt.Printf("Subnet: %s\n", val)
go setFieldValue(w, "subnet", val)
}
}
func get_peers(w webview.WebView, riv_ctrl_path string){
lines := run_command(riv_ctrl_path, "getPeers")
lines = lines[1:] /*remove first element which is a header*/
var m []string
r:=""
for _, s := range lines {
p := strings.SplitN(s, " ", -1)
if len(p)>1 {
for _, t := range p {
if len(strings.TrimSpace(t))>0 {
r=strings.TrimSpace(t)
}
}
index_p := strings.Index(r, "%")
index_b := strings.Index(r, "]")
if index_p>0 && index_b>0 {
r = r[:index_p]+r[index_b:]
}
m=append(m, r)
}
}
for k := range m { // Loop
fmt.Println(k)
}
inner_html := strings.Join(m[:], "<br>")
go setFieldValue(w, "peers", inner_html)
}
func setFieldValue(p webview.WebView, id string, value string) {