Skip to content

Commit 79fd075

Browse files
mapleafgoclaude
andcommitted
feat(api): QueryProxies 附带延迟历史和展开状态,实现 SetGroupExpand
QueryProxies 现在从 ClashServer HistoryStorage 读取每个节点的最近测 速延迟,并从 CacheFile 读取组的 UI 展开状态。SetGroupExpand 通过 CacheFile.StoreGroupExpand 持久化。每个 item 新增 type 字段标识协议。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 02bfffd commit 79fd075

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

core/service.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,20 +378,44 @@ func (s *Service) QueryProxies() string {
378378
return "[]"
379379
}
380380

381+
srv := s.clashServer()
382+
383+
var history adapter.URLTestHistoryStorage
384+
var cache adapter.CacheFile
385+
if srv != nil {
386+
history = srv.HistoryStorage()
387+
}
388+
cache = service.FromContext[adapter.CacheFile](s.boxCtx)
389+
381390
var groups []ProxyGroup
382391
for _, out := range inst.Outbound().Outbounds() {
383392
g, ok := out.(adapter.OutboundGroup)
384393
if !ok {
385394
continue
386395
}
396+
tag := out.Tag()
387397
pg := ProxyGroup{
388-
Tag: out.Tag(),
398+
Tag: tag,
389399
Type: out.Type(),
390400
Selected: g.Now(),
391401
Selectable: true,
392402
}
403+
if cache != nil {
404+
if expand, loaded := cache.LoadGroupExpand(tag); loaded {
405+
pg.Expand = expand
406+
}
407+
}
393408
for _, tag := range g.All() {
394-
pg.Items = append(pg.Items, ProxyGroupItem{Tag: tag})
409+
item := ProxyGroupItem{Tag: tag}
410+
if ob, ok := inst.Outbound().Outbound(tag); ok {
411+
item.Type = ob.Type()
412+
}
413+
if history != nil {
414+
if h := history.LoadURLTestHistory(tag); h != nil {
415+
item.Delay = int32(h.Delay)
416+
}
417+
}
418+
pg.Items = append(pg.Items, item)
395419
}
396420
groups = append(groups, pg)
397421
}
@@ -567,8 +591,11 @@ func (s *Service) CloseConnections() error {
567591
}
568592

569593
func (s *Service) SetGroupExpand(groupTag string, isExpand bool) error {
570-
// TODO: implement via CacheFile
571-
return nil
594+
cf := service.FromContext[adapter.CacheFile](s.boxCtx)
595+
if cf == nil {
596+
return fmt.Errorf("cache file not available")
597+
}
598+
return cf.StoreGroupExpand(groupTag, isExpand)
572599
}
573600

574601
func (s *Service) ResetNetwork() {

core/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type ProxyGroup struct {
1919
Type string `json:"type"`
2020
Selectable bool `json:"selectable"`
2121
Selected string `json:"selected"`
22+
Expand bool `json:"expand,omitempty"`
2223
Items []ProxyGroupItem `json:"items,omitempty"`
2324
}
2425

0 commit comments

Comments
 (0)