forked from x/icebergs
add mp
This commit is contained in:
parent
593c5a3313
commit
4679d5475a
@ -4,6 +4,7 @@ import (
|
||||
"encoding/base64"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
@ -47,7 +48,7 @@ const QRCODE = "qrcode"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
QRCODE: {Name: "qrcode text fg@key bg@key size auto", Help: "二维码", Actions: ice.Actions{
|
||||
QRCODE: {Name: "qrcode text fg@key bg@key size auto", Help: "二维码", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.AddRender(ice.RENDER_QRCODE, func(m *ice.Message, args ...ice.Any) string {
|
||||
return m.Cmd(Prefix(QRCODE), kit.Simple(args...)).Result()
|
||||
@ -59,7 +60,7 @@ func init() {
|
||||
m.Push(arg[0], BLACK, WHITE)
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
}, aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.IsCliUA() {
|
||||
m.OptionDefault(FG, BLACK, BG, WHITE)
|
||||
_qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0))
|
||||
|
@ -9,6 +9,6 @@ const TCP = "tcp"
|
||||
|
||||
var Index = &ice.Context{Name: TCP, Help: "通信模块"}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, HOST, PORT, CLIENT, SERVER) }
|
||||
func init() { ice.Index.Register(Index, nil, WIFI, HOST, PORT, CLIENT, SERVER) }
|
||||
|
||||
func Prefix(arg ...ice.Any) string { return kit.Keys(TCP, kit.Keys(arg...)) }
|
||||
|
@ -10,6 +10,9 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
SSID = "ssid"
|
||||
)
|
||||
const WIFI = "wifi"
|
||||
|
||||
func init() {
|
||||
@ -22,17 +25,17 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
WIFI: {Help: "无线", Actions: ice.MergeActions(ice.Actions{
|
||||
DISCOVER: {Help: "查找", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Push(mdb.NAME, strings.Split(m.Cmdx(SYSTEM, NETWORKSETUP, "-listpreferredwirelessnetworks", "en0"), lex.NL)[1:])
|
||||
m.Push(SSID, strings.Split(m.Cmdx(SYSTEM, NETWORKSETUP, "-listpreferredwirelessnetworks", "en0"), lex.NL)[1:])
|
||||
m.PushAction(CONNECT)
|
||||
}},
|
||||
CONNECT: {Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := mdb.HashSelect(m.Spawn(), m.Option(mdb.NAME, strings.TrimSpace(m.Option(mdb.NAME))))
|
||||
m.Cmd(SYSTEM, NETWORKSETUP, "-setairportnetwork", "en0", kit.Select(m.Option(mdb.NAME), msg.Append(mdb.NAME)), msg.Append(aaa.PASSWORD))
|
||||
msg := mdb.HashSelect(m.Spawn(), m.Option(SSID, strings.TrimSpace(m.Option(SSID))))
|
||||
m.Cmd(SYSTEM, NETWORKSETUP, "-setairportnetwork", "en0", kit.Select(m.Option(SSID), msg.Append(SSID)), msg.Append(aaa.PASSWORD))
|
||||
m.ProcessHold()
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,password")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.SHORT, SSID, mdb.FIELD, "time,ssid,password")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...).PushAction(CONNECT, mdb.REMOVE).Action(mdb.CREATE, DISCOVER); len(arg) > 0 {
|
||||
m.EchoQRCode(kit.Format("WIFI:T:WPA;S:%s;P:%s;H:false;;", m.Append(mdb.NAME), m.Append(aaa.PASSWORD)))
|
||||
m.EchoQRCode(kit.Format("WIFI:T:WPA;S:%s;P:%s;H:false;;", m.Append(SSID), m.Append(aaa.PASSWORD)))
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
@ -102,7 +102,7 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
|
||||
}
|
||||
return m
|
||||
}
|
||||
_log("page", Referer, r.Header.Get(Referer))
|
||||
kit.If(r.Header.Get(Referer), func(p string) { _log("page", Referer, p) })
|
||||
if u, e := url.Parse(r.Header.Get(Referer)); e == nil {
|
||||
add := func(k, v string) { _log(nfs.PATH, k, m.Option(k, v)) }
|
||||
switch arg := strings.Split(strings.TrimPrefix(u.Path, nfs.PS), nfs.PS); arg[0] {
|
||||
@ -165,6 +165,9 @@ func _serve_domain(m *ice.Message) string {
|
||||
)
|
||||
}
|
||||
func _serve_auth(m *ice.Message, key string, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) {
|
||||
if len(cmds) > 0 {
|
||||
cmds = append(kit.Split(cmds[0], ","), cmds[1:]...)
|
||||
}
|
||||
if r.URL.Path == PP(SPACE) {
|
||||
return cmds, true
|
||||
}
|
||||
|
@ -16,8 +16,10 @@ func _js_show(m *ice.Message, arg ...string) {
|
||||
if arg[1] == MAIN_JS {
|
||||
ctx.ProcessField(m, web.CHAT_IFRAME, kit.Simple(web.UserHost(m)))
|
||||
} else if arg[2] == ice.USR_VOLCANOS {
|
||||
if strings.HasPrefix(arg[1], "plugin/local/") {
|
||||
ctx.ProcessField(m, kit.Select(ice.CAN_PLUGIN, "web."+strings.Replace(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), nfs.PT+JS), nfs.PS, nfs.PT, -1)), kit.Simple())
|
||||
if strings.HasPrefix(arg[1], "publish/client/mp/") {
|
||||
ctx.ProcessField(m, "web.chat.wx.ide", nil)
|
||||
} else if strings.HasPrefix(arg[1], "plugin/local/") {
|
||||
ctx.ProcessField(m, kit.Select(ice.CAN_PLUGIN, "web."+strings.Replace(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), nfs.PT+JS), nfs.PS, nfs.PT, -1)), nil)
|
||||
}
|
||||
} else {
|
||||
ctx.DisplayBase(m, require(arg[2], arg[1]))
|
||||
|
@ -167,6 +167,9 @@ func init() {
|
||||
if m.Option(nfs.PATH) != "" && nfs.ExistsFile(m, path.Join(m.Option(nfs.PATH), ice.MAKEFILE)) {
|
||||
web.PushStream(m).Cmdy(cli.SYSTEM, cli.MAKE, kit.Dict(cli.CMD_DIR, m.Option(nfs.PATH)))
|
||||
return
|
||||
} else if m.Option(nfs.PATH) == ice.USR_VOLCANOS && strings.HasPrefix(m.Option(nfs.FILE), "publish/client/mp/") {
|
||||
web.PushStream(m).Cmdy(cli.SYSTEM, cli.MAKE, kit.Dict(cli.CMD_DIR, path.Join(m.Option(nfs.PATH), "publish/client/mp/")))
|
||||
return
|
||||
}
|
||||
const app, _app = "usr/publish/Contexts.app", "Contents/MacOS/Contexts"
|
||||
isWebview := func() bool { return strings.HasSuffix(os.Args[0], _app) }
|
||||
|
@ -13,12 +13,15 @@ import (
|
||||
"shylinux.com/x/icebergs/base/log"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _ide_args(m *ice.Message) []string {
|
||||
return append(kit.Split(m.Option(ctx.ARGS), "=&"), kit.Simple(kit.Dict(m.OptionSimple(web.SPACE, ctx.INDEX, log.DEBUG)))...)
|
||||
func _ide_args(m *ice.Message) (args []string) {
|
||||
args = append(kit.Split(m.Option(ctx.ARGS), "=&"), kit.Simple(kit.Dict(m.OptionSimple(web.SPACE, ctx.INDEX, log.DEBUG)))...)
|
||||
kit.If(m.Option(tcp.WIFI), func(p string) { args = append(args, m.Cmd(tcp.WIFI, p).AppendSimple(tcp.SSID, aaa.PASSWORD)...) })
|
||||
return
|
||||
}
|
||||
func _ide_args_cli(m *ice.Message) []string {
|
||||
return []string{"--project", kit.Path(mdb.Config(m, PROJECT)), "--compile-condition", kit.Format(kit.Dict(
|
||||
@ -49,20 +52,34 @@ func init() {
|
||||
m.Go(func() { web.PushNoticeGrow(m.Sleep("1s"), ice.Render(m, ice.RENDER_IMAGES, web.SHARE_LOCAL+p)) })
|
||||
IdeCli(m, "", _ide_args_cli(m), _ide_args_qrcode(m, p)).ProcessRefresh()
|
||||
}},
|
||||
AUTO_PREVIEW: {Help: "自动", Hand: func(m *ice.Message, arg ...string) { IdeCli(m, "", _ide_args_cli(m)).ProcessInner() }},
|
||||
PREVIEW: {Help: "预览", Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.MAKE: {Help: "调试", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(mdb.HASH), func(p string) { mdb.Config(m, cli.MAKE, p) })
|
||||
msg := m.Cmd("", kit.Select(mdb.Config(m, cli.MAKE), arg, 0))
|
||||
m.Options(msg.AppendSimple()).Cmd("", AUTO_PREVIEW)
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch mdb.HashInputs(m, arg); arg[0] {
|
||||
case nfs.PATH:
|
||||
m.Push(arg[0], kit.Value(kit.UnMarshal(m.Cmdx(nfs.CAT, path.Join(mdb.Config(m, PROJECT), "app.json"))), "pages"))
|
||||
case tcp.WIFI:
|
||||
m.Cmdy(tcp.WIFI).Cut(tcp.SSID)
|
||||
}
|
||||
}},
|
||||
AUTO_PREVIEW: {Help: "预览", Hand: func(m *ice.Message, arg ...string) { IdeCli(m, "", _ide_args_cli(m)).ProcessInner() }},
|
||||
PREVIEW: {Help: "体验", Hand: func(m *ice.Message, arg ...string) {
|
||||
p := nfs.TempName(m)
|
||||
IdeCli(m, "", _ide_args_cli(m), _ide_args_qrcode(m, p))
|
||||
m.EchoImages(web.SHARE_LOCAL + p).ProcessInner()
|
||||
}},
|
||||
}, mdb.ExportHashAction(mdb.FIELD, "time,hash,name,path,space,index,args", cli.DARWIN, "/Applications/wechatwebdevtools.app/Contents/MacOS/cli", PROJECT, "usr/volcanos/publish/client/mp/")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.ExportHashAction(mdb.FIELD, "time,hash,name,path,space,index,args,wifi", cli.DARWIN, "/Applications/wechatwebdevtools.app/Contents/MacOS/cli", PROJECT, "usr/volcanos/publish/client/mp/")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.Value(kit.UnMarshal(IdeCli(m.Spawn(), "islogin").Append(cli.CMD_OUT)), aaa.LOGIN) != true {
|
||||
m.EchoInfoButton("请登录: ", aaa.LOGIN)
|
||||
} else if mdb.HashSelect(m, arg...).PushAction(AUTO_PREVIEW, PREVIEW, mdb.REMOVE).Action(mdb.CREATE, ice.APP); len(arg) > 0 {
|
||||
m.Options(m.AppendSimple(web.SPACE, ctx.INDEX, ctx.ARGS))
|
||||
} else if mdb.HashSelect(m, arg...).PushAction(AUTO_PREVIEW, PREVIEW, cli.MAKE, mdb.REMOVE).Action(mdb.CREATE, ice.APP); len(arg) > 0 {
|
||||
m.Options(m.AppendSimple(web.SPACE, ctx.INDEX, ctx.ARGS, tcp.WIFI))
|
||||
p := kit.MergeURL2(web.UserHost(m), path.Join(nfs.PS+m.Append(nfs.PATH)), _ide_args(m))
|
||||
m.EchoQRCode(p).Echo(lex.NL).EchoAnchor(p)
|
||||
}
|
||||
m.StatusTimeCount(kit.Dict(mdb.ConfigSimple(m, cli.MAKE)))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user