mirror of
https://shylinux.com/x/icebergs
synced 2025-04-28 10:12:02 +08:00
opt some
This commit is contained in:
parent
40628e005a
commit
0ab3b73e38
@ -2,6 +2,7 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"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) {
|
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{}) {
|
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)
|
m.PushSearch(mdb.TYPE, "friend", mdb.TEXT, kit.Format("http://%s:%s", value[tcp.HOST], value[tcp.PORT]), value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -9,20 +9,15 @@ import (
|
|||||||
|
|
||||||
type WebView struct {
|
type WebView struct {
|
||||||
Source string
|
Source string
|
||||||
Target interface{}
|
|
||||||
WebView webview.WebView
|
WebView webview.WebView
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w WebView) Menu() bool {
|
func (w WebView) Menu() bool {
|
||||||
kit.Reflect(w.Target, func(name string, value interface{}) { w.WebView.Bind(name, value) })
|
|
||||||
list := []string{}
|
list := []string{}
|
||||||
ice.Pulse.Cmd(nfs.CAT, w.Source, func(ls []string, line string) {
|
ice.Pulse.Cmd(nfs.CAT, w.Source, func(ls []string, line string) {
|
||||||
if len(ls) > 1 {
|
if len(ls) > 1 {
|
||||||
list = append(list, kit.Format(`<button onclick=%s()>%s</button>`, ls[0], ls[0]))
|
list = append(list, kit.Format(`<button onclick=%s()>%s</button>`, ls[0], ls[0]))
|
||||||
w.WebView.Bind(ls[0], func() {
|
w.WebView.Bind(ls[0], func() { w.navigate(ls[1]) })
|
||||||
w.WebView.SetSize(1200, 800, webview.HintNone)
|
|
||||||
w.WebView.Navigate(ls[1])
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -37,20 +32,18 @@ func (w WebView) Menu() bool {
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<style>button { font-size:24px; font-family:monospace; margin:10px; width:-webkit-fill-available; display:block; clear:both; }</style>
|
<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>
|
</head>
|
||||||
|
|
||||||
<body>%s</body>
|
<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)))
|
</html>`, kit.Join(list, ice.NL)))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -63,29 +56,20 @@ func (w WebView) Close() {
|
|||||||
w.WebView.Terminate()
|
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{}) {
|
func Run(cb func(*WebView) interface{}) {
|
||||||
w := webview.New(true)
|
w := webview.New(true)
|
||||||
defer w.Destroy()
|
defer w.Destroy()
|
||||||
defer w.Run()
|
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}
|
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() {
|
if !view.Menu() {
|
||||||
w.SetSize(1200, 800, webview.HintNone)
|
view.navigate("http://localhost:9020")
|
||||||
w.Navigate("http://localhost:9020")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user