1
0
mirror of https://shylinux.com/x/icebergs synced 2025-07-01 04:14:42 +08:00
icebergs/core/chat/macos/macos.go
2025-06-30 19:36:00 +08:00

105 lines
3.6 KiB
Go

package macos
import (
"path"
"strings"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/base/web/html"
"shylinux.com/x/icebergs/core/chat"
kit "shylinux.com/x/toolkits"
)
const MACOS = "macos"
var Index = &ice.Context{Name: MACOS, Commands: ice.Commands{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { ice.Info.Load(m).Cmd(FINDER, ice.CTX_INIT) }},
}}
func init() { chat.Index.Register(Index, nil, DESKTOP, APPLICATIONS) }
func Prefix(arg ...string) string { return chat.Prefix(MACOS, kit.Keys(arg)) }
func disableApp(m *ice.Message) *ice.Message {
m.Table(func(value ice.Maps) {
switch index := ctx.ShortCmd(value[ctx.INDEX]); index {
case web.DREAM, web.CODE_GIT_SEARCH:
if ice.Info.NodeType == web.WORKER {
m.Push(mdb.STATUS, mdb.DISABLE)
return
}
case web.COMPILE:
if cli.SystemFind(m, "go") == "" {
m.Push(mdb.STATUS, mdb.DISABLE)
return
}
fallthrough
case web.XTERM:
if !kit.IsIn(m.Option(ice.MSG_USERROLE), aaa.TECH, aaa.ROOT) {
m.Push(mdb.STATUS, mdb.DISABLE)
return
}
default:
m.Push(mdb.STATUS, kit.Select(mdb.DISABLE, mdb.ENABLE, aaa.Right(m.Spawn(), index)))
return
}
m.Push(mdb.STATUS, mdb.ENABLE)
})
return m
}
func install(m *ice.Message, cmd, icon, index string, arg ...string) string {
if icon == "" {
return ""
} else if !kit.HasPrefix(icon, nfs.PS, web.HTTP) && !nfs.Exists(m, icon) && !nfs.Exists(m, ice.USR_ICONS+icon, func(p string) { icon = p }) {
if strings.Contains(kit.Path(""), nfs.USR_LOCAL_WORK) && nfs.Exists(m, path.Join(strings.Split(kit.Path(""), nfs.USR_LOCAL_WORK)[0], ice.USR_ICONS+icon)) {
icon = ice.USR_ICONS + icon
} else {
icon = path.Join(path.Dir(ctx.GetCmdFile(m, m.PrefixKey())), icon)
}
}
name := kit.TrimExt(path.Base(icon), nfs.PNG, nfs.JPG, nfs.JPEG)
if !strings.HasPrefix(icon, nfs.USR_ICONS) {
name = kit.Select("", kit.Split(index, "."), -1)
}
m.Cmd(Prefix(cmd), mdb.CREATE, mdb.NAME, name, mdb.ICON, icon, ctx.INDEX, index, mdb.SCORE, "1000", arg)
return icon
}
func PodCmdAction(arg ...string) ice.Actions {
file := kit.FileLine(-1, 100)
return ice.Actions{
mdb.SELECT: {Name: "list hash auto create", Hand: func(m *ice.Message, arg ...string) {
defer m.Display(m.FileURI(file))
msg := disableApp(mdb.HashSelect(m.Spawn(), arg...))
web.PushPodCmd(msg, m.PrefixKey(), arg...)
has := map[string]bool{}
msg.Table(func(value ice.Maps, index int, head []string) {
kit.If(!has[value[ctx.INDEX]+value[ctx.ARGS]], func() { has[value[ctx.INDEX]+value[ctx.ARGS]] = true; m.Push("", value, head) })
})
m.Sort("score,space,index,args", ice.INT)
}},
}
}
func CmdHashAction(arg ...string) ice.Actions {
file := kit.FileLine(-1, 100)
return ice.MergeActions(ice.Actions{
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
switch mdb.HashInputs(m, arg); arg[0] {
case mdb.ICON:
m.Cmd(nfs.DIR, ice.USR_ICONS, func(value ice.Maps) { m.Push(arg[0], value[nfs.PATH]) })
case mdb.NAME:
m.Cmd(nfs.DIR, ice.USR_ICONS, func(value ice.Maps) { m.Push(arg[0], kit.TrimExt(value[nfs.PATH], nfs.PNG)) })
}
}},
mdb.SELECT: {Hand: func(m *ice.Message, arg ...string) {
m.Option(html.FAVICON, m.Cmd(web.SPACE, ice.INFO).Append(mdb.ICONS))
disableApp(mdb.HashSelect(m, arg...).Sort("score,space,index,args").Display(m.FileURI(file)))
}},
}, mdb.HashAction(mdb.SHORT, kit.Select("", arg, 0), mdb.FIELD, kit.Select("time,hash,icon,name,text,score,space,index,args", arg, 1), kit.Slice(arg, 2)))
}