1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-25 17:18:05 +08:00
icebergs/core/chat/macos/applications.go
2024-08-09 00:04:14 +08:00

48 lines
1.7 KiB
Go

package macos
import (
"path"
"strings"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"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/core/code"
kit "shylinux.com/x/toolkits"
)
const APPLICATIONS = "applications"
func init() {
Index.MergeCommands(ice.Commands{
APPLICATIONS: {Help: "应用", Role: aaa.VOID, Actions: ice.MergeActions(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { FinderAppend(m, APPLICATIONS, m.PrefixKey()) }},
code.INSTALL: {Hand: func(m *ice.Message, arg ...string) { AppInstall(m, arg[0], arg[1]) }},
mdb.CREATE: {Name: "create space index args name icon"},
}, PodCmdAction(), CmdHashAction("space,index,args"), mdb.ClearOnExitHashAction())},
})
}
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, arg)
return icon
}
func AppInstall(m *ice.Message, icon, index string, arg ...string) string {
return install(m, APPLICATIONS, icon, index, arg...)
}