Optimize: Only add auto group when has more than one proxies .

This commit is contained in:
yicheng 2018-08-05 18:45:58 +08:00
parent c68017d604
commit ce19c5202f
3 changed files with 25 additions and 2 deletions

View File

@ -22,6 +22,11 @@ class ConfigFileFactory {
sampleConfigStr = sampleConfigStr?.replacingOccurrences(of: "{{ProxyPlaceHolder}}", with: proxyStr)
sampleConfigStr = sampleConfigStr?.replacingOccurrences(of: "{{ProxyGroupPlaceHolder}}", with: proxyGroupStr)
if proxies.count > 1 {
let autoGroupStr = "ProxyAuto = url-test, \(proxyGroupStr), http://www.google.com/generate_204, 300"
sampleConfigStr = sampleConfigStr?.replacingOccurrences(of: "{{ProxyAutoGroupPlaceHolder}}", with: autoGroupStr)
}
return sampleConfigStr!
}

View File

@ -13,7 +13,7 @@ Proxy = select, {{ProxyGroupPlaceHolder}}
# url-test select which proxy will be used by benchmarking speed to a URL.
# name = url-test, [proxys], url, interval(second)
ProxyAuto = url-test, {{ProxyGroupPlaceHolder}}, http://www.google.com/generate_204, 300
{{ProxyAutoGroupPlaceHolder}}
[Rule]

View File

@ -132,8 +132,26 @@ class PreferencesWindowController: NSWindowController
shakeWindows()
return
}
var vaild = true
var remarkSet = Set<String>()
remarkSet.insert("Proxy")
remarkSet.insert("ProxyAuto")
for config in serverConfigs {
if remarkSet.contains(config.remark) || !config.isValid() {
vaild = false
break
} else {
remarkSet.insert(config.remark)
}
}
if (!vaild) {
self.shakeWindows()
return
}
let str = ConfigFileFactory.configFile(proxies: serverConfigs)
ConfigFileFactory.saveToClashConfigFile(str)
ConfigFileFactory.saveToClashConfigFile(str: str)
window?.performClose(nil)
}