1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
harveyshao 2022-04-10 11:43:17 +08:00
parent 40628e005a
commit 0ab3b73e38
2 changed files with 21 additions and 34 deletions

View File

@ -2,6 +2,7 @@ package web
import (
"net"
"strings"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/mdb"
@ -58,7 +59,9 @@ func _serve_udp(m *ice.Message, host, port string) {
}
func _broad_search(m *ice.Message, kind, name, text string, arg ...string) {
m.Richs(BROAD, nil, mdb.FOREACH, func(key string, value map[string]interface{}) {
value = kit.GetMeta(value)
if value = kit.GetMeta(value); !strings.Contains(kit.Format(value[tcp.HOST]), name) {
return
}
m.PushSearch(mdb.TYPE, "friend", mdb.TEXT, kit.Format("http://%s:%s", value[tcp.HOST], value[tcp.PORT]), value)
})
}

View File

@ -9,20 +9,15 @@ import (
type WebView struct {
Source string
Target interface{}
WebView webview.WebView
}
func (w WebView) Menu() bool {
kit.Reflect(w.Target, func(name string, value interface{}) { w.WebView.Bind(name, value) })
list := []string{}
ice.Pulse.Cmd(nfs.CAT, w.Source, func(ls []string, line string) {
if len(ls) > 1 {
list = append(list, kit.Format(`<button onclick=%s()>%s</button>`, ls[0], ls[0]))
w.WebView.Bind(ls[0], func() {
w.WebView.SetSize(1200, 800, webview.HintNone)
w.WebView.Navigate(ls[1])
})
w.WebView.Bind(ls[0], func() { w.navigate(ls[1]) })
}
})
@ -37,20 +32,18 @@ func (w WebView) Menu() bool {
<html>
<head>
<style>button { font-size:24px; font-family:monospace; margin:10px; width:-webkit-fill-available; display:block; clear:both; }</style>
<script>
window.alert("hello world")
document.body.onclick = function(event) {
if (event.metaKey) {
switch (event.key) {
case "w": close() break
case "q": terminate() break
}
}
}
</script>
</head>
<body>%s</body>
<script>
document.body.onkeydown = function(event) {
if (event.metaKey) {
switch (event.key) {
case "q": window.terminate(); break
}
}
}
</script>
</html>`, kit.Join(list, ice.NL)))
return true
}
@ -63,29 +56,20 @@ func (w WebView) Close() {
w.WebView.Terminate()
}
}
func (w WebView) navigate(url string) {
w.WebView.SetSize(1200, 800, webview.HintNone)
w.WebView.Navigate(url)
}
func Run(cb func(*WebView) interface{}) {
w := webview.New(true)
defer w.Destroy()
defer w.Run()
w.Init(`
window.alert("hello world")
document.body.onclick = function(event) {
if (event.metaKey) {
switch (event.key) {
case "w": close() break
case "q": terminate() break
}
}
}
`)
view := &WebView{Source: "src/webview.txt", WebView: w}
target := cb(view)
kit.Reflect(cb(view), func(name string, value interface{}) { w.WebView.Bind(name, value) })
if view.Target = target; !view.Menu() {
w.SetSize(1200, 800, webview.HintNone)
w.Navigate("http://localhost:9020")
if !view.Menu() {
view.navigate("http://localhost:9020")
}
}