From 7fcbb658a3bb7858c7867bda418f33b9e06b0a28 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Wed, 14 Dec 2022 13:41:49 +0800 Subject: [PATCH] opt chrome --- misc/chrome/cache.go | 2 +- misc/chrome/change.go | 2 +- misc/chrome/chrome.go | 1 - misc/chrome/daemon.go | 66 ++++++++++++++++++++++++++++++++++++++++ misc/chrome/favor.go | 15 ++-------- misc/chrome/field.go | 14 ++++----- misc/chrome/operate.go | 68 ------------------------------------------ misc/chrome/page.go | 4 +-- misc/chrome/style.go | 6 ++-- misc/chrome/sync.go | 4 +-- misc/chrome/video.go | 2 +- 11 files changed, 85 insertions(+), 99 deletions(-) create mode 100644 misc/chrome/daemon.go delete mode 100644 misc/chrome/operate.go diff --git a/misc/chrome/cache.go b/misc/chrome/cache.go index c72cb965..e420c4e8 100644 --- a/misc/chrome/cache.go +++ b/misc/chrome/cache.go @@ -13,7 +13,7 @@ import ( type cache struct { ice.Hash - operate + daemon short string `data:"link"` field string `data:"show,count,total,value,hash,type,name,link"` diff --git a/misc/chrome/change.go b/misc/chrome/change.go index 3ea9d917..6c5fe4c8 100644 --- a/misc/chrome/change.go +++ b/misc/chrome/change.go @@ -9,7 +9,7 @@ import ( type change struct { ice.Hash - operate + daemon short string `data:"property"` list string `name:"list wid tid selector:text@key property:textarea@key auto export import" help:"编辑"` diff --git a/misc/chrome/chrome.go b/misc/chrome/chrome.go index 9a5749c7..b6981262 100644 --- a/misc/chrome/chrome.go +++ b/misc/chrome/chrome.go @@ -6,7 +6,6 @@ import ( type chrome struct { ice.Code - source string `data:"https://mirrors.tencent.com/tinycorelinux/4.x/x86/tcz/src/chromium-browser/chromium-22.0.1229.79.tar.xz"` list string `name:"list path auto order build download" help:"源码"` } diff --git a/misc/chrome/daemon.go b/misc/chrome/daemon.go new file mode 100644 index 00000000..6180820e --- /dev/null +++ b/misc/chrome/daemon.go @@ -0,0 +1,66 @@ +package chrome + +import ( + "shylinux.com/x/ice" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/web" + "shylinux.com/x/icebergs/core/wiki" + kit "shylinux.com/x/toolkits" +) + +type daemon struct { + reload string `name:"reload" help:"刷新"` + list string `name:"list wid tid url auto" help:"操作"` +} + +func (s daemon) send(m *ice.Message, arg ...ice.Any) *ice.Message { + return m.Cmdy(web.SPACE, "chrome", "chrome", arg) +} + +func (s daemon) Inputs(m *ice.Message, arg ...string) { + switch arg[0] { + case mdb.ZONE: + s.send(m.Spawn()).Tables(func(value ice.Maps) { + s.send(m.Spawn(), value[WID]).Tables(func(value ice.Maps) { m.Push(mdb.ZONE, kit.ParseURL(value[URL]).Host) }) + }).Sort(mdb.ZONE) + } +} +func (s daemon) Spide(m *ice.Message, arg ...string) { + if len(arg) < 2 { + s.send(m, arg) + return + } + s.send(m, arg[:2], "spide").Tables(func(value ice.Maps) { + switch value[mdb.TYPE] { + case wiki.VIDEO: + m.PushVideos(mdb.SHOW, value[mdb.LINK]) + case wiki.IMG: + m.PushImages(mdb.SHOW, value[mdb.LINK]) + default: + m.Push(mdb.SHOW, "") + } + }).Cut("show,type,name,link") +} +func (s daemon) Reload(m *ice.Message, arg ...string) { + s.send(m, arg[:2], "user.reload", ice.TRUE).ProcessHold() +} +func (s daemon) List(m *ice.Message, arg ...string) { + switch len(arg) { + case 3: + s.send(m, arg[:2], "user.jumps", arg[2]) + case 2: + s.Spide(m, arg...) + m.Action(s.Reload) + default: + s.send(m, arg) + } + m.StatusTimeCount() +} + +const ( + WID = "wid" + TID = "tid" + URL = "url" +) + +func init() { ice.CodeCtxCmd(daemon{}) } diff --git a/misc/chrome/favor.go b/misc/chrome/favor.go index 6dc89277..643669bb 100644 --- a/misc/chrome/favor.go +++ b/misc/chrome/favor.go @@ -6,24 +6,15 @@ import ( type favor struct { ice.Zone - short string `data:"zone"` field string `data:"time,id,type,name,link"` - insert string `name:"insert zone=官网文档 type name=hi link=hello" help:"添加"` - list string `name:"list zone id auto" help:"收载"` + insert string `name:"insert zone*=官网文档 type name=hi link=*hello"` + list string `name:"list zone id auto insert" help:"收藏"` } -func (f favor) Inputs(m *ice.Message, arg ...string) { - f.Zone.Inputs(m, arg...) -} -func (f favor) Insert(m *ice.Message, arg ...string) { - f.Zone.Insert(m, arg...) -} func (f favor) List(m *ice.Message, arg ...string) { if f.Zone.List(m, arg...); len(arg) == 0 { - m.Action(f.Insert, f.Export, f.Import) - } else if len(arg) == 1 { - m.Action(f.Insert) + m.Action(f.Export, f.Import) } } func init() { ice.CodeCtxCmd(favor{}) } diff --git a/misc/chrome/field.go b/misc/chrome/field.go index c8e22d40..a4b3c26b 100644 --- a/misc/chrome/field.go +++ b/misc/chrome/field.go @@ -10,27 +10,25 @@ import ( type field struct { ice.Zone - operate + daemon short string `data:"zone"` field string `data:"time,id,index,args,style,left,top,right,bottom,selection"` - insert string `name:"insert zone=golang.google.cn index=cli.system args=pwd" help:"添加"` + insert string `name:"insert zone=golang.google.cn index=cli.system args=pwd"` list string `name:"list zone id auto insert" help:"插件"` } func (f field) Inputs(m *ice.Message, arg ...string) { - f.operate.Inputs(m, arg...) + f.daemon.Inputs(m, arg...) } func (f field) Command(m *ice.Message, arg ...string) { m.OptionFields("") f.Zone.List(m.Spawn(), kit.Simple(m.Option(tcp.HOST), arg)...).Table(func(index int, value ice.Maps, head []string) { - if len(arg) == 0 { // 命令列表 + if len(arg) == 0 { m.Option(ice.MSG_OPTS, head) - for k, v := range value { - m.Option(k, v) - } + m.Options(kit.Simple(value)) f.send(m.Spawn(), "1", m.Option(TID), m.CommandKey(), value[mdb.ID], value[ctx.ARGS]) - } else { // 命令详情 + } else { m.Cmdy(ctx.COMMAND, value[mdb.INDEX]) } }) diff --git a/misc/chrome/operate.go b/misc/chrome/operate.go deleted file mode 100644 index 33fa070a..00000000 --- a/misc/chrome/operate.go +++ /dev/null @@ -1,68 +0,0 @@ -package chrome - -import ( - "shylinux.com/x/ice" - "shylinux.com/x/icebergs/base/mdb" - "shylinux.com/x/icebergs/base/web" - "shylinux.com/x/icebergs/core/wiki" - kit "shylinux.com/x/toolkits" -) - -type operate struct { - reload string `name:"reload" help:"刷新"` - list string `name:"list wid tid url auto" help:"操作"` -} - -func (o operate) send(m *ice.Message, arg ...ice.Any) *ice.Message { - return m.Cmdy(web.SPACE, "chrome", "chrome", arg) -} - -func (o operate) Inputs(m *ice.Message, arg ...string) { - switch arg[0] { - case mdb.ZONE: - o.send(m.Spawn()).Tables(func(value ice.Maps) { - o.send(m.Spawn(), value[WID]).Tables(func(value ice.Maps) { - m.Push(mdb.ZONE, kit.ParseURL(value[URL]).Host) - }) - }).Sort(mdb.ZONE) - } -} -func (o operate) Spide(m *ice.Message, arg ...string) { - if len(arg) < 2 { - o.send(m, arg) - return - } - o.send(m, arg[:2], "spide").Tables(func(value ice.Maps) { - switch value[mdb.TYPE] { - case wiki.VIDEO: - m.PushVideos(mdb.SHOW, value[mdb.LINK]) - case wiki.IMG: - m.PushImages(mdb.SHOW, value[mdb.LINK]) - default: - m.Push(mdb.SHOW, "") - } - }).Cut("show,type,name,link") -} -func (o operate) Reload(m *ice.Message, arg ...string) { - o.send(m, arg[:2], "user.reload", ice.TRUE).ProcessHold() -} -func (o operate) List(m *ice.Message, arg ...string) { - switch len(arg) { - case 3: - o.send(m, arg[:2], "user.jumps", arg[2]) - case 2: - m.Action(o.Reload) - o.Spide(m, arg...) - m.StatusTimeCount() - default: - o.send(m, arg) - } -} - -const ( - WID = "wid" - TID = "tid" - URL = "url" -) - -func init() { ice.CodeCtxCmd(operate{}) } diff --git a/misc/chrome/page.go b/misc/chrome/page.go index 36144cec..c62d54c0 100644 --- a/misc/chrome/page.go +++ b/misc/chrome/page.go @@ -6,7 +6,7 @@ import ( ) type page struct { - operate + daemon style field @@ -21,7 +21,7 @@ func (p page) Run(m *ice.Message, arg ...string) { m.Cmdy(p.field.Run, arg) } func (p page) List(m *ice.Message, arg ...string) { - p.operate.Inputs(m, mdb.ZONE) + p.daemon.Inputs(m, mdb.ZONE) } func init() { ice.CodeCtxCmd(page{}) } diff --git a/misc/chrome/style.go b/misc/chrome/style.go index a4661d68..597ec1d4 100644 --- a/misc/chrome/style.go +++ b/misc/chrome/style.go @@ -7,16 +7,16 @@ import ( type style struct { ice.Zone - operate + daemon short string `data:"zone"` field string `data:"time,id,selector,property"` - insert string `name:"insert zone=golang.google.cn selector=. property:textarea" help:"添加"` + insert string `name:"insert zone=golang.google.cn selector=. property:textarea"` list string `name:"style zone id auto insert" help:"样式"` } func (s style) Inputs(m *ice.Message, arg ...string) { - s.operate.Inputs(m, arg...) + s.daemon.Inputs(m, arg...) } func (s style) Command(m *ice.Message, arg ...string) { s.Zone.List(m, m.Option(tcp.HOST)).Tables(func(value ice.Maps) { diff --git a/misc/chrome/sync.go b/misc/chrome/sync.go index faed15b0..15471cd6 100644 --- a/misc/chrome/sync.go +++ b/misc/chrome/sync.go @@ -8,10 +8,10 @@ import ( type sync struct { ice.Lists - favor `name:"favor zone=some type name link" help:"收藏"` + favor `name:"favor zone=some type name link"` field string `data:"time,id,type,name,link"` - insert string `name:"insert type name link" help:"添加" http:"/sync"` + insert string `name:"insert type name link" http:"/sync"` list string `name:"list id auto" help:"同步流"` } diff --git a/misc/chrome/video.go b/misc/chrome/video.go index 8e0b32fb..6c48cc07 100644 --- a/misc/chrome/video.go +++ b/misc/chrome/video.go @@ -6,7 +6,7 @@ import ( ) type video struct { - operate + daemon play string `name:"play" help:"播放"` next string `name:"next" help:"下一集"`