Compare commits

..

No commits in common. "e6011cfede8101adaa46e08f4d25e7865d40fd07" and "3f0f895424fe5ca0cc1e3cc8cb9ee9a77513e088" have entirely different histories.

9 changed files with 135 additions and 112 deletions

View file

@ -11,9 +11,9 @@ namespace ServiceLib.Handler
private Dictionary<string, ProxiesItem>? _proxies; private Dictionary<string, ProxiesItem>? _proxies;
public Dictionary<string, object> ProfileContent { get; set; } public Dictionary<string, object> ProfileContent { get; set; }
public async Task<Tuple<ClashProxies, ClashProviders>?> GetClashProxiesAsync() public async Task<Tuple<ClashProxies, ClashProviders>?> GetClashProxiesAsync(Config config)
{ {
for (var i = 0; i < 3; i++) for (var i = 0; i < 5; i++)
{ {
var url = $"{GetApiUrl()}/proxies"; var url = $"{GetApiUrl()}/proxies";
var result = await HttpClientHelper.Instance.TryGetAsync(url); var result = await HttpClientHelper.Instance.TryGetAsync(url);
@ -41,26 +41,34 @@ namespace ServiceLib.Handler
{ {
if (blAll) if (blAll)
{ {
for (var i = 0; i < 5; i++)
{
if (_proxies != null)
{
break;
}
await Task.Delay(5000);
}
if (_proxies == null) if (_proxies == null)
{ {
await GetClashProxiesAsync(); return;
} }
lstProxy = new List<ClashProxyModel>(); lstProxy = new List<ClashProxyModel>();
foreach (var kv in _proxies ?? []) foreach (var kv in _proxies)
{ {
if (Global.notAllowTestType.Contains(kv.Value.type?.ToLower())) if (Global.notAllowTestType.Contains(kv.Value.type.ToLower()))
{ {
continue; continue;
} }
lstProxy.Add(new ClashProxyModel() lstProxy.Add(new ClashProxyModel()
{ {
Name = kv.Value.name, Name = kv.Value.name,
Type = kv.Value.type?.ToLower(), Type = kv.Value.type.ToLower(),
}); });
} }
} }
if (lstProxy is not { Count: > 0 }) if (lstProxy == null)
{ {
return; return;
} }
@ -149,7 +157,7 @@ namespace ServiceLib.Handler
} }
} }
public async Task<ClashConnections?> GetClashConnectionsAsync() public async Task<ClashConnections?> GetClashConnectionsAsync(Config config)
{ {
try try
{ {

View file

@ -5,44 +5,51 @@ namespace ServiceLib.Handler.Fmt
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks) public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
{ {
var configObjects = JsonUtils.Deserialize<object[]>(strData); var configObjects = JsonUtils.Deserialize<object[]>(strData);
if (configObjects is not { Length: > 0 }) if (configObjects != null && configObjects.Length > 0)
{ {
return null; List<ProfileItem> lstResult = [];
} foreach (var configObject in configObjects)
List<ProfileItem> lstResult = [];
foreach (var configObject in configObjects)
{
var objectString = JsonUtils.Serialize(configObject);
var profileIt = ResolveFull(objectString, subRemarks);
if (profileIt != null)
{ {
lstResult.Add(profileIt); var objectString = JsonUtils.Serialize(configObject);
var singboxCon = JsonUtils.Deserialize<SingboxConfig>(objectString);
if (singboxCon?.inbounds?.Count > 0
&& singboxCon.outbounds?.Count > 0
&& singboxCon.route != null)
{
var fileName = WriteAllText(objectString);
var profileIt = new ProfileItem
{
CoreType = ECoreType.sing_box,
Address = fileName,
Remarks = subRemarks ?? "singbox_custom",
};
lstResult.Add(profileIt);
}
} }
return lstResult;
} }
return lstResult; return null;
} }
public static ProfileItem? ResolveFull(string strData, string? subRemarks) public static ProfileItem? ResolveFull(string strData, string? subRemarks)
{ {
var config = JsonUtils.ParseJson(strData); var singboxConfig = JsonUtils.Deserialize<SingboxConfig>(strData);
if (config?["inbounds"] == null if (singboxConfig?.inbounds?.Count > 0
|| config["outbounds"] == null && singboxConfig.outbounds?.Count > 0
|| config["route"] == null && singboxConfig.route != null)
|| config["dns"] == null)
{ {
return null; var fileName = WriteAllText(strData);
var profileItem = new ProfileItem
{
CoreType = ECoreType.sing_box,
Address = fileName,
Remarks = subRemarks ?? "singbox_custom"
};
return profileItem;
} }
return null;
var fileName = WriteAllText(strData);
var profileItem = new ProfileItem
{
CoreType = ECoreType.sing_box,
Address = fileName,
Remarks = subRemarks ?? "singbox_custom"
};
return profileItem;
} }
} }
} }

View file

@ -5,45 +5,52 @@ namespace ServiceLib.Handler.Fmt
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks) public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
{ {
var configObjects = JsonUtils.Deserialize<object[]>(strData); var configObjects = JsonUtils.Deserialize<object[]>(strData);
if (configObjects is not { Length: > 0 }) if (configObjects != null && configObjects.Length > 0)
{ {
return null; List<ProfileItem> lstResult = [];
} foreach (var configObject in configObjects)
List<ProfileItem> lstResult = [];
foreach (var configObject in configObjects)
{
var objectString = JsonUtils.Serialize(configObject);
var profileIt = ResolveFull(objectString, subRemarks);
if (profileIt != null)
{ {
lstResult.Add(profileIt); var objectString = JsonUtils.Serialize(configObject);
} var v2rayCon = JsonUtils.Deserialize<V2rayConfig>(objectString);
} if (v2rayCon?.inbounds?.Count > 0
&& v2rayCon.outbounds?.Count > 0
&& v2rayCon.routing != null)
{
var fileName = WriteAllText(objectString);
return lstResult; var profileIt = new ProfileItem
{
CoreType = ECoreType.Xray,
Address = fileName,
Remarks = v2rayCon.remarks ?? subRemarks ?? "v2ray_custom",
};
lstResult.Add(profileIt);
}
}
return lstResult;
}
return null;
} }
public static ProfileItem? ResolveFull(string strData, string? subRemarks) public static ProfileItem? ResolveFull(string strData, string? subRemarks)
{ {
var config = JsonUtils.ParseJson(strData); var v2rayConfig = JsonUtils.Deserialize<V2rayConfig>(strData);
if (config?["inbounds"] == null if (v2rayConfig?.inbounds?.Count > 0
|| config["outbounds"] == null && v2rayConfig.outbounds?.Count > 0
|| config["routing"] == null) && v2rayConfig.routing != null)
{ {
return null; var fileName = WriteAllText(strData);
var profileItem = new ProfileItem
{
CoreType = ECoreType.Xray,
Address = fileName,
Remarks = v2rayConfig.remarks ?? subRemarks ?? "v2ray_custom"
};
return profileItem;
} }
return null;
var fileName = WriteAllText(strData);
var profileItem = new ProfileItem
{
CoreType = ECoreType.Xray,
Address = fileName,
Remarks = config?["remarks"]?.ToString() ?? subRemarks ?? "v2ray_custom"
};
return profileItem;
} }
} }
} }

View file

@ -582,7 +582,7 @@ namespace ServiceLib.Services.CoreConfig
var it = JsonUtils.DeepCopy(rule); var it = JsonUtils.DeepCopy(rule);
it.ip = null; it.ip = null;
it.type = "field"; it.type = "field";
for (var k = it.domain.Count - 1; k >= 0; k--) for (int k = it.domain.Count - 1; k >= 0; k--)
{ {
if (it.domain[k].StartsWith("#")) if (it.domain[k].StartsWith("#"))
{ {

View file

@ -74,14 +74,6 @@ namespace ServiceLib.ViewModels
} }
private async Task CheckUpdate() private async Task CheckUpdate()
{
await Task.Run(async () =>
{
await CheckUpdateTask();
});
}
private async Task CheckUpdateTask()
{ {
_lstUpdated.Clear(); _lstUpdated.Clear();
_lstUpdated = _checkUpdateModel.Where(x => x.IsSelected == true) _lstUpdated = _checkUpdateModel.Where(x => x.IsSelected == true)

View file

@ -58,7 +58,7 @@ namespace ServiceLib.ViewModels
private async Task GetClashConnections() private async Task GetClashConnections()
{ {
var ret = await ClashApiHandler.Instance.GetClashConnectionsAsync(); var ret = await ClashApiHandler.Instance.GetClashConnectionsAsync(_config);
if (ret == null) if (ret == null)
{ {
return; return;

View file

@ -13,7 +13,7 @@ namespace ServiceLib.ViewModels
{ {
private Dictionary<string, ProxiesItem>? _proxies; private Dictionary<string, ProxiesItem>? _proxies;
private Dictionary<string, ProvidersItem>? _providers; private Dictionary<string, ProvidersItem>? _providers;
private readonly int _delayTimeout = 99999999; private int _delayTimeout = 99999999;
private IObservableCollection<ClashProxyModel> _proxyGroups = new ObservableCollectionExtended<ClashProxyModel>(); private IObservableCollection<ClashProxyModel> _proxyGroups = new ObservableCollectionExtended<ClashProxyModel>();
private IObservableCollection<ClashProxyModel> _proxyDetails = new ObservableCollectionExtended<ClashProxyModel>(); private IObservableCollection<ClashProxyModel> _proxyDetails = new ObservableCollectionExtended<ClashProxyModel>();
@ -28,8 +28,8 @@ namespace ServiceLib.ViewModels
public ClashProxyModel SelectedDetail { get; set; } public ClashProxyModel SelectedDetail { get; set; }
public ReactiveCommand<Unit, Unit> ProxiesReloadCmd { get; } public ReactiveCommand<Unit, Unit> ProxiesReloadCmd { get; }
public ReactiveCommand<Unit, Unit> ProxiesDelayTestCmd { get; } public ReactiveCommand<Unit, Unit> ProxiesDelaytestCmd { get; }
public ReactiveCommand<Unit, Unit> ProxiesDelayTestPartCmd { get; } public ReactiveCommand<Unit, Unit> ProxiesDelaytestPartCmd { get; }
public ReactiveCommand<Unit, Unit> ProxiesSelectActivityCmd { get; } public ReactiveCommand<Unit, Unit> ProxiesSelectActivityCmd { get; }
[Reactive] [Reactive]
@ -50,12 +50,12 @@ namespace ServiceLib.ViewModels
{ {
await ProxiesReload(); await ProxiesReload();
}); });
ProxiesDelayTestCmd = ReactiveCommand.CreateFromTask(async () => ProxiesDelaytestCmd = ReactiveCommand.CreateFromTask(async () =>
{ {
await ProxiesDelayTest(true); await ProxiesDelayTest(true);
}); });
ProxiesDelayTestPartCmd = ReactiveCommand.CreateFromTask(async () => ProxiesDelaytestPartCmd = ReactiveCommand.CreateFromTask(async () =>
{ {
await ProxiesDelayTest(false); await ProxiesDelayTest(false);
}); });
@ -78,7 +78,7 @@ namespace ServiceLib.ViewModels
this.WhenAnyValue( this.WhenAnyValue(
x => x.RuleModeSelected, x => x.RuleModeSelected,
y => y >= 0) y => y >= 0)
.Subscribe(async c => await DoRuleModeSelected(c)); .Subscribe(async c => await DoRulemodeSelected(c));
this.WhenAnyValue( this.WhenAnyValue(
x => x.SortingSelected, x => x.SortingSelected,
@ -98,7 +98,7 @@ namespace ServiceLib.ViewModels
_ = DelayTestTask(); _ = DelayTestTask();
} }
private async Task DoRuleModeSelected(bool c) private async Task DoRulemodeSelected(bool c)
{ {
if (!c) if (!c)
{ {
@ -158,7 +158,7 @@ namespace ServiceLib.ViewModels
private async Task GetClashProxies(bool refreshUI) private async Task GetClashProxies(bool refreshUI)
{ {
var ret = await ClashApiHandler.Instance.GetClashProxiesAsync(); var ret = await ClashApiHandler.Instance.GetClashProxiesAsync(_config);
if (ret?.Item1 == null || ret.Item2 == null) if (ret?.Item1 == null || ret.Item2 == null)
{ {
return; return;
@ -255,23 +255,29 @@ namespace ServiceLib.ViewModels
} }
_proxies.TryGetValue(name, out var proxy); _proxies.TryGetValue(name, out var proxy);
if (proxy?.all == null) if (proxy == null || proxy.all == null)
{ {
return; return;
} }
var lstDetails = new List<ClashProxyModel>(); var lstDetails = new List<ClashProxyModel>();
foreach (var item in proxy.all) foreach (var item in proxy.all)
{ {
var IsActive = item == proxy.now;
var proxy2 = TryGetProxy(item); var proxy2 = TryGetProxy(item);
if (proxy2 == null) if (proxy2 == null)
{ {
continue; continue;
} }
var delay = proxy2.history?.Count > 0 ? proxy2.history.Last().delay : -1; int delay = -1;
if (proxy2.history.Count > 0)
{
delay = proxy2.history[proxy2.history.Count - 1].delay;
}
lstDetails.Add(new ClashProxyModel() lstDetails.Add(new ClashProxyModel()
{ {
IsActive = item == proxy.now, IsActive = IsActive,
Name = item, Name = item,
Type = proxy2.type, Type = proxy2.type,
Delay = delay <= 0 ? _delayTimeout : delay, Delay = delay <= 0 ? _delayTimeout : delay,
@ -368,7 +374,12 @@ namespace ServiceLib.ViewModels
{ {
ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), async (item, result) => ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), async (item, result) =>
{ {
if (item == null || result.IsNullOrEmpty()) if (item == null)
{
await GetClashProxies(true);
return;
}
if (result.IsNullOrEmpty())
{ {
return; return;
} }
@ -382,28 +393,26 @@ namespace ServiceLib.ViewModels
{ {
//UpdateHandler(false, $"{item.name}={result}"); //UpdateHandler(false, $"{item.name}={result}");
var detail = _proxyDetails.FirstOrDefault(it => it.Name == result.IndexId); var detail = _proxyDetails.FirstOrDefault(it => it.Name == result.IndexId);
if (detail == null) if (detail != null)
{ {
return; var dicResult = JsonUtils.Deserialize<Dictionary<string, object>>(result.Delay);
if (dicResult != null && dicResult.TryGetValue("delay", out var value))
{
detail.Delay = Convert.ToInt32(value.ToString());
detail.DelayName = $"{detail.Delay}ms";
}
else if (dicResult != null && dicResult.TryGetValue("message", out var value1))
{
detail.Delay = _delayTimeout;
detail.DelayName = $"{value1}";
}
else
{
detail.Delay = _delayTimeout;
detail.DelayName = string.Empty;
}
_proxyDetails.Replace(detail, JsonUtils.DeepCopy(detail));
} }
var dicResult = JsonUtils.Deserialize<Dictionary<string, object>>(result.Delay);
if (dicResult != null && dicResult.TryGetValue("delay", out var value))
{
detail.Delay = Convert.ToInt32(value.ToString());
detail.DelayName = $"{detail.Delay}ms";
}
else if (dicResult != null && dicResult.TryGetValue("message", out var value1))
{
detail.Delay = _delayTimeout;
detail.DelayName = $"{value1}";
}
else
{
detail.Delay = _delayTimeout;
detail.DelayName = string.Empty;
}
_proxyDetails.Replace(detail, JsonUtils.DeepCopy(detail));
} }
#endregion proxy function #endregion proxy function

View file

@ -27,9 +27,9 @@ namespace v2rayN.Desktop.Views
this.Bind(ViewModel, vm => vm.SelectedDetail, v => v.lstProxyDetails.SelectedItem).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedDetail, v => v.lstProxyDetails.SelectedItem).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesReloadCmd, v => v.menuProxiesReload).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ProxiesReloadCmd, v => v.menuProxiesReload).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelayTestCmd, v => v.menuProxiesDelaytest).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ProxiesDelaytestCmd, v => v.menuProxiesDelaytest).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelayTestPartCmd, v => v.menuProxiesDelaytestPart).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ProxiesDelaytestPartCmd, v => v.menuProxiesDelaytestPart).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesSelectActivityCmd, v => v.menuProxiesSelectActivity).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ProxiesSelectActivityCmd, v => v.menuProxiesSelectActivity).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.RuleModeSelected, v => v.cmbRulemode.SelectedIndex).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.RuleModeSelected, v => v.cmbRulemode.SelectedIndex).DisposeWith(disposables);

View file

@ -28,9 +28,9 @@ namespace v2rayN.Views
this.Bind(ViewModel, vm => vm.SelectedDetail, v => v.lstProxyDetails.SelectedItem).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedDetail, v => v.lstProxyDetails.SelectedItem).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesReloadCmd, v => v.menuProxiesReload).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ProxiesReloadCmd, v => v.menuProxiesReload).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelayTestCmd, v => v.menuProxiesDelaytest).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ProxiesDelaytestCmd, v => v.menuProxiesDelaytest).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelayTestPartCmd, v => v.menuProxiesDelaytestPart).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ProxiesDelaytestPartCmd, v => v.menuProxiesDelaytestPart).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesSelectActivityCmd, v => v.menuProxiesSelectActivity).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ProxiesSelectActivityCmd, v => v.menuProxiesSelectActivity).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.RuleModeSelected, v => v.cmbRulemode.SelectedIndex).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.RuleModeSelected, v => v.cmbRulemode.SelectedIndex).DisposeWith(disposables);