Skip to content

Commit

Permalink
Improved ReactiveCommand.CreateFromTask
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 10, 2024
1 parent 4f5362f commit a556bf9
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 202 deletions.
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Models/ProfileItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public string GetSummary()
string addr;
if (arrAddr.Length > 2)
{
addr = $"{arrAddr[0]}***{arrAddr[arrAddr.Length - 1]}";
addr = $"{arrAddr.First()}***{arrAddr.Last()}";
}
else if (arrAddr.Length > 1)
{
addr = $"***{arrAddr[arrAddr.Length - 1]}";
addr = $"***{arrAddr.Last()}";
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ public AddServer2ViewModel(ProfileItem profileItem, Func<EViewAction, object?, T
}
CoreType = SelectedSource?.coreType?.ToString();

BrowseServerCmd = ReactiveCommand.Create(() =>
BrowseServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
_updateView?.Invoke(EViewAction.BrowseServer, null);
});

EditServerCmd = ReactiveCommand.Create(() =>
EditServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
EditServer();
await EditServer();
});

SaveServerCmd = ReactiveCommand.Create(() =>
SaveServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
SaveServerAsync();
await SaveServerAsync();
});
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public void BrowseServer(string fileName)
}
}

private void EditServer()
private async Task EditServer()
{
var address = SelectedSource.address;
if (Utils.IsNullOrEmpty(address))
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public AddServerViewModel(ProfileItem profileItem, Func<EViewAction, object?, Ta
}
CoreType = SelectedSource?.coreType?.ToString();

SaveCmd = ReactiveCommand.Create(() =>
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
{
SaveServerAsync();
await SaveServerAsync();
});
}

Expand Down
10 changes: 5 additions & 5 deletions v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public ClashConnectionsViewModel(Func<EViewAction, object?, Task<bool>>? updateV
y => y == true)
.Subscribe(c => { _config.clashUIItem.connectionsAutoRefresh = AutoRefresh; });

ConnectionCloseCmd = ReactiveCommand.Create(() =>
ConnectionCloseCmd = ReactiveCommand.CreateFromTask(async () =>
{
ClashConnectionClose(false);
await ClashConnectionClose(false);
}, canEditRemove);

ConnectionCloseAllCmd = ReactiveCommand.Create(() =>
ConnectionCloseAllCmd = ReactiveCommand.CreateFromTask(async () =>
{
ClashConnectionClose(true);
await ClashConnectionClose(true);
});

Init();
Expand Down Expand Up @@ -177,7 +177,7 @@ public void RefreshConnections(List<ConnectionItem>? connections)
_connectionItems.AddRange(lstModel);
}

public void ClashConnectionClose(bool all)
public async Task ClashConnectionClose(bool all)
{
var id = string.Empty;
if (!all)
Expand Down
24 changes: 12 additions & 12 deletions v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ public ClashProxiesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
y => y == true)
.Subscribe(c => { _config.clashUIItem.proxiesAutoRefresh = AutoRefresh; });

ProxiesReloadCmd = ReactiveCommand.Create(() =>
ProxiesReloadCmd = ReactiveCommand.CreateFromTask(async () =>
{
ProxiesReload();
await ProxiesReload();
});
ProxiesDelaytestCmd = ReactiveCommand.Create(() =>
ProxiesDelaytestCmd = ReactiveCommand.CreateFromTask(async () =>
{
ProxiesDelayTest(true);
await ProxiesDelayTest(true);
});

ProxiesDelaytestPartCmd = ReactiveCommand.Create(() =>
ProxiesDelaytestPartCmd = ReactiveCommand.CreateFromTask(async () =>
{
ProxiesDelayTest(false);
await ProxiesDelayTest(false);
});
ProxiesSelectActivityCmd = ReactiveCommand.Create(() =>
ProxiesSelectActivityCmd = ReactiveCommand.CreateFromTask(async () =>
{
SetActiveProxy();
await SetActiveProxy();
});

ProxiesReload();
Expand Down Expand Up @@ -136,13 +136,13 @@ private void UpdateHandler(bool notify, string msg)
NoticeHandler.Instance.SendMessageEx(msg);
}

public void ProxiesReload()
public async Task ProxiesReload()
{
GetClashProxies(true);
ProxiesDelayTest();
}

public void ProxiesDelayTest()
public async Task ProxiesDelayTest()
{
ProxiesDelayTest(true);
}
Expand Down Expand Up @@ -338,7 +338,7 @@ private void RefreshProxyDetails(bool c)
return null;
}

public void SetActiveProxy()
public async Task SetActiveProxy()
{
if (SelectedGroup == null || Utils.IsNullOrEmpty(SelectedGroup.name))
{
Expand Down Expand Up @@ -380,7 +380,7 @@ public void SetActiveProxy()
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
}

private void ProxiesDelayTest(bool blAll)
private async Task ProxiesDelayTest(bool blAll)
{
//UpdateHandler(false, "Clash Proxies Latency Test");

Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public DNSSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
await SaveSettingAsync();
});

ImportDefConfig4V2rayCmd = ReactiveCommand.Create(() =>
ImportDefConfig4V2rayCmd = ReactiveCommand.CreateFromTask(async () =>
{
normalDNS = Utils.GetEmbedText(Global.DNSV2rayNormalFileName);
});

ImportDefConfig4SingboxCmd = ReactiveCommand.Create(() =>
ImportDefConfig4SingboxCmd = ReactiveCommand.CreateFromTask(async () =>
{
normalDNS2 = Utils.GetEmbedText(Global.DNSSingboxNormalFileName);
tunDNS2 = Utils.GetEmbedText(Global.TunSingboxDNSFileName);
Expand Down
Loading

0 comments on commit a556bf9

Please sign in to comment.