Improved ReactiveCommand.CreateFromTask

pull/5829/head
2dust 2024-10-10 18:02:09 +08:00
parent 4f5362fdc4
commit a556bf9487
14 changed files with 209 additions and 202 deletions

View File

@ -35,11 +35,11 @@ namespace ServiceLib.Models
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
{

View File

@ -32,19 +32,19 @@ namespace ServiceLib.ViewModels
}
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();
});
}
@ -100,7 +100,7 @@ namespace ServiceLib.ViewModels
}
}
private void EditServer()
private async Task EditServer()
{
var address = SelectedSource.address;
if (Utils.IsNullOrEmpty(address))

View File

@ -34,9 +34,9 @@ namespace ServiceLib.ViewModels
}
CoreType = SelectedSource?.coreType?.ToString();
SaveCmd = ReactiveCommand.Create(() =>
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
{
SaveServerAsync();
await SaveServerAsync();
});
}

View File

@ -49,14 +49,14 @@ namespace ServiceLib.ViewModels
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();
@ -177,7 +177,7 @@ namespace ServiceLib.ViewModels
_connectionItems.AddRange(lstModel);
}
public void ClashConnectionClose(bool all)
public async Task ClashConnectionClose(bool all)
{
var id = string.Empty;
if (!all)

View File

@ -73,22 +73,22 @@ namespace ServiceLib.ViewModels
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();
@ -136,13 +136,13 @@ namespace ServiceLib.ViewModels
NoticeHandler.Instance.SendMessageEx(msg);
}
public void ProxiesReload()
public async Task ProxiesReload()
{
GetClashProxies(true);
ProxiesDelayTest();
}
public void ProxiesDelayTest()
public async Task ProxiesDelayTest()
{
ProxiesDelayTest(true);
}
@ -338,7 +338,7 @@ namespace ServiceLib.ViewModels
return null;
}
public void SetActiveProxy()
public async Task SetActiveProxy()
{
if (SelectedGroup == null || Utils.IsNullOrEmpty(SelectedGroup.name))
{
@ -380,7 +380,7 @@ namespace ServiceLib.ViewModels
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
}
private void ProxiesDelayTest(bool blAll)
private async Task ProxiesDelayTest(bool blAll)
{
//UpdateHandler(false, "Clash Proxies Latency Test");

View File

@ -43,12 +43,12 @@ namespace ServiceLib.ViewModels
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);

View File

@ -191,49 +191,49 @@ namespace ServiceLib.ViewModels
.Subscribe(c => DoEnableTun(c));
//servers
AddVmessServerCmd = ReactiveCommand.Create(() =>
AddVmessServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerAsync(true, EConfigType.VMess);
await AddServerAsync(true, EConfigType.VMess);
});
AddVlessServerCmd = ReactiveCommand.Create(() =>
AddVlessServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerAsync(true, EConfigType.VLESS);
await AddServerAsync(true, EConfigType.VLESS);
});
AddShadowsocksServerCmd = ReactiveCommand.Create(() =>
AddShadowsocksServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerAsync(true, EConfigType.Shadowsocks);
await AddServerAsync(true, EConfigType.Shadowsocks);
});
AddSocksServerCmd = ReactiveCommand.Create(() =>
AddSocksServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerAsync(true, EConfigType.SOCKS);
await AddServerAsync(true, EConfigType.SOCKS);
});
AddHttpServerCmd = ReactiveCommand.Create(() =>
AddHttpServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerAsync(true, EConfigType.HTTP);
await AddServerAsync(true, EConfigType.HTTP);
});
AddTrojanServerCmd = ReactiveCommand.Create(() =>
AddTrojanServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerAsync(true, EConfigType.Trojan);
await AddServerAsync(true, EConfigType.Trojan);
});
AddHysteria2ServerCmd = ReactiveCommand.Create(() =>
AddHysteria2ServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerAsync(true, EConfigType.Hysteria2);
await AddServerAsync(true, EConfigType.Hysteria2);
});
AddTuicServerCmd = ReactiveCommand.Create(() =>
AddTuicServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerAsync(true, EConfigType.TUIC);
await AddServerAsync(true, EConfigType.TUIC);
});
AddWireguardServerCmd = ReactiveCommand.Create(() =>
AddWireguardServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerAsync(true, EConfigType.WireGuard);
await AddServerAsync(true, EConfigType.WireGuard);
});
AddCustomServerCmd = ReactiveCommand.Create(() =>
AddCustomServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerAsync(true, EConfigType.Custom);
await AddServerAsync(true, EConfigType.Custom);
});
AddServerViaClipboardCmd = ReactiveCommand.Create(() =>
AddServerViaClipboardCmd = ReactiveCommand.CreateFromTask(async () =>
{
AddServerViaClipboardAsync(null);
await AddServerViaClipboardAsync(null);
});
AddServerViaScanCmd = ReactiveCommand.CreateFromTask(async () =>
{
@ -241,40 +241,40 @@ namespace ServiceLib.ViewModels
});
//Subscription
SubSettingCmd = ReactiveCommand.Create(() =>
SubSettingCmd = ReactiveCommand.CreateFromTask(async () =>
{
SubSettingAsync();
await SubSettingAsync();
});
SubUpdateCmd = ReactiveCommand.Create(() =>
SubUpdateCmd = ReactiveCommand.CreateFromTask(async () =>
{
UpdateSubscriptionProcess("", false);
await UpdateSubscriptionProcess("", false);
});
SubUpdateViaProxyCmd = ReactiveCommand.Create(() =>
SubUpdateViaProxyCmd = ReactiveCommand.CreateFromTask(async () =>
{
UpdateSubscriptionProcess("", true);
await UpdateSubscriptionProcess("", true);
});
SubGroupUpdateCmd = ReactiveCommand.Create(() =>
SubGroupUpdateCmd = ReactiveCommand.CreateFromTask(async () =>
{
UpdateSubscriptionProcess(_config.subIndexId, false);
await UpdateSubscriptionProcess(_config.subIndexId, false);
});
SubGroupUpdateViaProxyCmd = ReactiveCommand.Create(() =>
SubGroupUpdateViaProxyCmd = ReactiveCommand.CreateFromTask(async () =>
{
UpdateSubscriptionProcess(_config.subIndexId, true);
await UpdateSubscriptionProcess(_config.subIndexId, true);
});
//Setting
OptionSettingCmd = ReactiveCommand.Create(() =>
OptionSettingCmd = ReactiveCommand.CreateFromTask(async () =>
{
OptionSettingAsync();
await OptionSettingAsync();
});
RoutingSettingCmd = ReactiveCommand.Create(() =>
RoutingSettingCmd = ReactiveCommand.CreateFromTask(async () =>
{
RoutingSettingAsync();
await RoutingSettingAsync();
});
DNSSettingCmd = ReactiveCommand.Create(() =>
DNSSettingCmd = ReactiveCommand.CreateFromTask(async () =>
{
DNSSettingAsync();
await DNSSettingAsync();
});
GlobalHotkeySettingCmd = ReactiveCommand.CreateFromTask(async () =>
{
@ -283,30 +283,22 @@ namespace ServiceLib.ViewModels
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
}
});
RebootAsAdminCmd = ReactiveCommand.Create(() =>
RebootAsAdminCmd = ReactiveCommand.CreateFromTask(async () =>
{
RebootAsAdmin();
await RebootAsAdmin();
});
ClearServerStatisticsCmd = ReactiveCommand.Create(() =>
ClearServerStatisticsCmd = ReactiveCommand.CreateFromTask(async () =>
{
StatisticsHandler.Instance.ClearAllServerStatistics();
RefreshServers();
await ClearServerStatistics();
});
OpenTheFileLocationCmd = ReactiveCommand.Create(() =>
OpenTheFileLocationCmd = ReactiveCommand.CreateFromTask(async () =>
{
if (Utils.IsWindows())
{
Utils.ProcessStart("Explorer", $"/select,{Utils.GetConfigPath()}");
}
else if (Utils.IsLinux())
{
Utils.ProcessStart("nautilus", Utils.GetConfigPath());
}
await OpenTheFileLocation();
});
ReloadCmd = ReactiveCommand.Create(() =>
ReloadCmd = ReactiveCommand.CreateFromTask(async () =>
{
Reload();
await Reload();
});
NotifyLeftClickCmd = ReactiveCommand.CreateFromTask(async () =>
@ -315,21 +307,21 @@ namespace ServiceLib.ViewModels
});
//System proxy
SystemProxyClearCmd = ReactiveCommand.Create(() =>
SystemProxyClearCmd = ReactiveCommand.CreateFromTask(async () =>
{
SetListenerType(ESysProxyType.ForcedClear);
await SetListenerType(ESysProxyType.ForcedClear);
});
SystemProxySetCmd = ReactiveCommand.Create(() =>
SystemProxySetCmd = ReactiveCommand.CreateFromTask(async () =>
{
SetListenerType(ESysProxyType.ForcedChange);
await SetListenerType(ESysProxyType.ForcedChange);
});
SystemProxyNothingCmd = ReactiveCommand.Create(() =>
SystemProxyNothingCmd = ReactiveCommand.CreateFromTask(async () =>
{
SetListenerType(ESysProxyType.Unchanged);
await SetListenerType(ESysProxyType.Unchanged);
});
SystemProxyPacCmd = ReactiveCommand.Create(() =>
SystemProxyPacCmd = ReactiveCommand.CreateFromTask(async () =>
{
SetListenerType(ESysProxyType.Pac);
await SetListenerType(ESysProxyType.Pac);
});
#endregion WhenAnyValue && ReactiveCommand
@ -651,7 +643,7 @@ namespace ServiceLib.ViewModels
}
}
public void UpdateSubscriptionProcess(string subId, bool blProxy)
public async Task UpdateSubscriptionProcess(string subId, bool blProxy)
{
(new UpdateService()).UpdateSubscriptionProcess(_config, subId, blProxy, UpdateTaskHandler);
}
@ -691,7 +683,7 @@ namespace ServiceLib.ViewModels
}
}
private void RebootAsAdmin()
private async Task RebootAsAdmin()
{
ProcessStartInfo startInfo = new()
{
@ -709,20 +701,35 @@ namespace ServiceLib.ViewModels
catch { }
}
private async Task ClearServerStatistics()
{
StatisticsHandler.Instance.ClearAllServerStatistics();
RefreshServers();
}
private async Task OpenTheFileLocation()
{
if (Utils.IsWindows())
{
Utils.ProcessStart("Explorer", $"/select,{Utils.GetConfigPath()}");
}
else if (Utils.IsLinux())
{
Utils.ProcessStart("nautilus", Utils.GetConfigPath());
}
}
#endregion Setting
#region core job
public void Reload()
public async Task Reload()
{
BlReloadEnabled = false;
LoadCore().ContinueWith(async task =>
{
await TestServerAvailability();
_updateView?.Invoke(EViewAction.DispatcherReload, null);
});
await LoadCore();
await TestServerAvailability();
_updateView?.Invoke(EViewAction.DispatcherReload, null);
}
public void ReloadResult()
@ -765,7 +772,7 @@ namespace ServiceLib.ViewModels
#region System proxy and Routings
public void SetListenerType(ESysProxyType type)
public async Task SetListenerType(ESysProxyType type)
{
if (_config.systemProxyItem.sysProxyType == type)
{

View File

@ -187,9 +187,9 @@ namespace ServiceLib.ViewModels
InitCoreType();
SaveCmd = ReactiveCommand.Create(() =>
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
{
SaveSettingAsync();
await SaveSettingAsync();
});
}

View File

@ -137,104 +137,104 @@ namespace ServiceLib.ViewModels
.Subscribe(c => ServerFilterChanged(c));
//servers delete
EditServerCmd = ReactiveCommand.Create(() =>
EditServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
EditServerAsync(EConfigType.Custom);
await EditServerAsync(EConfigType.Custom);
}, canEditRemove);
RemoveServerCmd = ReactiveCommand.Create(() =>
RemoveServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
RemoveServerAsync();
await RemoveServerAsync();
}, canEditRemove);
RemoveDuplicateServerCmd = ReactiveCommand.Create(() =>
RemoveDuplicateServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
RemoveDuplicateServer();
await RemoveDuplicateServer();
});
CopyServerCmd = ReactiveCommand.Create(() =>
CopyServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
CopyServer();
await CopyServer();
}, canEditRemove);
SetDefaultServerCmd = ReactiveCommand.Create(() =>
SetDefaultServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
SetDefaultServer();
await SetDefaultServer();
}, canEditRemove);
ShareServerCmd = ReactiveCommand.Create(() =>
ShareServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
ShareServerAsync();
await ShareServerAsync();
}, canEditRemove);
SetDefaultMultipleServerCmd = ReactiveCommand.Create(() =>
SetDefaultMultipleServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
SetDefaultMultipleServer(ECoreType.sing_box);
await SetDefaultMultipleServer(ECoreType.sing_box);
}, canEditRemove);
SetDefaultLoadBalanceServerCmd = ReactiveCommand.Create(() =>
SetDefaultLoadBalanceServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
SetDefaultMultipleServer(ECoreType.Xray);
await SetDefaultMultipleServer(ECoreType.Xray);
}, canEditRemove);
//servers move
MoveTopCmd = ReactiveCommand.Create(() =>
MoveTopCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveServer(EMove.Top);
await MoveServer(EMove.Top);
}, canEditRemove);
MoveUpCmd = ReactiveCommand.Create(() =>
MoveUpCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveServer(EMove.Up);
await MoveServer(EMove.Up);
}, canEditRemove);
MoveDownCmd = ReactiveCommand.Create(() =>
MoveDownCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveServer(EMove.Down);
await MoveServer(EMove.Down);
}, canEditRemove);
MoveBottomCmd = ReactiveCommand.Create(() =>
MoveBottomCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveServer(EMove.Bottom);
await MoveServer(EMove.Bottom);
}, canEditRemove);
//servers ping
MixedTestServerCmd = ReactiveCommand.Create(() =>
MixedTestServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
ServerSpeedtest(ESpeedActionType.Mixedtest);
await ServerSpeedtest(ESpeedActionType.Mixedtest);
});
TcpingServerCmd = ReactiveCommand.Create(() =>
TcpingServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
ServerSpeedtest(ESpeedActionType.Tcping);
await ServerSpeedtest(ESpeedActionType.Tcping);
}, canEditRemove);
RealPingServerCmd = ReactiveCommand.Create(() =>
RealPingServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
ServerSpeedtest(ESpeedActionType.Realping);
await ServerSpeedtest(ESpeedActionType.Realping);
}, canEditRemove);
SpeedServerCmd = ReactiveCommand.Create(() =>
SpeedServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
ServerSpeedtest(ESpeedActionType.Speedtest);
await ServerSpeedtest(ESpeedActionType.Speedtest);
}, canEditRemove);
SortServerResultCmd = ReactiveCommand.Create(() =>
SortServerResultCmd = ReactiveCommand.CreateFromTask(async () =>
{
SortServer(EServerColName.delayVal.ToString());
await SortServer(EServerColName.delayVal.ToString());
});
//servers export
Export2ClientConfigCmd = ReactiveCommand.Create(() =>
Export2ClientConfigCmd = ReactiveCommand.CreateFromTask(async () =>
{
Export2ClientConfigAsync(false);
await Export2ClientConfigAsync(false);
}, canEditRemove);
Export2ClientConfigClipboardCmd = ReactiveCommand.Create(() =>
Export2ClientConfigClipboardCmd = ReactiveCommand.CreateFromTask(async () =>
{
Export2ClientConfigAsync(true);
await Export2ClientConfigAsync(true);
}, canEditRemove);
Export2ShareUrlCmd = ReactiveCommand.Create(() =>
Export2ShareUrlCmd = ReactiveCommand.CreateFromTask(async () =>
{
Export2ShareUrlAsync(false);
await Export2ShareUrlAsync(false);
}, canEditRemove);
Export2ShareUrlBase64Cmd = ReactiveCommand.Create(() =>
Export2ShareUrlBase64Cmd = ReactiveCommand.CreateFromTask(async () =>
{
Export2ShareUrlAsync(true);
await Export2ShareUrlAsync(true);
}, canEditRemove);
//Subscription
AddSubCmd = ReactiveCommand.Create(() =>
AddSubCmd = ReactiveCommand.CreateFromTask(async () =>
{
EditSubAsync(true);
await EditSubAsync(true);
});
EditSubCmd = ReactiveCommand.Create(() =>
EditSubCmd = ReactiveCommand.CreateFromTask(async () =>
{
EditSubAsync(false);
await EditSubAsync(false);
});
#endregion WhenAnyValue && ReactiveCommand
@ -475,7 +475,7 @@ namespace ServiceLib.ViewModels
}
}
private void RemoveDuplicateServer()
private async Task RemoveDuplicateServer()
{
var tuple = ConfigHandler.DedupServerList(_config, _config.subIndexId);
RefreshServers();
@ -483,7 +483,7 @@ namespace ServiceLib.ViewModels
NoticeHandler.Instance.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, tuple.Item1, tuple.Item2));
}
private void CopyServer()
private async Task CopyServer()
{
if (GetProfileItems(out List<ProfileItem> lstSelecteds, false) < 0)
{
@ -496,7 +496,7 @@ namespace ServiceLib.ViewModels
}
}
public void SetDefaultServer()
public async Task SetDefaultServer()
{
if (Utils.IsNullOrEmpty(SelectedProfile?.indexId))
{
@ -505,7 +505,7 @@ namespace ServiceLib.ViewModels
SetDefaultServer(SelectedProfile.indexId);
}
private void SetDefaultServer(string indexId)
private async Task SetDefaultServer(string indexId)
{
if (Utils.IsNullOrEmpty(indexId))
{
@ -563,7 +563,7 @@ namespace ServiceLib.ViewModels
await _updateView?.Invoke(EViewAction.ShareServer, url);
}
private void SetDefaultMultipleServer(ECoreType coreType)
private async Task SetDefaultMultipleServer(ECoreType coreType)
{
if (GetProfileItems(out List<ProfileItem> lstSelecteds, true) < 0)
{
@ -586,7 +586,7 @@ namespace ServiceLib.ViewModels
}
}
public void SortServer(string colName)
public async Task SortServer(string colName)
{
if (Utils.IsNullOrEmpty(colName))
{
@ -624,7 +624,7 @@ namespace ServiceLib.ViewModels
//Reload();
}
public void MoveServer(EMove eMove)
public async Task MoveServer(EMove eMove)
{
var item = _lstProfile.FirstOrDefault(t => t.indexId == SelectedProfile.indexId);
if (item is null)
@ -656,7 +656,7 @@ namespace ServiceLib.ViewModels
}
}
public void ServerSpeedtest(ESpeedActionType actionType)
public async Task ServerSpeedtest(ESpeedActionType actionType)
{
if (actionType == ESpeedActionType.Mixedtest)
{

View File

@ -48,9 +48,9 @@ namespace ServiceLib.ViewModels
IP = Utils.List2String(SelectedSource.ip, true);
Process = Utils.List2String(SelectedSource.process, true);
SaveCmd = ReactiveCommand.Create(() =>
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
{
SaveRulesAsync();
await SaveRulesAsync();
});
}

View File

@ -57,52 +57,52 @@ namespace ServiceLib.ViewModels
x => x.SelectedSource,
selectedSource => selectedSource != null && !selectedSource.outboundTag.IsNullOrEmpty());
RuleAddCmd = ReactiveCommand.Create(() =>
RuleAddCmd = ReactiveCommand.CreateFromTask(async () =>
{
RuleEditAsync(true);
await RuleEditAsync(true);
});
ImportRulesFromFileCmd = ReactiveCommand.CreateFromTask(async () =>
{
await _updateView?.Invoke(EViewAction.ImportRulesFromFile, null);
});
ImportRulesFromClipboardCmd = ReactiveCommand.Create(() =>
ImportRulesFromClipboardCmd = ReactiveCommand.CreateFromTask(async () =>
{
ImportRulesFromClipboardAsync(null);
await ImportRulesFromClipboardAsync(null);
});
ImportRulesFromUrlCmd = ReactiveCommand.Create(() =>
ImportRulesFromUrlCmd = ReactiveCommand.CreateFromTask(async () =>
{
ImportRulesFromUrl();
await ImportRulesFromUrl();
});
RuleRemoveCmd = ReactiveCommand.Create(() =>
RuleRemoveCmd = ReactiveCommand.CreateFromTask(async () =>
{
RuleRemoveAsync();
await RuleRemoveAsync();
}, canEditRemove);
RuleExportSelectedCmd = ReactiveCommand.Create(() =>
RuleExportSelectedCmd = ReactiveCommand.CreateFromTask(async () =>
{
RuleExportSelectedAsync();
await RuleExportSelectedAsync();
}, canEditRemove);
MoveTopCmd = ReactiveCommand.Create(() =>
MoveTopCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveRule(EMove.Top);
await MoveRule(EMove.Top);
}, canEditRemove);
MoveUpCmd = ReactiveCommand.Create(() =>
MoveUpCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveRule(EMove.Up);
await MoveRule(EMove.Up);
}, canEditRemove);
MoveDownCmd = ReactiveCommand.Create(() =>
MoveDownCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveRule(EMove.Down);
await MoveRule(EMove.Down);
}, canEditRemove);
MoveBottomCmd = ReactiveCommand.Create(() =>
MoveBottomCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveRule(EMove.Bottom);
await MoveRule(EMove.Bottom);
}, canEditRemove);
SaveCmd = ReactiveCommand.Create(() =>
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
{
SaveRoutingAsync();
await SaveRoutingAsync();
});
}
@ -201,7 +201,7 @@ namespace ServiceLib.ViewModels
}
}
public void MoveRule(EMove eMove)
public async Task MoveRule(EMove eMove)
{
if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty())
{
@ -285,7 +285,7 @@ namespace ServiceLib.ViewModels
}
}
private async void ImportRulesFromUrl()
private async Task ImportRulesFromUrl()
{
var url = SelectedRouting.url;
if (Utils.IsNullOrEmpty(url))

View File

@ -90,31 +90,31 @@ namespace ServiceLib.ViewModels
x => x.enableRoutingAdvanced)
.Subscribe(c => enableRoutingBasic = !enableRoutingAdvanced);
RoutingBasicImportRulesCmd = ReactiveCommand.Create(() =>
RoutingBasicImportRulesCmd = ReactiveCommand.CreateFromTask(async () =>
{
RoutingBasicImportRules();
await RoutingBasicImportRules();
});
RoutingAdvancedAddCmd = ReactiveCommand.Create(() =>
RoutingAdvancedAddCmd = ReactiveCommand.CreateFromTask(async () =>
{
RoutingAdvancedEditAsync(true);
await RoutingAdvancedEditAsync(true);
});
RoutingAdvancedRemoveCmd = ReactiveCommand.Create(() =>
RoutingAdvancedRemoveCmd = ReactiveCommand.CreateFromTask(async () =>
{
RoutingAdvancedRemoveAsync();
await RoutingAdvancedRemoveAsync();
}, canEditRemove);
RoutingAdvancedSetDefaultCmd = ReactiveCommand.Create(() =>
RoutingAdvancedSetDefaultCmd = ReactiveCommand.CreateFromTask(async () =>
{
RoutingAdvancedSetDefault();
await RoutingAdvancedSetDefault();
}, canEditRemove);
RoutingAdvancedImportRulesCmd = ReactiveCommand.Create(() =>
RoutingAdvancedImportRulesCmd = ReactiveCommand.CreateFromTask(async () =>
{
RoutingAdvancedImportRules();
await RoutingAdvancedImportRules();
});
SaveCmd = ReactiveCommand.Create(() =>
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
{
SaveRoutingAsync();
await SaveRoutingAsync();
});
}
@ -210,7 +210,7 @@ namespace ServiceLib.ViewModels
#endregion Refresh Save
private void RoutingBasicImportRules()
private async Task RoutingBasicImportRules()
{
//Extra to bypass the mainland
ProxyDomain = "geosite:google";
@ -268,7 +268,7 @@ namespace ServiceLib.ViewModels
IsModified = true;
}
public void RoutingAdvancedSetDefault()
public async Task RoutingAdvancedSetDefault()
{
var item = AppHandler.Instance.GetRoutingItem(SelectedSource?.id);
if (item is null)
@ -284,7 +284,7 @@ namespace ServiceLib.ViewModels
}
}
private void RoutingAdvancedImportRules()
private async Task RoutingAdvancedImportRules()
{
if (ConfigHandler.InitBuiltinRouting(_config, true) == 0)
{

View File

@ -26,9 +26,9 @@ namespace ServiceLib.ViewModels
SelectedSource = JsonUtils.DeepCopy(subItem);
}
SaveCmd = ReactiveCommand.Create(() =>
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
{
SaveSubAsync();
await SaveSubAsync();
});
}

View File

@ -36,13 +36,13 @@ namespace ServiceLib.ViewModels
x => x.SelectedSource,
selectedSource => selectedSource != null && !selectedSource.id.IsNullOrEmpty());
SubAddCmd = ReactiveCommand.Create(() =>
SubAddCmd = ReactiveCommand.CreateFromTask(async () =>
{
EditSubAsync(true);
await EditSubAsync(true);
});
SubDeleteCmd = ReactiveCommand.Create(() =>
SubDeleteCmd = ReactiveCommand.CreateFromTask(async () =>
{
DeleteSubAsync();
await DeleteSubAsync();
}, canEditRemove);
SubEditCmd = ReactiveCommand.CreateFromTask(async () =>
{