Show Providers proxy

This commit is contained in:
2dust
2022-04-20 19:45:59 +08:00
parent 7016f428ed
commit 463e259523
5 changed files with 72 additions and 14 deletions

View File

@@ -11,6 +11,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using static clashN.Mode.ClashProviders;
using static clashN.Mode.ClashProxies; using static clashN.Mode.ClashProxies;
namespace clashN.Forms namespace clashN.Forms
@@ -18,6 +19,7 @@ namespace clashN.Forms
public partial class ProxiesForm : BaseForm public partial class ProxiesForm : BaseForm
{ {
Dictionary<String, ProxiesItem> proxies; Dictionary<String, ProxiesItem> proxies;
Dictionary<String, ProvidersItem> providers;
ProxiesItem selectedProxy; ProxiesItem selectedProxy;
public ProxiesForm() public ProxiesForm()
@@ -78,9 +80,11 @@ namespace clashN.Forms
private void GetClashProxies(bool refreshUI) private void GetClashProxies(bool refreshUI)
{ {
MainFormHandler.Instance.GetClashProxies(config, it => MainFormHandler.Instance.GetClashProxies(config, (it, it2) =>
{ {
proxies = it.proxies; proxies = it.proxies;
providers = it2.providers;
LazyConfig.Instance.SetProxies(proxies); LazyConfig.Instance.SetProxies(proxies);
if (refreshUI) if (refreshUI)
{ {
@@ -106,7 +110,7 @@ namespace clashN.Forms
foreach (KeyValuePair<string, ProxiesItem> kv in proxies) foreach (KeyValuePair<string, ProxiesItem> kv in proxies)
{ {
if (kv.Value.type != "Selector" && kv.Value.type != "URLTest") if (!Global.allowSelectType.Contains(kv.Value.type.ToLower()))
{ {
continue; continue;
} }
@@ -159,7 +163,8 @@ namespace clashN.Forms
foreach (var item in proxy.all) foreach (var item in proxy.all)
{ {
var isActive = item == proxy.now; var isActive = item == proxy.now;
proxies.TryGetValue(item, out ProxiesItem proxy2);
var proxy2 = TryGetProxy(item);
if (proxy2 == null) if (proxy2 == null)
{ {
continue; continue;
@@ -197,6 +202,28 @@ namespace clashN.Forms
lvDetail.EndUpdate(); lvDetail.EndUpdate();
} }
private ProxiesItem TryGetProxy(string name)
{
proxies.TryGetValue(name, out ProxiesItem proxy2);
if (proxy2 != null)
{
return proxy2;
}
//from providers
foreach (KeyValuePair<string, ProvidersItem> kv in providers)
{
if (Global.proxyVehicleType.Contains(kv.Value.vehicleType.ToLower()))
{
var proxy3 = kv.Value.proxies.FirstOrDefault(t => t.name == name);
if (proxy3 != null)
{
return proxy3;
}
}
}
return null;
}
private void lvProxies_SelectedIndexChanged(object sender, EventArgs e) private void lvProxies_SelectedIndexChanged(object sender, EventArgs e)
{ {
RefreshDetail(GetLvSelectedIndex()); RefreshDetail(GetLvSelectedIndex());

View File

@@ -48,7 +48,7 @@ namespace clashN
/// </summary> /// </summary>
public const string httpsProtocol = "https://"; public const string httpsProtocol = "https://";
public const string clashProtocol = "clash://"; public const string clashProtocol = "clash://";
/// <summary> /// <summary>
/// MyRegPath /// MyRegPath
@@ -83,6 +83,12 @@ namespace clashN
public static readonly List<string> coreTypes = new List<string> { "clash", "clash_meta" }; public static readonly List<string> coreTypes = new List<string> { "clash", "clash_meta" };
public static readonly List<string> allowSelectType = new List<string> { "selector", "urltest" };
public static readonly List<string> notAllowTestType = new List<string> { "selector", "urltest", "direct", "reject", "compatible", "pass" };
public static readonly List<string> proxyVehicleType = new List<string> { "file", "http" };
public const string CheckMark = "√"; public const string CheckMark = "√";

View File

@@ -100,6 +100,12 @@ namespace clashN.Handler
ModifyContent(fileContent, "allow-lan", "false"); ModifyContent(fileContent, "allow-lan", "false");
} }
//mode
if (!fileContent.ContainsKey("mode"))
{
ModifyContent(fileContent, "mode", "Rule");
}
//enable tun mode //enable tun mode
if (node.enableTun) if (node.enableTun)
{ {

View File

@@ -12,6 +12,7 @@ using System.Linq;
using clashN.Resx; using clashN.Resx;
using static clashN.Mode.ClashProxies; using static clashN.Mode.ClashProxies;
using clashN.Base; using clashN.Base;
using static clashN.Mode.ClashProviders;
namespace clashN.Handler namespace clashN.Handler
{ {
@@ -195,19 +196,22 @@ namespace clashN.Handler
} }
} }
public void GetClashProxies(Config config, Action<ClashProxies> update) public void GetClashProxies(Config config, Action<ClashProxies, ClashProviders> update)
{ {
Task.Run(() => GetClashProxiesAsync(config, update)); Task.Run(() => GetClashProxiesAsync(config, update));
} }
private async Task GetClashProxiesAsync(Config config, Action<ClashProxies> update) private async Task GetClashProxiesAsync(Config config, Action<ClashProxies, ClashProviders> update)
{ {
var url = $"{Global.httpProtocol}{Global.Loopback}:{config.APIPort}/proxies"; var url = $"{Global.httpProtocol}{Global.Loopback}:{config.APIPort}/proxies";
var result = await Base.HttpClientHelper.GetInstance().GetAsync(url); var result = await HttpClientHelper.GetInstance().GetAsync(url);
var clashProxies = Utils.FromJson<ClashProxies>(result); var clashProxies = Utils.FromJson<ClashProxies>(result);
update(clashProxies); var url2 = $"{Global.httpProtocol}{Global.Loopback}:{config.APIPort}/providers/proxies";
var result2 = await HttpClientHelper.GetInstance().GetAsync(url2);
var clashProviders = Utils.FromJson<ClashProviders>(result2);
update(clashProxies, clashProviders);
} }
public void ClashProxiesDelayTest(Action<string> update) public void ClashProxiesDelayTest(Action<string> update)
@@ -225,11 +229,7 @@ namespace clashN.Handler
List<Task> tasks = new List<Task>(); List<Task> tasks = new List<Task>();
foreach (KeyValuePair<string, ProxiesItem> kv in proxies) foreach (KeyValuePair<string, ProxiesItem> kv in proxies)
{ {
if (kv.Value.type == "Selector" if (Global.notAllowTestType.Contains(kv.Value.type.ToLower()))
|| kv.Value.type == "URLTest"
|| kv.Value.type == "Direct"
|| kv.Value.type == "Reject"
)
{ {
continue; continue;
} }

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using static clashN.Mode.ClashProxies;
namespace clashN.Mode
{
public class ClashProviders
{
public Dictionary<String, ProvidersItem> providers { get; set; }
public class ProvidersItem
{
public string name { get; set; }
public ProxiesItem[] proxies { get; set; }
public string type { get; set; }
public string vehicleType { get; set; }
}
}
}