Add option to change style of proxies section in Clash subscriptions

This commit is contained in:
Tindy X committed 2020-08-12 18:33:31 +08:00
1 parent 41bc002cab
commit f671230ce8
5 files changed
+37 -1

No files matched your search

+6
View File
@@ -54,6 +54,7 @@ bool add_emoji = false, remove_old_emoji = false, append_proxy_type = false, fil
tribool udp_flag, tfo_flag, scv_flag, tls13_flag, enable_insert;
bool do_sort = false, config_update_strict = false;
bool clash_use_new_field_name = false;
std::string clash_proxies_style = "flow";
std::string proxy_config, proxy_ruleset, proxy_subscription;
int config_update_interval = 0;
std::string sort_script, filter_script;
@@ -745,6 +746,7 @@ void readYAMLConf(YAML::Node &node)
section["filter_deprecated_nodes"] >> filter_deprecated;
section["append_sub_userinfo"] >> append_userinfo;
section["clash_use_new_field_name"] >> clash_use_new_field_name;
section["clash_proxies_style"] >> clash_proxies_style;
}
if(section["rename_node"].IsSequence())
@@ -983,6 +985,7 @@ void readConf()
ini.GetBoolIfExist("filter_deprecated_nodes", filter_deprecated);
ini.GetBoolIfExist("append_sub_userinfo", append_userinfo);
ini.GetBoolIfExist("clash_use_new_field_name", clash_use_new_field_name);
ini.GetIfExist("clash_proxies_style", clash_proxies_style);
if(ini.ItemPrefixExist("rename_node"))
{
ini.GetAll("rename_node", tempArray);
@@ -1450,6 +1453,8 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
if((target == "clash" || target == "clashr") && clash_script.is_undef())
expand.define(true);
ext.clash_proxies_style = clash_proxies_style;
/// read preference from argument, assign global var if not in argument
ext.tfo.parse(tfo).parse(tfo_flag);
ext.udp.parse(udp).parse(udp_flag);
@@ -2072,6 +2077,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
}
extra_settings ext = {true, true, dummy_str_array, dummy_str_array, false, false, false, false, do_sort, filter_deprecated, clash_use_new_field_name, false, "", "", "", udp_flag, tfo_flag, scv_flag, tls13_flag};
ext.clash_proxies_style = clash_proxies_style;
netchToClash(nodes, clash, dummy_str_array, false, ext);
+21 -1
View File
@@ -1149,6 +1149,20 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, const stri
std::vector<nodeInfo> nodelist;
bool tlssecure;
string_array vArray, remarks_list, filtered_nodelist;
/// proxies style
bool block = false, compact = false;
switch(hash_(ext.clash_proxies_style))
{
case "block"_hash:
block = true;
break;
default:
case "flow"_hash:
break;
case "compact"_hash:
compact = true;
break;
}
for(nodeInfo &x : nodes)
{
@@ -1341,12 +1355,18 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, const stri
if(udp)
singleproxy["udp"] = true;
singleproxy.SetStyle(YAML::EmitterStyle::Flow);
if(block)
singleproxy.SetStyle(YAML::EmitterStyle::Block);
else
singleproxy.SetStyle(YAML::EmitterStyle::Flow);
proxies.push_back(singleproxy);
remarks_list.emplace_back(std::move(remark));
nodelist.emplace_back(x);
}
if(compact)
proxies.SetStyle(YAML::EmitterStyle::Flow);
if(ext.nodelist)
{
YAML::Node provider;
+1
View File
@@ -51,6 +51,7 @@ struct extra_settings
tribool tls13 = tribool();
bool clash_classical_ruleset = false;
std::string sort_script = "";
std::string clash_proxies_style = "flow";
};
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules, bool new_field_name);