From 0ab3b73e389fb424ea8c65caa09ec837f3267677 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Sun, 10 Apr 2022 11:43:17 +0800 Subject: [PATCH] opt some --- base/web/broad.go | 5 ++++- misc/webview/webview.go | 50 ++++++++++++++--------------------------- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/base/web/broad.go b/base/web/broad.go index b5479df5..c726a4b1 100644 --- a/base/web/broad.go +++ b/base/web/broad.go @@ -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) }) } diff --git a/misc/webview/webview.go b/misc/webview/webview.go index 84415090..45aafcca 100644 --- a/misc/webview/webview.go +++ b/misc/webview/webview.go @@ -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(``, 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 { - %s + `, 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") } }