Refactor_updateView to add task

This commit is contained in:
2dust
2024-08-22 19:51:10 +08:00
parent b936c194e4
commit b57cdd31bd
27 changed files with 218 additions and 216 deletions
@@ -15,7 +15,7 @@ namespace ServiceLib.ViewModels
public ReactiveCommand<Unit, Unit> SaveServerCmd { get; }
public bool IsModified { get; set; }
public AddServer2ViewModel(ProfileItem profileItem, Func<EViewAction, object?, bool>? updateView)
public AddServer2ViewModel(ProfileItem profileItem, Func<EViewAction, object?, Task<bool>>? updateView)
{
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_config = LazyConfig.Instance.Config;
@@ -30,9 +30,9 @@ namespace ServiceLib.ViewModels
SelectedSource = JsonUtils.DeepCopy(profileItem);
}
BrowseServerCmd = ReactiveCommand.Create(() =>
BrowseServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
_updateView?.Invoke(EViewAction.BrowseServer, null);
await _updateView?.Invoke(EViewAction.BrowseServer, null);
});
EditServerCmd = ReactiveCommand.Create(() =>
@@ -42,11 +42,11 @@ namespace ServiceLib.ViewModels
SaveServerCmd = ReactiveCommand.Create(() =>
{
SaveServer();
SaveServerAsync();
});
}
private void SaveServer()
private async Task SaveServerAsync()
{
string remarks = SelectedSource.remarks;
if (Utils.IsNullOrEmpty(remarks))
@@ -64,7 +64,7 @@ namespace ServiceLib.ViewModels
if (ConfigHandler.EditCustomServer(_config, SelectedSource) == 0)
{
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow, null);
await _updateView?.Invoke(EViewAction.CloseWindow, null);
}
else
{