AI-optimized code

This commit is contained in:
2dust 2025-03-06 14:34:31 +08:00
parent 3869148fc8
commit 50d7912f62
4 changed files with 19 additions and 19 deletions

View file

@ -42,7 +42,7 @@ namespace ServiceLib.ViewModels
private async Task SaveServerAsync() private async Task SaveServerAsync()
{ {
string remarks = SelectedSource.Remarks; var remarks = SelectedSource.Remarks;
if (remarks.IsNullOrEmpty()) if (remarks.IsNullOrEmpty())
{ {
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks); NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);

View file

@ -72,8 +72,7 @@ namespace ServiceLib.ViewModels
return; return;
} }
} }
if (SelectedSource.ConfigType != EConfigType.SOCKS if (SelectedSource.ConfigType is not EConfigType.SOCKS and not EConfigType.HTTP)
&& SelectedSource.ConfigType != EConfigType.HTTP)
{ {
if (SelectedSource.Id.IsNullOrEmpty()) if (SelectedSource.Id.IsNullOrEmpty())
{ {

View file

@ -50,7 +50,7 @@ namespace ServiceLib.ViewModels
{ {
DisplayOperationMsg(); DisplayOperationMsg();
_config.WebDavItem = SelectedSource; _config.WebDavItem = SelectedSource;
await ConfigHandler.SaveConfig(_config); _ = await ConfigHandler.SaveConfig(_config);
var result = await WebDavHandler.Instance.CheckConnection(); var result = await WebDavHandler.Instance.CheckConnection();
if (result) if (result)
@ -151,7 +151,7 @@ namespace ServiceLib.ViewModels
{ {
if (Utils.UpgradeAppExists(out var upgradeFileName)) if (Utils.UpgradeAppExists(out var upgradeFileName))
{ {
ProcUtils.ProcessStart(upgradeFileName, Global.RebootAs, Utils.StartupPath()); _ = ProcUtils.ProcessStart(upgradeFileName, Global.RebootAs, Utils.StartupPath());
} }
} }
service?.Shutdown(true); service?.Shutdown(true);

View file

@ -53,7 +53,7 @@ namespace ServiceLib.ViewModels
private async Task Init() private async Task Init()
{ {
Task.Run(async () => _ = Task.Run(async () =>
{ {
var numOfExecuted = 1; var numOfExecuted = 1;
while (true) while (true)
@ -89,7 +89,7 @@ namespace ServiceLib.ViewModels
return; return;
} }
_updateView?.Invoke(EViewAction.DispatcherRefreshConnections, ret?.connections); _ = _updateView?.Invoke(EViewAction.DispatcherRefreshConnections, ret?.connections);
} }
public void RefreshConnections(List<ConnectionItem>? connections) public void RefreshConnections(List<ConnectionItem>? connections)
@ -106,22 +106,23 @@ namespace ServiceLib.ViewModels
continue; continue;
} }
ClashConnectionModel model = new(); var model = new ClashConnectionModel
{
model.Id = item.id; Id = item.id,
model.Network = item.metadata.network; Network = item.metadata.network,
model.Type = item.metadata.type; Type = item.metadata.type,
model.Host = host; Host = host,
var sp = (dtNow - item.start); Time = (dtNow - item.start).TotalSeconds < 0 ? 1 : (dtNow - item.start).TotalSeconds,
model.Time = sp.TotalSeconds < 0 ? 1 : sp.TotalSeconds; Elapsed = (dtNow - item.start).ToString(@"hh\:mm\:ss"),
model.Elapsed = sp.ToString(@"hh\:mm\:ss"); Chain = $"{item.rule} , {string.Join("->", item.chains ?? new())}"
item.chains?.Reverse(); };
model.Chain = $"{item.rule} , {string.Join("->", item.chains ?? new())}";
lstModel.Add(model); lstModel.Add(model);
} }
if (lstModel.Count <= 0) if (lstModel.Count <= 0)
{ return; } {
return;
}
_connectionItems.AddRange(lstModel); _connectionItems.AddRange(lstModel);
} }