The first letter of the guiconfig attribute must be capitalized.

This commit is contained in:
2dust
2024-10-23 17:19:57 +08:00
parent 3c550c094a
commit ffb38129e2
27 changed files with 232 additions and 250 deletions
@@ -36,7 +36,7 @@ namespace ServiceLib.ViewModels
var canEditRemove = this.WhenAnyValue(
x => x.SelectedSource,
selectedSource => selectedSource != null && Utils.IsNotEmpty(selectedSource.id));
selectedSource => selectedSource != null && Utils.IsNotEmpty(selectedSource.Id));
this.WhenAnyValue(
x => x.SortingSelected,
@@ -125,18 +125,18 @@ namespace ServiceLib.ViewModels
ClashConnectionModel model = new();
model.id = item.id;
model.network = item.metadata.network;
model.type = item.metadata.type;
model.host = host;
model.Id = item.id;
model.Network = item.metadata.network;
model.Type = item.metadata.type;
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;
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;
lstModel.Add(model);
}
@@ -146,27 +146,27 @@ namespace ServiceLib.ViewModels
switch (SortingSelected)
{
case 0:
lstModel = lstModel.OrderBy(t => t.upload / t.time).ToList();
lstModel = lstModel.OrderBy(t => t.Upload / t.Time).ToList();
break;
case 1:
lstModel = lstModel.OrderBy(t => t.download / t.time).ToList();
lstModel = lstModel.OrderBy(t => t.Download / t.Time).ToList();
break;
case 2:
lstModel = lstModel.OrderBy(t => t.upload).ToList();
lstModel = lstModel.OrderBy(t => t.Upload).ToList();
break;
case 3:
lstModel = lstModel.OrderBy(t => t.download).ToList();
lstModel = lstModel.OrderBy(t => t.Download).ToList();
break;
case 4:
lstModel = lstModel.OrderBy(t => t.time).ToList();
lstModel = lstModel.OrderBy(t => t.Time).ToList();
break;
case 5:
lstModel = lstModel.OrderBy(t => t.host).ToList();
lstModel = lstModel.OrderBy(t => t.Host).ToList();
break;
}
@@ -183,7 +183,7 @@ namespace ServiceLib.ViewModels
{
return;
}
id = item.id;
id = item.Id;
}
else
{
@@ -72,7 +72,7 @@ namespace ServiceLib.ViewModels
this.WhenAnyValue(
x => x.SelectedGroup,
y => y != null && Utils.IsNotEmpty(y.name))
y => y != null && Utils.IsNotEmpty(y.Name))
.Subscribe(c => RefreshProxyDetails(c));
this.WhenAnyValue(
@@ -185,7 +185,7 @@ namespace ServiceLib.ViewModels
public void RefreshProxyGroups()
{
var selectedName = SelectedGroup?.name;
var selectedName = SelectedGroup?.Name;
_proxyGroups.Clear();
var proxyGroups = ClashApiHandler.Instance.GetClashProxyGroups();
@@ -204,9 +204,9 @@ namespace ServiceLib.ViewModels
}
_proxyGroups.Add(new ClashProxyModel()
{
now = item.now,
name = item.name,
type = item.type
Now = item.now,
Name = item.name,
Type = item.type
});
}
}
@@ -218,24 +218,24 @@ namespace ServiceLib.ViewModels
{
continue;
}
var item = _proxyGroups.Where(t => t.name == kv.Key).FirstOrDefault();
if (item != null && Utils.IsNotEmpty(item.name))
var item = _proxyGroups.Where(t => t.Name == kv.Key).FirstOrDefault();
if (item != null && Utils.IsNotEmpty(item.Name))
{
continue;
}
_proxyGroups.Add(new ClashProxyModel()
{
now = kv.Value.now,
name = kv.Key,
type = kv.Value.type
Now = kv.Value.now,
Name = kv.Key,
Type = kv.Value.type
});
}
if (_proxyGroups != null && _proxyGroups.Count > 0)
{
if (selectedName != null && _proxyGroups.Any(t => t.name == selectedName))
if (selectedName != null && _proxyGroups.Any(t => t.Name == selectedName))
{
SelectedGroup = _proxyGroups.FirstOrDefault(t => t.name == selectedName);
SelectedGroup = _proxyGroups.FirstOrDefault(t => t.Name == selectedName);
}
else
{
@@ -255,7 +255,7 @@ namespace ServiceLib.ViewModels
{
return;
}
var name = SelectedGroup?.name;
var name = SelectedGroup?.Name;
if (Utils.IsNullOrEmpty(name))
{
return;
@@ -289,21 +289,21 @@ namespace ServiceLib.ViewModels
lstDetails.Add(new ClashProxyModel()
{
IsActive = IsActive,
name = item,
type = proxy2.type,
delay = delay <= 0 ? _delayTimeout : delay,
delayName = delay <= 0 ? string.Empty : $"{delay}ms",
Name = item,
Type = proxy2.type,
Delay = delay <= 0 ? _delayTimeout : delay,
DelayName = delay <= 0 ? string.Empty : $"{delay}ms",
});
}
//sort
switch (SortingSelected)
{
case 0:
lstDetails = lstDetails.OrderBy(t => t.delay).ToList();
lstDetails = lstDetails.OrderBy(t => t.Delay).ToList();
break;
case 1:
lstDetails = lstDetails.OrderBy(t => t.name).ToList();
lstDetails = lstDetails.OrderBy(t => t.Name).ToList();
break;
default:
@@ -341,20 +341,20 @@ namespace ServiceLib.ViewModels
public async Task SetActiveProxy()
{
if (SelectedGroup == null || Utils.IsNullOrEmpty(SelectedGroup.name))
if (SelectedGroup == null || Utils.IsNullOrEmpty(SelectedGroup.Name))
{
return;
}
if (SelectedDetail == null || Utils.IsNullOrEmpty(SelectedDetail.name))
if (SelectedDetail == null || Utils.IsNullOrEmpty(SelectedDetail.Name))
{
return;
}
var name = SelectedGroup.name;
var name = SelectedGroup.Name;
if (Utils.IsNullOrEmpty(name))
{
return;
}
var nameNode = SelectedDetail.name;
var nameNode = SelectedDetail.Name;
if (Utils.IsNullOrEmpty(nameNode))
{
return;
@@ -369,10 +369,10 @@ namespace ServiceLib.ViewModels
await ClashApiHandler.Instance.ClashSetActiveProxy(name, nameNode);
selectedProxy.now = nameNode;
var group = _proxyGroups.Where(it => it.name == SelectedGroup.name).FirstOrDefault();
var group = _proxyGroups.Where(it => it.Name == SelectedGroup.Name).FirstOrDefault();
if (group != null)
{
group.now = nameNode;
group.Now = nameNode;
var group2 = JsonUtils.DeepCopy(group);
_proxyGroups.Replace(group, group2);
@@ -397,31 +397,31 @@ namespace ServiceLib.ViewModels
return;
}
_updateView?.Invoke(EViewAction.DispatcherProxiesDelayTest, new SpeedTestResult() { IndexId = item.name, Delay = result });
_updateView?.Invoke(EViewAction.DispatcherProxiesDelayTest, new SpeedTestResult() { IndexId = item.Name, Delay = result });
});
}
public void ProxiesDelayTestResult(SpeedTestResult result)
{
//UpdateHandler(false, $"{item.name}={result}");
var detail = _proxyDetails.Where(it => it.name == result.IndexId).FirstOrDefault();
var detail = _proxyDetails.Where(it => it.Name == result.IndexId).FirstOrDefault();
if (detail != null)
{
var dicResult = JsonUtils.Deserialize<Dictionary<string, object>>(result.Delay);
if (dicResult != null && dicResult.ContainsKey("delay"))
{
detail.delay = Convert.ToInt32(dicResult["delay"].ToString());
detail.delayName = $"{detail.delay}ms";
detail.Delay = Convert.ToInt32(dicResult["delay"].ToString());
detail.DelayName = $"{detail.Delay}ms";
}
else if (dicResult != null && dicResult.ContainsKey("message"))
{
detail.delay = _delayTimeout;
detail.delayName = $"{dicResult["message"]}";
detail.Delay = _delayTimeout;
detail.DelayName = $"{dicResult["message"]}";
}
else
{
detail.delay = _delayTimeout;
detail.delayName = string.Empty;
detail.Delay = _delayTimeout;
detail.DelayName = string.Empty;
}
_proxyDetails.Replace(detail, JsonUtils.DeepCopy(detail));
}
@@ -265,7 +265,7 @@ namespace ServiceLib.ViewModels
try
{
Locator.Current.GetService<StatusBarViewModel>()?.UpdateStatistics(update);
if ((update.proxyUp + update.proxyDown) > 0 && DateTime.Now.Second % 3 == 0)
if ((update.ProxyUp + update.ProxyDown) > 0 && DateTime.Now.Second % 3 == 0)
{
Locator.Current.GetService<ProfilesViewModel>()?.UpdateStatistics(update);
}
@@ -36,10 +36,10 @@ namespace ServiceLib.ViewModels
await SaveRulesAsync();
});
if (rulesItem.id.IsNullOrEmpty())
if (rulesItem.Id.IsNullOrEmpty())
{
rulesItem.id = Utils.GetGuid(false);
rulesItem.outboundTag = Global.ProxyTag;
rulesItem.Id = Utils.GetGuid(false);
rulesItem.OutboundTag = Global.ProxyTag;
rulesItem.Enabled = true;
SelectedSource = rulesItem;
}
@@ -48,9 +48,9 @@ namespace ServiceLib.ViewModels
SelectedSource = rulesItem;
}
Domain = Utils.List2String(SelectedSource.domain, true);
IP = Utils.List2String(SelectedSource.ip, true);
Process = Utils.List2String(SelectedSource.process, true);
Domain = Utils.List2String(SelectedSource.Domain, true);
IP = Utils.List2String(SelectedSource.Ip, true);
Process = Utils.List2String(SelectedSource.Process, true);
}
private async Task SaveRulesAsync()
@@ -61,24 +61,24 @@ namespace ServiceLib.ViewModels
if (AutoSort)
{
SelectedSource.domain = Utils.String2ListSorted(Domain);
SelectedSource.ip = Utils.String2ListSorted(IP);
SelectedSource.process = Utils.String2ListSorted(Process);
SelectedSource.Domain = Utils.String2ListSorted(Domain);
SelectedSource.Ip = Utils.String2ListSorted(IP);
SelectedSource.Process = Utils.String2ListSorted(Process);
}
else
{
SelectedSource.domain = Utils.String2List(Domain);
SelectedSource.ip = Utils.String2List(IP);
SelectedSource.process = Utils.String2List(Process);
SelectedSource.Domain = Utils.String2List(Domain);
SelectedSource.Ip = Utils.String2List(IP);
SelectedSource.Process = Utils.String2List(Process);
}
SelectedSource.protocol = ProtocolItems?.ToList();
SelectedSource.inboundTag = InboundTagItems?.ToList();
SelectedSource.Protocol = ProtocolItems?.ToList();
SelectedSource.InboundTag = InboundTagItems?.ToList();
bool hasRule = SelectedSource.domain?.Count > 0
|| SelectedSource.ip?.Count > 0
|| SelectedSource.protocol?.Count > 0
|| SelectedSource.process?.Count > 0
|| Utils.IsNotEmpty(SelectedSource.port);
bool hasRule = SelectedSource.Domain?.Count > 0
|| SelectedSource.Ip?.Count > 0
|| SelectedSource.Protocol?.Count > 0
|| SelectedSource.Process?.Count > 0
|| Utils.IsNotEmpty(SelectedSource.Port);
if (!hasRule)
{
@@ -40,7 +40,7 @@ namespace ServiceLib.ViewModels
var canEditRemove = this.WhenAnyValue(
x => x.SelectedSource,
selectedSource => selectedSource != null && !selectedSource.outboundTag.IsNullOrEmpty());
selectedSource => selectedSource != null && !selectedSource.OutboundTag.IsNullOrEmpty());
RuleAddCmd = ReactiveCommand.CreateFromTask(async () =>
{
@@ -105,14 +105,14 @@ namespace ServiceLib.ViewModels
{
var it = new RulesItemModel()
{
id = item.id,
outboundTag = item.outboundTag,
port = item.port,
network = item.network,
Protocols = Utils.List2String(item.protocol),
InboundTags = Utils.List2String(item.inboundTag),
Domains = Utils.List2String(item.domain),
Ips = Utils.List2String(item.ip),
Id = item.Id,
OutboundTag = item.OutboundTag,
Port = item.Port,
Network = item.Network,
Protocols = Utils.List2String(item.Protocol),
InboundTags = Utils.List2String(item.InboundTag),
Domains = Utils.List2String(item.Domain),
Ips = Utils.List2String(item.Ip),
Enabled = item.Enabled,
Remarks = item.Remarks,
};
@@ -129,7 +129,7 @@ namespace ServiceLib.ViewModels
}
else
{
item = _rules.FirstOrDefault(t => t.id == SelectedSource?.id);
item = _rules.FirstOrDefault(t => t.Id == SelectedSource?.Id);
if (item is null)
{
return;
@@ -147,7 +147,7 @@ namespace ServiceLib.ViewModels
public async Task RuleRemoveAsync()
{
if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty())
if (SelectedSource is null || SelectedSource.OutboundTag.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectRules);
return;
@@ -158,7 +158,7 @@ namespace ServiceLib.ViewModels
}
foreach (var it in SelectedSources ?? [SelectedSource])
{
var item = _rules.FirstOrDefault(t => t.id == it?.id);
var item = _rules.FirstOrDefault(t => t.Id == it?.Id);
if (item != null)
{
_rules.Remove(item);
@@ -170,7 +170,7 @@ namespace ServiceLib.ViewModels
public async Task RuleExportSelectedAsync()
{
if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty())
if (SelectedSource is null || SelectedSource.OutboundTag.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectRules);
return;
@@ -179,7 +179,7 @@ namespace ServiceLib.ViewModels
var lst = new List<RulesItem4Ray>();
foreach (var it in SelectedSources ?? [SelectedSource])
{
var item = _rules.FirstOrDefault(t => t.id == it?.id);
var item = _rules.FirstOrDefault(t => t.Id == it?.Id);
if (item != null)
{
var item2 = JsonUtils.Deserialize<RulesItem4Ray>(JsonUtils.Serialize(item));
@@ -194,13 +194,13 @@ namespace ServiceLib.ViewModels
public async Task MoveRule(EMove eMove)
{
if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty())
if (SelectedSource is null || SelectedSource.OutboundTag.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectRules);
return;
}
var item = _rules.FirstOrDefault(t => t.id == SelectedSource?.id);
var item = _rules.FirstOrDefault(t => t.Id == SelectedSource?.Id);
if (item == null)
{
return;
@@ -223,7 +223,7 @@ namespace ServiceLib.ViewModels
var item = SelectedRouting;
foreach (var it in _rules)
{
it.id = Utils.GetGuid(false);
it.Id = Utils.GetGuid(false);
}
item.RuleNum = _rules.Count;
item.RuleSet = JsonUtils.Serialize(_rules, false);
@@ -313,7 +313,7 @@ namespace ServiceLib.ViewModels
}
foreach (var rule in lstRules)
{
rule.id = Utils.GetGuid(false);
rule.Id = Utils.GetGuid(false);
}
if (blReplace)
@@ -140,14 +140,14 @@ namespace ServiceLib.ViewModels
if (_lockedItem != null)
{
_lockedRules = JsonUtils.Deserialize<List<RulesItem>>(_lockedItem.RuleSet);
ProxyDomain = Utils.List2String(_lockedRules[0].domain, true);
ProxyIP = Utils.List2String(_lockedRules[0].ip, true);
ProxyDomain = Utils.List2String(_lockedRules[0].Domain, true);
ProxyIP = Utils.List2String(_lockedRules[0].Ip, true);
DirectDomain = Utils.List2String(_lockedRules[1].domain, true);
DirectIP = Utils.List2String(_lockedRules[1].ip, true);
DirectDomain = Utils.List2String(_lockedRules[1].Domain, true);
DirectIP = Utils.List2String(_lockedRules[1].Ip, true);
BlockDomain = Utils.List2String(_lockedRules[2].domain, true);
BlockIP = Utils.List2String(_lockedRules[2].ip, true);
BlockDomain = Utils.List2String(_lockedRules[2].Domain, true);
BlockIP = Utils.List2String(_lockedRules[2].Ip, true);
}
}
@@ -155,14 +155,14 @@ namespace ServiceLib.ViewModels
{
if (_lockedItem != null)
{
_lockedRules[0].domain = Utils.String2List(Utils.Convert2Comma(ProxyDomain.TrimEx()));
_lockedRules[0].ip = Utils.String2List(Utils.Convert2Comma(ProxyIP.TrimEx()));
_lockedRules[0].Domain = Utils.String2List(Utils.Convert2Comma(ProxyDomain.TrimEx()));
_lockedRules[0].Ip = Utils.String2List(Utils.Convert2Comma(ProxyIP.TrimEx()));
_lockedRules[1].domain = Utils.String2List(Utils.Convert2Comma(DirectDomain.TrimEx()));
_lockedRules[1].ip = Utils.String2List(Utils.Convert2Comma(DirectIP.TrimEx()));
_lockedRules[1].Domain = Utils.String2List(Utils.Convert2Comma(DirectDomain.TrimEx()));
_lockedRules[1].Ip = Utils.String2List(Utils.Convert2Comma(DirectIP.TrimEx()));
_lockedRules[2].domain = Utils.String2List(Utils.Convert2Comma(BlockDomain.TrimEx()));
_lockedRules[2].ip = Utils.String2List(Utils.Convert2Comma(BlockIP.TrimEx()));
_lockedRules[2].Domain = Utils.String2List(Utils.Convert2Comma(BlockDomain.TrimEx()));
_lockedRules[2].Ip = Utils.String2List(Utils.Convert2Comma(BlockIP.TrimEx()));
_lockedItem.RuleSet = JsonUtils.Serialize(_lockedRules, false);
@@ -460,8 +460,8 @@ namespace ServiceLib.ViewModels
public void UpdateStatistics(ServerSpeedItem update)
{
SpeedProxyDisplay = string.Format(ResUI.SpeedDisplayText, Global.ProxyTag, Utils.HumanFy(update.proxyUp), Utils.HumanFy(update.proxyDown));
SpeedDirectDisplay = string.Format(ResUI.SpeedDisplayText, Global.DirectTag, Utils.HumanFy(update.directUp), Utils.HumanFy(update.directDown));
SpeedProxyDisplay = string.Format(ResUI.SpeedDisplayText, Global.ProxyTag, Utils.HumanFy(update.ProxyUp), Utils.HumanFy(update.ProxyDown));
SpeedDirectDisplay = string.Format(ResUI.SpeedDisplayText, Global.DirectTag, Utils.HumanFy(update.DirectUp), Utils.HumanFy(update.DirectDown));
}
#endregion UI