From 94c2979c93e30a30ef533c864e53dc2a0fd98bc6 Mon Sep 17 00:00:00 2001 From: shy Date: Mon, 22 Apr 2024 08:27:21 +0800 Subject: [PATCH] add some --- base/cli/system.go | 6 +-- base/cli/system_darwin.go | 11 ++++++ base/cli/system_linux.go | 11 ++++++ base/cli/system_windows.go | 11 ++++++ misc/systray/systray.go | 75 -------------------------------------- misc/systray/systray.shy | 11 ------ misc/windows/installed.go | 40 -------------------- misc/windows/logged.go | 27 -------------- misc/windows/process.go | 24 ------------ misc/windows/service.go | 23 ------------ misc/windows/windows.go | 32 ---------------- 11 files changed, 34 insertions(+), 237 deletions(-) create mode 100644 base/cli/system_darwin.go create mode 100644 base/cli/system_linux.go create mode 100644 base/cli/system_windows.go delete mode 100644 misc/systray/systray.go delete mode 100644 misc/systray/systray.shy delete mode 100644 misc/windows/installed.go delete mode 100644 misc/windows/logged.go delete mode 100644 misc/windows/process.go delete mode 100644 misc/windows/service.go delete mode 100644 misc/windows/windows.go diff --git a/base/cli/system.go b/base/cli/system.go index a5fdeb3c..e16f3570 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -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 { diff --git a/base/cli/system_darwin.go b/base/cli/system_darwin.go new file mode 100644 index 00000000..1b3ec4af --- /dev/null +++ b/base/cli/system_darwin.go @@ -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 +} diff --git a/base/cli/system_linux.go b/base/cli/system_linux.go new file mode 100644 index 00000000..1b3ec4af --- /dev/null +++ b/base/cli/system_linux.go @@ -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 +} diff --git a/base/cli/system_windows.go b/base/cli/system_windows.go new file mode 100644 index 00000000..1b3ec4af --- /dev/null +++ b/base/cli/system_windows.go @@ -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 +} diff --git a/misc/systray/systray.go b/misc/systray/systray.go deleted file mode 100644 index 8cbe600a..00000000 --- a/misc/systray/systray.go +++ /dev/null @@ -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{}) } diff --git a/misc/systray/systray.shy b/misc/systray/systray.shy deleted file mode 100644 index 71b07e01..00000000 --- a/misc/systray/systray.shy +++ /dev/null @@ -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 -` \ No newline at end of file diff --git a/misc/windows/installed.go b/misc/windows/installed.go deleted file mode 100644 index a51514a9..00000000 --- a/misc/windows/installed.go +++ /dev/null @@ -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{}) } diff --git a/misc/windows/logged.go b/misc/windows/logged.go deleted file mode 100644 index e69dcba7..00000000 --- a/misc/windows/logged.go +++ /dev/null @@ -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{}) } diff --git a/misc/windows/process.go b/misc/windows/process.go deleted file mode 100644 index 4e091c45..00000000 --- a/misc/windows/process.go +++ /dev/null @@ -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{}) } diff --git a/misc/windows/service.go b/misc/windows/service.go deleted file mode 100644 index cd1b1117..00000000 --- a/misc/windows/service.go +++ /dev/null @@ -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{}) } diff --git a/misc/windows/windows.go b/misc/windows/windows.go deleted file mode 100644 index 502c3743..00000000 --- a/misc/windows/windows.go +++ /dev/null @@ -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 -}