forked from x/icebergs
add some
This commit is contained in:
parent
f79d9b23d7
commit
94c2979c93
@ -7,9 +7,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
@ -67,9 +65,7 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
}
|
||||
kit.For(env, func(k, v string) { cmd.Env = append(cmd.Env, kit.Format("%s=%s", k, v)) })
|
||||
kit.If(len(cmd.Env) > 0 && m.IsDebug(), func() { m.Logs(EXEC, CMD_ENV, kit.Format(cmd.Env)) })
|
||||
if runtime.GOOS == "windows" {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
||||
}
|
||||
_system_cmds(m, cmd, arg...)
|
||||
return cmd
|
||||
}
|
||||
func _system_out(m *ice.Message, out string) io.Writer {
|
||||
|
11
base/cli/system_darwin.go
Normal file
11
base/cli/system_darwin.go
Normal file
@ -0,0 +1,11 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
|
||||
func _system_cmds(m *ice.Message, cmd *exec.Cmd, arg ...string) *exec.Cmd {
|
||||
return cmd
|
||||
}
|
11
base/cli/system_linux.go
Normal file
11
base/cli/system_linux.go
Normal file
@ -0,0 +1,11 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
|
||||
func _system_cmds(m *ice.Message, cmd *exec.Cmd, arg ...string) *exec.Cmd {
|
||||
return cmd
|
||||
}
|
11
base/cli/system_windows.go
Normal file
11
base/cli/system_windows.go
Normal file
@ -0,0 +1,11 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
|
||||
func _system_cmds(m *ice.Message, cmd *exec.Cmd, arg ...string) *exec.Cmd {
|
||||
return cmd
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package systray
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
"shylinux.com/x/ice"
|
||||
"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"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
|
||||
"github.com/getlantern/systray"
|
||||
)
|
||||
|
||||
type Systray struct {
|
||||
ice.Hash
|
||||
short string `data:"name"`
|
||||
field string `data:"time,type,name,text,icons,order,space,index"`
|
||||
create string `name:"create type name* text icons order space index"`
|
||||
list string `name:"list name auto"`
|
||||
}
|
||||
|
||||
func (s Systray) Init(m *ice.Message, arg ...string) {
|
||||
m = m.Spawn()
|
||||
s.Hash.Init(m, arg...).GoSleep("3s", func() {
|
||||
opened := false
|
||||
m.AdminCmd(web.SPACE).Table(func(value ice.Maps) { kit.If(value[mdb.TYPE] == web.PORTAL, func() { opened = true }) })
|
||||
opened = true
|
||||
kit.If(!opened, func() { m.Spawn().Opens(m.SpideOrigin(ice.OPS)) })
|
||||
m.Go(func() { systray.Run(func() { s.Show(m, arg...) }, func() {}) })
|
||||
})
|
||||
}
|
||||
func (s Systray) Show(m *ice.Message, arg ...string) {
|
||||
title := kit.JoinLine(m.SpideOrigin(ice.OPS), ice.Info.Make.Module, path.Base(kit.Path("")))
|
||||
systray.SetIcon([]byte(m.Cmdx(nfs.CAT, ice.SRC_MAIN_ICO)))
|
||||
systray.SetTitle(title)
|
||||
systray.SetTooltip(title)
|
||||
s.List(m).Table(func(value ice.Maps) {
|
||||
item := systray.AddMenuItem(value[mdb.NAME], value[mdb.TEXT])
|
||||
kit.If(value[mdb.ICONS], func(p string) { kit.If(m.Cmdx(nfs.CAT, p), func(p string) { item.SetIcon([]byte(p)) }) })
|
||||
m.Go(func() {
|
||||
for _ = range item.ClickedCh {
|
||||
if value[ctx.INDEX] == ice.EXIT {
|
||||
m.Cmd(ice.EXIT)
|
||||
break
|
||||
}
|
||||
p := m.SpideOrigin(ice.OPS)
|
||||
kit.If(value[web.SPACE], func(pod string) { p += web.S(pod) })
|
||||
kit.If(value[ctx.INDEX], func(cmd string) { p += web.C(cmd) })
|
||||
m.Opens(p)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
func (s Systray) List(m *ice.Message, arg ...string) *ice.Message {
|
||||
if s.Hash.List(m, arg...); len(arg) == 0 {
|
||||
if m.Action(s.Create, s.Build).Sort(mdb.ORDER, ice.INT).Length() == 0 {
|
||||
kit.For([]string{web.PORTAL, web.DESKTOP, web.DREAM, web.ADMIN, web.VIMER, ice.EXIT}, func(p string) {
|
||||
m.Search(p, func(key string, cmd *ice.Command) {
|
||||
m.Push(mdb.NAME, kit.Format("%s(%s)", key, cmd.Help)).Push(ctx.INDEX, p)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
func (s Systray) Build(m *ice.Message, arg ...string) {
|
||||
defer m.ToastProcess()()
|
||||
m.Cmdy(cli.SYSTEM, cli.GO, cli.BUILD, "-ldflags", "-w -s -H=windowsgui", "-o", ice.USR_PUBLISH+"ice.exe",
|
||||
ice.SRC_MAIN_GO, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO, ice.SRC_BINPACK_USR_GO)
|
||||
}
|
||||
|
||||
func init() { ice.ChatCtxCmd(Systray{}) }
|
@ -1,11 +0,0 @@
|
||||
chapter "systray"
|
||||
refer `
|
||||
源码 https://github.com/getlantern/systray
|
||||
文档 https://pkg.go.dev/github.com/getlantern/systray#section-readme
|
||||
`
|
||||
field web.chat.systray.systray
|
||||
field web.code.git.source args `
|
||||
https://github.com/getlantern/systray
|
||||
usr/local/systray/
|
||||
go.mod
|
||||
`
|
@ -1,40 +0,0 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
|
||||
wapi "github.com/iamacarpet/go-win64api"
|
||||
)
|
||||
|
||||
type installed struct {
|
||||
list string `name:"list name auto filter"`
|
||||
}
|
||||
|
||||
func (s installed) List(m *ice.Message, arg ...string) {
|
||||
list, err := wapi.InstalledSoftwareList()
|
||||
ListPush(m, list, err,
|
||||
"installDate",
|
||||
"arch", "estimatedSize",
|
||||
"displayName", "displayVersion",
|
||||
"publisher", "HelpLink",
|
||||
"InstallLocation",
|
||||
"UninstallString",
|
||||
)
|
||||
m.RenameAppend(
|
||||
"installDate", mdb.TIME,
|
||||
"estimatedSize", nfs.SIZE,
|
||||
"displayName", mdb.NAME,
|
||||
"displayVersion", nfs.VERSION,
|
||||
)
|
||||
m.RewriteAppend(func(value, key string, index int) string {
|
||||
kit.If(key == nfs.SIZE, func() { value = kit.FmtSize(kit.Int(value) * 1024) })
|
||||
kit.If(key == mdb.TIME, func() { value = ParseTime(m, value) })
|
||||
return value
|
||||
})
|
||||
m.SortIntR(nfs.SIZE)
|
||||
}
|
||||
|
||||
func init() { ice.ChatCtxCmd(installed{}) }
|
@ -1,27 +0,0 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
|
||||
wapi "github.com/iamacarpet/go-win64api"
|
||||
)
|
||||
|
||||
type logged struct {
|
||||
list string `name:"list username auto"`
|
||||
}
|
||||
|
||||
func (s logged) List(m *ice.Message, arg ...string) {
|
||||
list, err := wapi.ListLoggedInUsers()
|
||||
ListPush(m, list, err, "logonTime", aaa.USERNAME, web.DOMAIN, "isLocal", "isAdmin")
|
||||
m.RenameAppend("logonTime", mdb.TIME)
|
||||
m.RewriteAppend(func(value, key string, index int) string {
|
||||
kit.If(key == mdb.TIME, func() { value = ParseTime(m, value) })
|
||||
return value
|
||||
})
|
||||
}
|
||||
|
||||
func init() { ice.ChatCtxCmd(logged{}) }
|
@ -1,24 +0,0 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
|
||||
wapi "github.com/iamacarpet/go-win64api"
|
||||
)
|
||||
|
||||
type process struct {
|
||||
list string `name:"list name auto filter"`
|
||||
}
|
||||
|
||||
func (s process) List(m *ice.Message, arg ...string) {
|
||||
list, err := wapi.ProcessList()
|
||||
ListPush(m, list, err, "parentpid", cli.PID, aaa.USERNAME, "exeName", "fullPath")
|
||||
m.RenameAppend("parentpid", cli.PPID, "exeName", mdb.NAME, "fullPath", nfs.PATH)
|
||||
m.Sort("username,path")
|
||||
}
|
||||
|
||||
func init() { ice.ChatCtxCmd(process{}) }
|
@ -1,23 +0,0 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
|
||||
wapi "github.com/iamacarpet/go-win64api"
|
||||
)
|
||||
|
||||
type service struct {
|
||||
list string `name:"list name auto filter"`
|
||||
}
|
||||
|
||||
func (s service) List(m *ice.Message, arg ...string) {
|
||||
list, err := wapi.GetServices()
|
||||
ListPush(m, list, err, cli.PID, "statusText", mdb.NAME, "displayName")
|
||||
m.RenameAppend("statusText", mdb.STATUS, "displayName", mdb.TEXT)
|
||||
m.StatusTimeCountStats(mdb.STATUS)
|
||||
m.Sort("status,name")
|
||||
}
|
||||
|
||||
func init() { ice.ChatCtxCmd(service{}) }
|
@ -1,32 +0,0 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"shylinux.com/x/ice"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
type windows struct {
|
||||
cmds string `data:"logged,process,service,installed"`
|
||||
list string `name:"list name auto"`
|
||||
}
|
||||
|
||||
func (s windows) List(m *ice.Message, arg ...string) { m.DisplayStudio() }
|
||||
|
||||
func init() { ice.ChatCtxCmd(windows{}) }
|
||||
|
||||
func ListPush(m *ice.Message, list ice.Any, err error, arg ...string) *ice.Message {
|
||||
if !m.Warn(err) {
|
||||
kit.For(kit.UnMarshal(kit.Format(list)), func(value ice.Map) { m.PushRecord(value, arg...) })
|
||||
kit.If(m.IsDebug(), func() { m.Echo(kit.Formats(list)) })
|
||||
}
|
||||
return m
|
||||
}
|
||||
func ParseTime(m *ice.Message, value string) string {
|
||||
if t, e := time.Parse(time.RFC3339, value); e == nil {
|
||||
value = strings.TrimSuffix(t.Local().Format(ice.MOD_TIME), ".000")
|
||||
}
|
||||
return value
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user