From 5d510eb5aa3d21013965ad1aec0b2ab20473c2be Mon Sep 17 00:00:00 2001 From: Mazeorz Date: Tue, 16 Nov 2021 20:08:52 +0800 Subject: [PATCH] [test]core 1.8 --- config/config.go | 17 +++++++++++++++++ hub/route/proxies.go | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/config/config.go b/config/config.go index a9abe71f..aeb9e312 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,7 @@ package config import ( + "container/list" "errors" "fmt" "net" @@ -77,6 +78,12 @@ type FallbackFilter struct { Domain []string `yaml:"domain"` } +var ( + GroupsList = list.New() + ProxiesList = list.New() + ParsingProxiesCallback func(groupsList *list.List, proxiesList *list.List) +) + // Profile config type Profile struct { StoreSelected bool `yaml:"store-selected"` @@ -276,6 +283,8 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[ proxies = make(map[string]C.Proxy) providersMap = make(map[string]providerTypes.ProxyProvider) proxyList := []string{} + _proxiesList := list.New() + _groupsList := list.New() proxiesConfig := cfg.Proxy groupsConfig := cfg.ProxyGroup providersConfig := cfg.ProxyProvider @@ -296,6 +305,7 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[ } proxies[proxy.Name()] = proxy proxyList = append(proxyList, proxy.Name()) + _proxiesList.PushBack(mapping) } // keep the original order of ProxyGroups in config file @@ -305,6 +315,7 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[ return nil, nil, fmt.Errorf("proxy group %d: missing name", idx) } proxyList = append(proxyList, groupName) + _groupsList.PushBack(mapping) } // check if any loop exists and sort the ProxyGroups @@ -375,6 +386,12 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[ []providerTypes.ProxyProvider{pd}, ) proxies["GLOBAL"] = adapter.NewProxy(global) + ProxiesList = _proxiesList + GroupsList = _groupsList + if ParsingProxiesCallback != nil { + // refresh tray menu + go ParsingProxiesCallback(GroupsList, ProxiesList) + } return proxies, providersMap, nil } diff --git a/hub/route/proxies.go b/hub/route/proxies.go index bba9e2a8..6b9f7c70 100644 --- a/hub/route/proxies.go +++ b/hub/route/proxies.go @@ -17,6 +17,10 @@ import ( "github.com/go-chi/render" ) +var ( + SwitchProxiesCallback func(sGroup string, sProxy string) +) + func proxyRouter() http.Handler { r := chi.NewRouter() r.Get("/", getProxies)