1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-12-25 10:28:18 +08:00
parent 2d1c99af56
commit d60b1fc1a5
2 changed files with 14 additions and 8 deletions

View File

@ -177,14 +177,16 @@ func OpenCmds(m *ice.Message, arg ...string) *ice.Message {
if len(arg) == 0 || arg[0] == "" { if len(arg) == 0 || arg[0] == "" {
return m return m
} }
m.Cmd(SYSTEM, "osascript", "-e", kit.Format(` TellApp(m, "Terminal", kit.Format(`do script %s`, strings.Join(arg, "; ")), "activate")
tell application "Terminal"
do script "%s"
activate
end tell
`, strings.Join(arg, "; ")))
return m return m
} }
func TellApp(m *ice.Message, app string, arg ...string) {
OSAScript(m, kit.Format(`
tell application "%s"
%s
end tell
`, app, strings.Join(arg, lex.NL)))
}
func OSAScript(m *ice.Message, arg ...string) { func OSAScript(m *ice.Message, arg ...string) {
m.Cmd(SYSTEM, "osascript", "-e", arg) m.Cmd(SYSTEM, "osascript", "-e", arg)
} }

View File

@ -163,7 +163,7 @@ const RUNTIME = "runtime"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,procstat,procinfo,bootinfo,role,api,cli,cmd,mod,env,path,chain,routine auto upgrade restart reboot logs conf lock", Icon: "Infomation.png", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{ RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,procstat,procinfo,bootinfo,role,api,cli,cmd,mod,env,path,chain,routine auto upgrade restart reboot logs conf", Icon: "Infomation.png", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
aaa.White(m, ice.LICENSE) aaa.White(m, ice.LICENSE)
_runtime_init(m) _runtime_init(m)
@ -270,7 +270,10 @@ func init() {
OpenCmds(m, kit.Format("cd %s", kit.Path("")), "vim etc/init.shy") OpenCmds(m, kit.Format("cd %s", kit.Path("")), "vim etc/init.shy")
}}, }},
"lock": {Help: "锁屏", Hand: func(m *ice.Message, arg ...string) { "lock": {Help: "锁屏", Hand: func(m *ice.Message, arg ...string) {
OSAScript(m, `tell application "System Events" to keystroke "q" using {control down, command down}`) switch runtime.GOOS {
case DARWIN:
TellApp(m, "System Events", `keystroke "q" using {control down, command down}`)
}
}}, }},
}, ctx.ConfAction("")), Hand: func(m *ice.Message, arg ...string) { }, ctx.ConfAction("")), Hand: func(m *ice.Message, arg ...string) {
kit.If(len(arg) > 0 && arg[0] == BOOTINFO, func() { arg = arg[1:] }) kit.If(len(arg) > 0 && arg[0] == BOOTINFO, func() { arg = arg[1:] })
@ -279,6 +282,7 @@ func init() {
mdb.NAME, ice.Info.NodeName, nfs.VERSION, ice.Info.Make.Versions(), mdb.NAME, ice.Info.NodeName, nfs.VERSION, ice.Info.Make.Versions(),
).Option(ice.MSG_ACTION, "") ).Option(ice.MSG_ACTION, "")
ctx.DisplayStoryJSON(m) ctx.DisplayStoryJSON(m)
m.Action("lock")
}}, }},
}) })
} }