mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-06 04:24:59 +03:00
Improve the clash connection
This commit is contained in:
@@ -21,9 +21,6 @@ namespace ServiceLib.ViewModels
|
||||
[Reactive]
|
||||
public string HostFilter { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public int SortingSelected { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public bool AutoRefresh { get; set; }
|
||||
|
||||
@@ -31,18 +28,12 @@ namespace ServiceLib.ViewModels
|
||||
{
|
||||
_config = AppHandler.Instance.Config;
|
||||
_updateView = updateView;
|
||||
SortingSelected = _config.ClashUIItem.ConnectionsSorting;
|
||||
AutoRefresh = _config.ClashUIItem.ConnectionsAutoRefresh;
|
||||
|
||||
var canEditRemove = this.WhenAnyValue(
|
||||
x => x.SelectedSource,
|
||||
selectedSource => selectedSource != null && Utils.IsNotEmpty(selectedSource.Id));
|
||||
|
||||
this.WhenAnyValue(
|
||||
x => x.SortingSelected,
|
||||
y => y >= 0)
|
||||
.Subscribe(async c => await DoSortingSelected(c));
|
||||
|
||||
this.WhenAnyValue(
|
||||
x => x.AutoRefresh,
|
||||
y => y == true)
|
||||
@@ -84,20 +75,6 @@ namespace ServiceLib.ViewModels
|
||||
});
|
||||
}
|
||||
|
||||
private async Task DoSortingSelected(bool c)
|
||||
{
|
||||
if (!c)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (SortingSelected != _config.ClashUIItem.ConnectionsSorting)
|
||||
{
|
||||
_config.ClashUIItem.ConnectionsSorting = SortingSelected;
|
||||
}
|
||||
|
||||
await GetClashConnections();
|
||||
}
|
||||
|
||||
private async Task GetClashConnections()
|
||||
{
|
||||
var ret = await ClashApiHandler.Instance.GetClashConnectionsAsync(_config);
|
||||
@@ -115,7 +92,7 @@ namespace ServiceLib.ViewModels
|
||||
|
||||
var dtNow = DateTime.Now;
|
||||
var lstModel = new List<ClashConnectionModel>();
|
||||
foreach (var item in connections ?? [])
|
||||
foreach (var item in connections ?? new())
|
||||
{
|
||||
var host = $"{(Utils.IsNullOrEmpty(item.metadata.host) ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}";
|
||||
if (HostFilter.IsNotEmpty() && !host.Contains(HostFilter))
|
||||
@@ -131,45 +108,14 @@ namespace ServiceLib.ViewModels
|
||||
model.Host = host;
|
||||
var sp = (dtNow - item.start);
|
||||
model.Time = sp.TotalSeconds < 0 ? 1 : sp.TotalSeconds;
|
||||
model.Upload = item.upload;
|
||||
model.Download = item.download;
|
||||
model.UploadTraffic = $"{Utils.HumanFy((long)item.upload)}";
|
||||
model.DownloadTraffic = $"{Utils.HumanFy((long)item.download)}";
|
||||
model.Elapsed = sp.ToString(@"hh\:mm\:ss");
|
||||
model.Chain = item.chains?.Count > 0 ? item.chains[0] : string.Empty;
|
||||
item.chains?.Reverse();
|
||||
model.Chain = $"{item.rule} , {string.Join("->", item.chains ?? new())}";
|
||||
|
||||
lstModel.Add(model);
|
||||
}
|
||||
if (lstModel.Count <= 0) { return; }
|
||||
|
||||
//sort
|
||||
switch (SortingSelected)
|
||||
{
|
||||
case 0:
|
||||
lstModel = lstModel.OrderBy(t => t.Upload / t.Time).ToList();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
lstModel = lstModel.OrderBy(t => t.Download / t.Time).ToList();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
lstModel = lstModel.OrderBy(t => t.Upload).ToList();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
lstModel = lstModel.OrderBy(t => t.Download).ToList();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
lstModel = lstModel.OrderBy(t => t.Time).ToList();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
lstModel = lstModel.OrderBy(t => t.Host).ToList();
|
||||
break;
|
||||
}
|
||||
|
||||
_connectionItems.AddRange(lstModel);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user