diff --git a/README.md b/README.md index 13dd2d0d..bfe3b20f 100644 --- a/README.md +++ b/README.md @@ -138,9 +138,7 @@ your-custom-domain.com 手机客户端apk文件可直接在[release页面](https://github.com/nange/easyss/releases)下载。 -用法:创建Easyss配置项:点击右上角+图标 -> 手动输入 -> 选择Easyss - -注意: 在菜单路由项里面,把绕过:中国域名规则和中国IP规则,勾选上。这样对于绝大部分国内的APP和网站就不会走代理了。 +注意: 可将常用的国内大流量APP勾选上跳过,这样可减少电量消耗。当然不选也没关系,Easyss会自动判断该直连还是走代理。 ### 服务器端 和客户端一样, 同样先创建配置文件`config.json`,并配置文件和二进制`easyss-server`放同一目录中。 diff --git a/assets/img/tray3.png b/assets/img/tray3.png index 8fa48fa1..feff5807 100644 Binary files a/assets/img/tray3.png and b/assets/img/tray3.png differ diff --git a/cmd/easyss/tray.go b/cmd/easyss/tray.go index 36e4792f..64c76ab0 100644 --- a/cmd/easyss/tray.go +++ b/cmd/easyss/tray.go @@ -119,7 +119,7 @@ func (st *SysTray) AddProxyRuleMenu() (*systray.MenuItem, *systray.MenuItem, *sy autoBlock := proxyMenue.AddSubMenuItemCheckbox("自动+屏蔽广告跟踪", "自动判断请求是否走代理或者屏蔽", false) if st.SS().ProxyRule() == easyss.ProxyRuleAutoBlock { - auto.Check() + autoBlock.Check() } reverseAuto := proxyMenue.AddSubMenuItemCheckbox("反向自动(国外访问国内)", "适用国外访问国内IP域名", false) diff --git a/config.go b/config.go index 2a168134..14333560 100644 --- a/config.go +++ b/config.go @@ -17,16 +17,52 @@ import ( "github.com/nange/easyss/v2/util" ) -var Methods = map[string]struct{}{ +type ProxyRule int + +const ( + ProxyRuleUnknown ProxyRule = iota + ProxyRuleAuto + ProxyRuleReverseAuto + ProxyRuleProxy + ProxyRuleDirect + ProxyRuleAutoBlock +) + +var proxyRules = map[string]ProxyRule{ + "auto": ProxyRuleAuto, + "reverse_auto": ProxyRuleReverseAuto, + "proxy": ProxyRuleProxy, + "direct": ProxyRuleDirect, + "auto_block": ProxyRuleAutoBlock, +} + +func ParseProxyRuleFromString(rule string) ProxyRule { + if r, ok := proxyRules[rule]; ok { + return r + } + + return ProxyRuleUnknown +} + +func AllProxyRule() []string { + keys := make([]string, 0, len(proxyRules)) + for k := range proxyRules { + keys = append(keys, k) + } + return keys +} + +var methods = map[string]struct{}{ "aes-256-gcm": {}, "chacha20-poly1305": {}, } -var ProxyRules = map[string]struct{}{ - "auto": {}, - "auto_block": {}, - "proxy": {}, - "direct": {}, +func AllMethod() []string { + keys := make([]string, 0, len(methods)) + for k := range proxyRules { + keys = append(keys, k) + } + return keys } const ( @@ -134,8 +170,8 @@ func (c *Config) Validate() error { } } if c.Method != "" { - if _, ok := Methods[c.Method]; !ok { - return fmt.Errorf("unsupported method:%s, supported methods:[aes-256-gcm, chacha20-poly1305]", c.Method) + if _, ok := methods[c.Method]; !ok { + return fmt.Errorf("unsupported method:%s, supported methods:%v", c.Method, AllMethod()) } } switch c.LogLevel { @@ -144,8 +180,8 @@ func (c *Config) Validate() error { return fmt.Errorf("unsupported log-level:%s, supported log-levels:[debug, info, warn, error]", c.LogLevel) } if c.ProxyRule != "" { - if _, ok := ProxyRules[c.ProxyRule]; !ok { - return fmt.Errorf("unsupported proxy rule:%s, supported rules:[auto, auto_block, proxy, direct]", c.ProxyRule) + if _, ok := proxyRules[c.ProxyRule]; !ok { + return fmt.Errorf("unsupported proxy rule:%s, supported rules:%v", c.ProxyRule, AllProxyRule()) } } if c.OutboundProto != OutboundProtoNative && c.OutboundProto != OutboundProtoHTTP && diff --git a/easyss.go b/easyss.go index 70abf1ec..4237bb7d 100644 --- a/easyss.go +++ b/easyss.go @@ -165,32 +165,6 @@ func (gs *GeoSite) SimpleMatch(domain string, matchSub bool) bool { return false } -type ProxyRule int - -const ( - ProxyRuleUnknown ProxyRule = iota - ProxyRuleAuto - ProxyRuleReverseAuto - ProxyRuleProxy - ProxyRuleDirect - ProxyRuleAutoBlock -) - -func ParseProxyRuleFromString(rule string) ProxyRule { - m := map[string]ProxyRule{ - "auto": ProxyRuleAuto, - "reverse_auto": ProxyRuleReverseAuto, - "proxy": ProxyRuleProxy, - "direct": ProxyRuleDirect, - "auto_block": ProxyRuleAutoBlock, - } - if r, ok := m[rule]; ok { - return r - } - - return ProxyRuleUnknown -} - type HostRule int const (