save peers RIVM-31

This commit is contained in:
Mihail Slobodyanuk 2022-12-16 22:58:12 +02:00
parent d68d3db702
commit 0b54277ece
7 changed files with 164 additions and 165 deletions

File diff suppressed because one or more lines are too long

View file

@ -68,8 +68,13 @@ img {
display: block;
}
html, body {
height: 100vh;
html, body {
height: 100vh;
}
body {
max-width: 690px;
margin: auto;
}
td.fi {

View file

@ -4,6 +4,7 @@ var $$ = clazz => document.getElementsByClassName(clazz)
function setPingValue(peer, value) {
var cellText;
var peerCell = $(peer);
if (!peerCell) return;
var peerTable = $("peer_list");
if (value === "-1") {
var peerAddress = $("label_" + peer);
@ -148,7 +149,7 @@ function showWindow(text) {
'Content-Type': 'application/json',
'Riv-Save-Config': 'true',
},
body: JSON.stringify({"peers": peer_list}),
body: JSON.stringify(peer_list),
})
.catch((error) => {
console.error('Error:', error);
@ -315,6 +316,7 @@ ui.updateSelfInfo = () =>
ui.getSelfInfo()
.then((info) => {
$("ipv6").innerText = info.address;
$("subnet").innerText = info.subnet;
$("pub_key").innerText = info.key;
$("priv_key").innerText = info.private_key;
$("ipv6").innerText = info.address;

View file

@ -1,14 +1,11 @@
package main
import (
"bytes"
"log"
"os"
"github.com/RiV-chain/RiV-mesh/src/defaults"
"github.com/hjson/hjson-go"
"github.com/webview/webview"
"golang.org/x/text/encoding/unicode"
"github.com/docopt/docopt-go"
)
@ -46,35 +43,10 @@ func main() {
w.SetSize(690, 920, webview.HintFixed)
if confui.IndexHtml == "" {
confui.IndexHtml = getEndpoint()
}
if confui.IndexHtml == "" {
confui.IndexHtml = "http://localhost:19019"
confui.IndexHtml = defaults.GetHttpEndpoint("http://localhost:19019")
}
log.Printf("Opening: %v", confui.IndexHtml)
w.Navigate(confui.IndexHtml)
w.Run()
}
func getEndpoint() string {
if config, err := os.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil {
if bytes.Equal(config[0:2], []byte{0xFF, 0xFE}) ||
bytes.Equal(config[0:2], []byte{0xFE, 0xFF}) {
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
decoder := utf.NewDecoder()
config, err = decoder.Bytes(config)
if err != nil {
return ""
}
}
var dat map[string]interface{}
if err := hjson.Unmarshal(config, &dat); err != nil {
return ""
}
if ep, ok := dat["HttpAddress"].(string); ok && (ep != "none" && ep != "") {
return ep
}
}
return ""
}