1
0
forked from x/icebergs

add windows

This commit is contained in:
IT 老营长 @云轩领航-创始人 2024-04-22 00:36:57 +08:00
parent b3959aa68d
commit f79d9b23d7
9 changed files with 273 additions and 8 deletions

View File

@ -65,8 +65,9 @@ const (
ENV = "env"
API = "api"
MOD = "mod"
PID = "pid"
PWD = "pwd"
PID = "pid"
PPID = "ppid"
)
const (
BUILD = "build"
@ -160,9 +161,9 @@ func init() {
func Opens(m *ice.Message, arg ...string) {
if !tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
return
// return
} else if len(arg) == 0 || arg[0] == "" {
return
// return
}
switch runtime.GOOS {
case DARWIN:

75
misc/systray/systray.go Normal file
View File

@ -0,0 +1,75 @@
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{}) }

11
misc/systray/systray.shy Normal file
View File

@ -0,0 +1,11 @@
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
`

32
misc/wind/wind.go Normal file
View File

@ -0,0 +1,32 @@
package wind
import (
"runtime"
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/cli"
"github.com/rodrigocfd/windigo/ui"
"github.com/rodrigocfd/windigo/win"
)
type wind struct {
ice.Hash
list string `name:"list hash auto"`
}
func (s wind) List(m *ice.Message, arg ...string) {
m.Echo("hello world")
}
func init() { ice.ChatCtxCmd(wind{}) }
func Run(arg ...string) string {
go func() { ice.Runs(func() {}, "serve", "start") }()
runtime.LockOSThread()
wnd := ui.NewWindowMain(ui.WindowMainOpts().Title("Contexts").ClientArea(win.SIZE{Cx: 340, Cy: 80}))
btnShow := ui.NewButton(wnd, ui.ButtonOpts().Text("&Open").Position(win.POINT{X: 0, Y: 0}))
btnShow.On().BnClicked(func() { ice.Pulse.Cmd(cli.SYSTEM, "explorer", "http://localhost:9020") })
wnd.RunAsMain()
return ""
}

40
misc/windows/installed.go Normal file
View File

@ -0,0 +1,40 @@
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{}) }

27
misc/windows/logged.go Normal file
View File

@ -0,0 +1,27 @@
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{}) }

24
misc/windows/process.go Normal file
View File

@ -0,0 +1,24 @@
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{}) }

23
misc/windows/service.go Normal file
View File

@ -0,0 +1,23 @@
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{}) }

32
misc/windows/windows.go Normal file
View File

@ -0,0 +1,32 @@
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
}