mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 22:55:06 +03:00
added webview
This commit is contained in:
parent
c566f4a981
commit
75b2a7421f
6 changed files with 316 additions and 0 deletions
BIN
contrib/ui/webview/dll/x64/WebView2Loader.dll
Executable file
BIN
contrib/ui/webview/dll/x64/WebView2Loader.dll
Executable file
Binary file not shown.
BIN
contrib/ui/webview/dll/x64/webview.dll
Executable file
BIN
contrib/ui/webview/dll/x64/webview.dll
Executable file
Binary file not shown.
BIN
contrib/ui/webview/dll/x86/WebView2Loader.dll
Executable file
BIN
contrib/ui/webview/dll/x86/WebView2Loader.dll
Executable file
Binary file not shown.
BIN
contrib/ui/webview/dll/x86/webview.dll
Executable file
BIN
contrib/ui/webview/dll/x86/webview.dll
Executable file
Binary file not shown.
229
contrib/ui/webview/index.html
Executable file
229
contrib/ui/webview/index.html
Executable file
|
@ -0,0 +1,229 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html class="is-clipped">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
|
<title>Yggdrasil</title>
|
||||||
|
<link rel="stylesheet" href="https://maxst.icons8.com/vue-static/landings/line-awesome/font-awesome-line-awesome/css/all.min.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/slate/bulmaswatch.min.css" type="text/css">
|
||||||
|
<script>
|
||||||
|
|
||||||
|
function setFieldValue(id, value){
|
||||||
|
var field = document.getElementById(id);
|
||||||
|
field.innerHTML = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openTab(element, tabName) {
|
||||||
|
// Declare all variables
|
||||||
|
var i, tabContent, tabLinks;
|
||||||
|
|
||||||
|
// Get all elements with class="content" and hide them
|
||||||
|
tabContent = document.getElementsByClassName("tab here");
|
||||||
|
for (i = 0; i < tabContent.length; i++) {
|
||||||
|
tabContent[i].className = "tab here is-hidden";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all elements with class="tab" and remove the class "is-active"
|
||||||
|
tabLinks = document.getElementsByClassName("tab is-active");
|
||||||
|
for (i = 0; i < tabLinks.length; i++) {
|
||||||
|
tabLinks[i].className = "tab";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the current tab, and add an "is-active" class to the button that opened the tab
|
||||||
|
document.getElementById(tabName).className = "tab here";
|
||||||
|
element.parentElement.className = "tab is-active";
|
||||||
|
refreshRecordsList();
|
||||||
|
}
|
||||||
|
|
||||||
|
function copy2clipboard(text){
|
||||||
|
var textArea = document.createElement("textarea");
|
||||||
|
textArea.style.position = 'fixed';
|
||||||
|
textArea.style.top = 0;
|
||||||
|
textArea.style.left = 0;
|
||||||
|
|
||||||
|
// Ensure it has a small width and height. Setting to 1px / 1em
|
||||||
|
// doesn't work as this gives a negative w/h on some browsers.
|
||||||
|
textArea.style.width = '2em';
|
||||||
|
textArea.style.height = '2em';
|
||||||
|
|
||||||
|
// We don't need padding, reducing the size if it does flash render.
|
||||||
|
textArea.style.padding = 0;
|
||||||
|
|
||||||
|
// Clean up any borders.
|
||||||
|
textArea.style.border = 'none';
|
||||||
|
textArea.style.outline = 'none';
|
||||||
|
textArea.style.boxShadow = 'none';
|
||||||
|
|
||||||
|
// Avoid flash of the white box if rendered for any reason.
|
||||||
|
textArea.style.background = 'transparent';
|
||||||
|
textArea.value = text;
|
||||||
|
|
||||||
|
document.body.appendChild(textArea);
|
||||||
|
textArea.focus();
|
||||||
|
textArea.select();
|
||||||
|
try {
|
||||||
|
var successful = document.execCommand('copy');
|
||||||
|
var msg = successful ? 'successful' : 'unsuccessful';
|
||||||
|
console.log('Copying text command was ' + msg);
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Oops, unable to copy');
|
||||||
|
}
|
||||||
|
document.body.removeChild(textArea);
|
||||||
|
showInfo('value copied successfully!');
|
||||||
|
}
|
||||||
|
|
||||||
|
function showInfo(text) {
|
||||||
|
var info = document.getElementById("notification_info");
|
||||||
|
var message = document.getElementById("info_text");
|
||||||
|
message.innerHTML = text;
|
||||||
|
|
||||||
|
info.className = "notification is-primary";
|
||||||
|
var button = document.getElementById("info_close");
|
||||||
|
button.onclick = function() {
|
||||||
|
message.value = "";
|
||||||
|
info.className = "notification is-primary is-hidden";
|
||||||
|
};
|
||||||
|
setTimeout(button.onclick, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
|
||||||
|
.container-ip {
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
border: 1px solid #5d656d;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin:10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.push-right {
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item {
|
||||||
|
padding: 10px;
|
||||||
|
/*border: 1px solid #5d656d;*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.column {
|
||||||
|
max-height: 350px;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.over {
|
||||||
|
max-height: 150px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body onload="onLoad();">
|
||||||
|
<div style="padding:3px; max-height: 250px;">
|
||||||
|
|
||||||
|
<!-- Tabs -->
|
||||||
|
<div class="tabs is-centered is-boxed">
|
||||||
|
<ul>
|
||||||
|
<li class="tab is-active">
|
||||||
|
<a onclick="openTab(this, 'my_node');">
|
||||||
|
<span class="icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 42 42"><path d="M18.5 35.5l-8 2c-.48.04-1 .52-1 1v1c0 .5.47 1 1 1h20c.43 0 1-.41 1-1v-1c-.02-.52-.55-.98-1-1l-8-2h-4zm19-1c2.59 0 3-.529 3-3v-26c0-2.391-.55-3-3-3h-34c-2.43 0-3 .54-3 3v26c0 2.51.529 3 3 3h34zm-2-27v22h-30v-22h30z" fill="white"/></svg>
|
||||||
|
</span>
|
||||||
|
<span>My Node</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="tab">
|
||||||
|
<a onclick="openTab(this, 'keys');">
|
||||||
|
<span class="icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><g fill="none" stroke="white" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M5 15v15h22V15zm4 0C9 9 9 5 16 5s7 4 7 10m-7 5v3"/><circle cx="16" cy="24" r="1"/></g></svg>
|
||||||
|
</span>
|
||||||
|
<span>Keys</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="tab">
|
||||||
|
<a onclick="openTab(this, 'about');">
|
||||||
|
<span class="icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 48 48"><path fill="#2196F3" d="M37 40H11l-6 6V12c0-3.3 2.7-6 6-6h26c3.3 0 6 2.7 6 6v22c0 3.3-2.7 6-6 6z"/><g fill="#fff"><path d="M22 20h4v11h-4z"/><circle cx="24" cy="15" r="2"/></g></svg>
|
||||||
|
</span>
|
||||||
|
<span>About</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="tab here " id="my_node">
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<div class="container-ip">
|
||||||
|
<div class="item">IPv6</div>
|
||||||
|
<div id="ipv6" class="item push-right">N/A</div>
|
||||||
|
<div class="item">
|
||||||
|
<a class="fas fa-copy" onclick="copy2clipboard(document.getElementById('ipv6').innerHTML);"/></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container-ip">
|
||||||
|
<div class="item">Subnet</div>
|
||||||
|
<div id="subnet" class="item push-right">N/A</div>
|
||||||
|
<div class="item">
|
||||||
|
<a class="fas fa-copy" onclick="copy2clipboard(document.getElementById('subnet').innerHTML);"></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container-ip">
|
||||||
|
|
||||||
|
<div class="item">Peers</div>
|
||||||
|
<div class="item over">
|
||||||
|
23123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
123123123123
|
||||||
|
</div>
|
||||||
|
<div class="item push-right">
|
||||||
|
<a class="fas fa-edit"></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab here is-hidden" id="keys">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div style="margin-left: 100px; margin-right: 100px;">
|
||||||
|
<div class="notification is-primary is-hidden" id="notification_info">
|
||||||
|
<button class="delete" id="info_close"></button>
|
||||||
|
<p id="info_text"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--div style="width: 100%; padding: 20px; box-sizing: border-box;">
|
||||||
|
<div class="buttons">
|
||||||
|
<a class="button">Save</a>
|
||||||
|
</div>
|
||||||
|
</div-->
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
87
contrib/ui/webview/main.go
Executable file
87
contrib/ui/webview/main.go
Executable file
|
@ -0,0 +1,87 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/webview/webview"
|
||||||
|
"path/filepath"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"os/exec"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
debug := true
|
||||||
|
w := webview.New(debug)
|
||||||
|
defer w.Destroy()
|
||||||
|
w.SetTitle("RiV-mesh")
|
||||||
|
w.SetSize(450, 410, webview.HintNone)
|
||||||
|
path, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Println(path)
|
||||||
|
w.Bind("onLoad", func() {
|
||||||
|
log.Println("page loaded")
|
||||||
|
go run(w)
|
||||||
|
})
|
||||||
|
dat, err := ioutil.ReadFile(path+"/index.html")
|
||||||
|
w.Navigate("data:text/html,"+url.QueryEscape(string(dat)))
|
||||||
|
w.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(w webview.WebView){
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
program_path := "programfiles"
|
||||||
|
path, exists := os.LookupEnv(program_path)
|
||||||
|
if exists {
|
||||||
|
fmt.Println("Program path: %s", path)
|
||||||
|
riv_ctrl_path := fmt.Sprintf("%s\\RiV-mesh\\meshctl.exe", path)
|
||||||
|
run_command(w, riv_ctrl_path, "getSelf")
|
||||||
|
} else {
|
||||||
|
fmt.Println("could not find Program Files path")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
riv_ctrl_path := fmt.Sprintf("meshctl")
|
||||||
|
run_command(w, riv_ctrl_path, "getSelf")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func run_command(w webview.WebView, riv_ctrl_path string, command string){
|
||||||
|
|
||||||
|
cmd := exec.Command(riv_ctrl_path, command)
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cmd.Run() failed with %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lines := strings.Split(string(out), "\n")
|
||||||
|
m := make(map[string]string)
|
||||||
|
for i, 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 {
|
||||||
|
//found ipv6
|
||||||
|
fmt.Printf("IPv6: %s\n", val)
|
||||||
|
go setFieldValue(w, "ipv6", val)
|
||||||
|
}
|
||||||
|
if val, ok := m["IPv6 subnet"]; ok {
|
||||||
|
//found subnet
|
||||||
|
fmt.Printf("Subnet: %s\n", val)
|
||||||
|
go setFieldValue(w, "subnet", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func setFieldValue(p webview.WebView, id string, value string) {
|
||||||
|
p.Dispatch(func() {
|
||||||
|
p.Eval("setFieldValue('"+id+"','"+value+"');")
|
||||||
|
})
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue