mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-23 05:35:00 +03:00
ViewModel-First (#9621)
* Interaction * Remove view action * ViewModel-first * MainGirdOrientation Hot Reload * Fix avalonia preview * Remove CloseWindowInteraction * Fix * Avoid threading issues * Fix * ProfilesSelect * Try fix previewer * Remove AppEvents.ProfilesRefreshRequested * Remove AppEvents.SubscriptionsRefreshRequested * Remove AppEvents.ProxiesReloadRequested * Remove AppEvents.AdjustMainLvColWidthRequested * Remove AppEvents.SetDefaultServerRequested * Remove AppEvents.RoutingsMenuRefreshRequested * Remove AppEvents.TestServerRequested * Remove AppEvents.InboundDisplayRequested * Remove AppEvents.SubscriptionsUpdateRequested * Remove AppEvents.ShowHideWindowRequested * Remove AppEvents.ReloadRequested * Remove AppEvents.AddServerRequested * Fix
This commit is contained in:
@@ -1,17 +1,38 @@
|
||||
namespace ServiceLib.ViewModels;
|
||||
|
||||
public class SubEditViewModel : MyReactiveObject
|
||||
public class SubEditViewModel : MyReactiveObject, ICloseable
|
||||
{
|
||||
public event EventHandler? RequestClose;
|
||||
|
||||
[Reactive]
|
||||
public SubItem SelectedSource { get; set; }
|
||||
|
||||
public ReactiveCommand<Unit, Unit> SelectPrevProfileCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> SelectNextProfileCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
|
||||
|
||||
public SubEditViewModel(SubItem subItem, Func<EViewAction, object?, Task<bool>>? updateView)
|
||||
public SubEditViewModel(SubItem subItem)
|
||||
{
|
||||
_config = AppManager.Instance.Config;
|
||||
_updateView = updateView;
|
||||
|
||||
SelectPrevProfileCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
var profileItem = await SelectProfileAsync();
|
||||
if (profileItem != null)
|
||||
{
|
||||
SelectedSource?.PrevProfile = profileItem.Remarks;
|
||||
SelectedSource = JsonUtils.DeepCopy(SelectedSource);
|
||||
}
|
||||
});
|
||||
SelectNextProfileCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
var profileItem = await SelectProfileAsync();
|
||||
if (profileItem != null)
|
||||
{
|
||||
SelectedSource?.NextProfile = profileItem.Remarks;
|
||||
SelectedSource = JsonUtils.DeepCopy(SelectedSource);
|
||||
}
|
||||
});
|
||||
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
await SaveSubAsync();
|
||||
@@ -49,11 +70,24 @@ public class SubEditViewModel : MyReactiveObject
|
||||
if (await ConfigHandler.AddSubItem(_config, SelectedSource) == 0)
|
||||
{
|
||||
NoticeManager.Instance.Enqueue(ResUI.OperationSuccess);
|
||||
_updateView?.Invoke(EViewAction.CloseWindow, null);
|
||||
RequestClose?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
NoticeManager.Instance.Enqueue(ResUI.OperationFailed);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<ProfileItem?> SelectProfileAsync()
|
||||
{
|
||||
var profileSelectViewModel = new ProfilesSelectViewModel();
|
||||
profileSelectViewModel.SetConfigTypeFilter([EConfigType.Custom], exclude: true);
|
||||
var result = await AppManager.Instance.WindowDialog.ShowDialogAsync(profileSelectViewModel);
|
||||
if (result != true)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var profileItem = await profileSelectViewModel.GetProfileItem();
|
||||
return profileItem;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user