Refactor code to decouple view and viewmodel

pull/5550/head
2dust 2024-08-10 14:44:25 +08:00
parent 8ff04dca0d
commit 2504b4737b
25 changed files with 180 additions and 94 deletions

View File

@ -8,7 +8,7 @@ namespace v2rayN.Base
public class MyReactiveObject : ReactiveObject
{
protected static Config? _config;
protected Func<EViewAction, bool>? _updateView;
protected Func<EViewAction, object?, bool>? _updateView;
protected NoticeHandler? _noticeHandler;
}
}

View File

@ -7,5 +7,17 @@
CloseWindow,
ShowYesNo,
AddBatchRoutingRulesYesNo,
SubEditWindow,
SubShare,
RoutingRuleSettingWindow,
RoutingRuleDetailsWindow,
AddServerWindow,
AddServer2Window,
ShareServer,
DNSSettingWindow,
RoutingSettingWindow,
OptionSettingWindow,
GlobalHotkeySettingWindow,
SubSettingWindow,
}
}

View File

@ -5,9 +5,9 @@ namespace v2rayN.Handler
{
public class NoticeHandler
{
private readonly ISnackbarMessageQueue _snackbarMessageQueue;
private readonly ISnackbarMessageQueue? _snackbarMessageQueue;
public NoticeHandler(ISnackbarMessageQueue snackbarMessageQueue)
public NoticeHandler(ISnackbarMessageQueue? snackbarMessageQueue)
{
_snackbarMessageQueue = snackbarMessageQueue ?? throw new ArgumentNullException(nameof(snackbarMessageQueue));
}

View File

@ -21,7 +21,7 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> SaveServerCmd { get; }
public bool IsModified { get; set; }
public AddServer2ViewModel(ProfileItem profileItem, Func<EViewAction, bool>? updateView)
public AddServer2ViewModel(ProfileItem profileItem, Func<EViewAction, object?, bool>? updateView)
{
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_config = LazyConfig.Instance.GetConfig();
@ -84,7 +84,7 @@ namespace v2rayN.ViewModels
if (ConfigHandler.EditCustomServer(_config, item) == 0)
{
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow);
_updateView?.Invoke(EViewAction.CloseWindow, null);
}
else
{

View File

@ -17,7 +17,7 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
public AddServerViewModel(ProfileItem profileItem, Func<EViewAction, bool>? updateView)
public AddServerViewModel(ProfileItem profileItem, Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@ -135,7 +135,7 @@ namespace v2rayN.ViewModels
if (ret == 0)
{
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow);
_updateView?.Invoke(EViewAction.CloseWindow, null);
}
else
{

View File

@ -26,7 +26,7 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> ImportDefConfig4V2rayCmd { get; }
public ReactiveCommand<Unit, Unit> ImportDefConfig4SingboxCmd { get; }
public DNSSettingViewModel(Func<EViewAction, bool>? updateView)
public DNSSettingViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@ -112,7 +112,7 @@ namespace v2rayN.ViewModels
ConfigHandler.SaveDNSItems(_config, item2);
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow);
_updateView?.Invoke(EViewAction.CloseWindow, null);
}
}
}

View File

@ -1,5 +1,4 @@
using DynamicData.Binding;
using MaterialDesignThemes.Wpf;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Splat;
@ -17,7 +16,6 @@ using v2rayN.Handler;
using v2rayN.Handler.Statistics;
using v2rayN.Models;
using v2rayN.Resx;
using v2rayN.Views;
namespace v2rayN.ViewModels
{
@ -170,14 +168,13 @@ namespace v2rayN.ViewModels
#region Init
public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, Func<EViewAction, bool>? updateView)
public MainWindowViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
_updateView = updateView;
ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false);
Locator.CurrentMutable.RegisterLazySingleton(() => _noticeHandler, typeof(NoticeHandler));
MessageBus.Current.Listen<string>(Global.CommandRefreshProfiles).Subscribe(x => RefreshServersBiz());
SelectedRouting = new();
@ -307,7 +304,7 @@ namespace v2rayN.ViewModels
});
GlobalHotkeySettingCmd = ReactiveCommand.Create(() =>
{
if ((new GlobalHotkeySettingWindow()).ShowDialog() == true)
if (_updateView?.Invoke(EViewAction.GlobalHotkeySettingWindow, null) == true)
{
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
}
@ -444,7 +441,7 @@ namespace v2rayN.ViewModels
}
if (_config.uiItem.enableAutoAdjustMainLvColWidth)
{
_updateView(EViewAction.AdjustMainLvColWidth);
_updateView?.Invoke(EViewAction.AdjustMainLvColWidth, null);
}
}
}
@ -610,11 +607,11 @@ namespace v2rayN.ViewModels
bool? ret = false;
if (eConfigType == EConfigType.Custom)
{
ret = (new AddServer2Window(item)).ShowDialog();
ret = _updateView?.Invoke(EViewAction.AddServer2Window, item);
}
else
{
ret = (new AddServerWindow(item)).ShowDialog();
ret = _updateView?.Invoke(EViewAction.AddServerWindow, item);
}
if (ret == true)
{
@ -734,7 +731,7 @@ namespace v2rayN.ViewModels
private void SubSetting()
{
if ((new SubSettingWindow()).ShowDialog() == true)
if (_updateView?.Invoke(EViewAction.SubSettingWindow, null) == true)
{
RefreshSubscriptions();
}
@ -751,7 +748,7 @@ namespace v2rayN.ViewModels
private void OptionSetting()
{
var ret = (new OptionSettingWindow()).ShowDialog();
var ret = _updateView?.Invoke(EViewAction.OptionSettingWindow, null);
if (ret == true)
{
//RefreshServers();
@ -761,7 +758,7 @@ namespace v2rayN.ViewModels
private void RoutingSetting()
{
var ret = (new RoutingSettingWindow()).ShowDialog();
var ret = _updateView?.Invoke(EViewAction.RoutingSettingWindow, null);
if (ret == true)
{
ConfigHandler.InitBuiltinRouting(_config);
@ -773,7 +770,7 @@ namespace v2rayN.ViewModels
private void DNSSetting()
{
var ret = (new DNSSettingWindow()).ShowDialog();
var ret = _updateView?.Invoke(EViewAction.DNSSettingWindow, null);
if (ret == true)
{
Reload();

View File

@ -105,7 +105,7 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
public OptionSettingViewModel(Func<EViewAction, bool>? updateView)
public OptionSettingViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@ -359,7 +359,7 @@ namespace v2rayN.ViewModels
{
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
}
_updateView?.Invoke(EViewAction.CloseWindow);
_updateView?.Invoke(EViewAction.CloseWindow, null);
}
else
{

View File

@ -1,6 +1,5 @@
using DynamicData;
using DynamicData.Binding;
using MaterialDesignThemes.Wpf;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Splat;
@ -15,7 +14,6 @@ using v2rayN.Handler.Fmt;
using v2rayN.Handler.Statistics;
using v2rayN.Models;
using v2rayN.Resx;
using v2rayN.Views;
namespace v2rayN.ViewModels
{
@ -102,7 +100,7 @@ namespace v2rayN.ViewModels
#region Init
public ProfilesViewModel(Func<EViewAction, bool>? updateView)
public ProfilesViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@ -327,7 +325,7 @@ namespace v2rayN.ViewModels
RefreshServers();
_updateView(EViewAction.ProfilesFocus);
_updateView?.Invoke(EViewAction.ProfilesFocus, null);
}
private void ServerFilterChanged(bool c)
@ -484,11 +482,11 @@ namespace v2rayN.ViewModels
bool? ret = false;
if (eConfigType == EConfigType.Custom)
{
ret = (new AddServer2Window(item)).ShowDialog();
ret = _updateView?.Invoke(EViewAction.AddServer2Window, item);
}
else
{
ret = (new AddServerWindow(item)).ShowDialog();
ret = _updateView?.Invoke(EViewAction.AddServerWindow, item);
}
if (ret == true)
{
@ -506,7 +504,7 @@ namespace v2rayN.ViewModels
{
return;
}
if (_updateView?.Invoke(EViewAction.ShowYesNo) == false)
if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false)
{
return;
}
@ -593,7 +591,7 @@ namespace v2rayN.ViewModels
SetDefaultServer(SelectedServer.ID);
}
public async void ShareServer()
public void ShareServer()
{
var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null)
@ -606,14 +604,8 @@ namespace v2rayN.ViewModels
{
return;
}
var img = QRCodeHelper.GetQRCode(url);
var dialog = new QrcodeView()
{
imgQrcode = { Source = img },
txtContent = { Text = url },
};
await DialogHost.Show(dialog, "RootDialog");
_updateView?.Invoke(EViewAction.ShareServer, url);
}
private void SetDefaultMultipleServer(ECoreType coreType)
@ -781,8 +773,7 @@ namespace v2rayN.ViewModels
return;
}
}
var ret = (new SubEditWindow(item)).ShowDialog();
if (ret == true)
if (_updateView?.Invoke(EViewAction.SubEditWindow, item) == true)
{
RefreshSubscriptions();
SubSelectedChanged(true);

View File

@ -32,7 +32,7 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func<EViewAction, bool>? updateView)
public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@ -93,7 +93,7 @@ namespace v2rayN.ViewModels
return;
}
//_noticeHandler?.Enqueue(ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow);
_updateView?.Invoke(EViewAction.CloseWindow, null);
}
}
}

View File

@ -8,7 +8,6 @@ using v2rayN.Enums;
using v2rayN.Handler;
using v2rayN.Models;
using v2rayN.Resx;
using v2rayN.Views;
using Application = System.Windows.Application;
namespace v2rayN.ViewModels
@ -41,7 +40,7 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
public RoutingRuleSettingViewModel(RoutingItem routingItem, Func<EViewAction, bool>? updateView)
public RoutingRuleSettingViewModel(RoutingItem routingItem, Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@ -151,8 +150,7 @@ namespace v2rayN.ViewModels
return;
}
}
var ret = (new RoutingRuleDetailsWindow(item)).ShowDialog();
if (ret == true)
if (_updateView?.Invoke(EViewAction.RoutingRuleDetailsWindow, item) == true)
{
if (blNew)
{
@ -169,7 +167,7 @@ namespace v2rayN.ViewModels
_noticeHandler?.Enqueue(ResUI.PleaseSelectRules);
return;
}
if (_updateView?.Invoke(EViewAction.ShowYesNo) == false)
if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false)
{
return;
}
@ -249,7 +247,7 @@ namespace v2rayN.ViewModels
if (ConfigHandler.SaveRoutingItem(_config, item) == 0)
{
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow);
_updateView?.Invoke(EViewAction.CloseWindow, null);
}
else
{
@ -318,7 +316,7 @@ namespace v2rayN.ViewModels
private int AddBatchRoutingRules(RoutingItem routingItem, string? clipboardData)
{
bool blReplace = false;
if (_updateView?.Invoke(EViewAction.AddBatchRoutingRulesYesNo) == false)
if (_updateView?.Invoke(EViewAction.AddBatchRoutingRulesYesNo, null) == false)
{
blReplace = true;
}

View File

@ -8,7 +8,6 @@ using v2rayN.Enums;
using v2rayN.Handler;
using v2rayN.Models;
using v2rayN.Resx;
using v2rayN.Views;
namespace v2rayN.ViewModels
{
@ -71,7 +70,7 @@ namespace v2rayN.ViewModels
#endregion Reactive
public RoutingSettingViewModel(Func<EViewAction, bool>? updateView)
public RoutingSettingViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@ -207,7 +206,7 @@ namespace v2rayN.ViewModels
if (ConfigHandler.SaveConfig(_config) == 0)
{
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow);
_updateView?.Invoke(EViewAction.CloseWindow, null);
}
else
{
@ -244,8 +243,7 @@ namespace v2rayN.ViewModels
return;
}
}
var ret = (new RoutingRuleSettingWindow(item)).ShowDialog();
if (ret == true)
if (_updateView?.Invoke(EViewAction.RoutingRuleSettingWindow, item) == true)
{
RefreshRoutingItems();
IsModified = true;
@ -259,7 +257,7 @@ namespace v2rayN.ViewModels
_noticeHandler?.Enqueue(ResUI.PleaseSelectRules);
return;
}
if (_updateView?.Invoke(EViewAction.ShowYesNo) == false)
if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false)
{
return;
}

View File

@ -17,7 +17,7 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
public SubEditViewModel(SubItem subItem, Func<EViewAction, bool>? updateView)
public SubEditViewModel(SubItem subItem, Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@ -70,7 +70,7 @@ namespace v2rayN.ViewModels
if (ConfigHandler.AddSubItem(_config, item) == 0)
{
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow);
_updateView?.Invoke(EViewAction.CloseWindow, null);
}
else
{

View File

@ -1,6 +1,5 @@
using DynamicData;
using DynamicData.Binding;
using MaterialDesignThemes.Wpf;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Splat;
@ -10,7 +9,6 @@ using v2rayN.Enums;
using v2rayN.Handler;
using v2rayN.Models;
using v2rayN.Resx;
using v2rayN.Views;
namespace v2rayN.ViewModels
{
@ -30,7 +28,7 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> SubShareCmd { get; }
public bool IsModified { get; set; }
public SubSettingViewModel(Func<EViewAction, bool>? updateView)
public SubSettingViewModel(Func<EViewAction, object?, bool>? updateView)
{
_config = LazyConfig.Instance.GetConfig();
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@ -58,7 +56,7 @@ namespace v2rayN.ViewModels
}, canEditRemove);
SubShareCmd = ReactiveCommand.Create(() =>
{
SubShare();
_updateView?.Invoke(EViewAction.SubShare, SelectedSource?.url);
}, canEditRemove);
}
@ -83,8 +81,7 @@ namespace v2rayN.ViewModels
return;
}
}
var ret = (new SubEditWindow(item)).ShowDialog();
if (ret == true)
if (_updateView?.Invoke(EViewAction.SubEditWindow, item) == true)
{
RefreshSubItems();
IsModified = true;
@ -93,7 +90,7 @@ namespace v2rayN.ViewModels
private void DeleteSub()
{
if (_updateView?.Invoke(EViewAction.ShowYesNo) == false)
if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false)
{
return;
}
@ -106,21 +103,5 @@ namespace v2rayN.ViewModels
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
IsModified = true;
}
private async void SubShare()
{
if (Utils.IsNullOrEmpty(SelectedSource?.url))
{
return;
}
var img = QRCodeHelper.GetQRCode(SelectedSource?.url);
var dialog = new QrcodeView()
{
imgQrcode = { Source = img },
txtContent = { Text = SelectedSource?.url },
};
await DialogHost.Show(dialog, "SubDialog");
}
}
}

View File

@ -42,7 +42,7 @@ namespace v2rayN.Views
Utils.SetDarkBorder(this, LazyConfig.Instance.GetConfig().uiItem.followSystemTheme ? !Utils.IsLightTheme() : LazyConfig.Instance.GetConfig().uiItem.colorModeDark);
}
private bool UpdateViewHandler(EViewAction action)
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.CloseWindow)
{

View File

@ -224,7 +224,7 @@ namespace v2rayN.Views
this.Title = $"{profileItem.configType}";
}
private bool UpdateViewHandler(EViewAction action)
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.CloseWindow)
{

View File

@ -56,7 +56,7 @@ namespace v2rayN.Views
});
}
private bool UpdateViewHandler(EViewAction action)
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.CloseWindow)
{

View File

@ -18,6 +18,7 @@ namespace v2rayN.Views
public partial class MainWindow
{
private static Config _config;
private NoticeHandler _noticeHandler;
public MainWindow()
{
@ -29,7 +30,10 @@ namespace v2rayN.Views
this.Closing += MainWindow_Closing;
this.PreviewKeyDown += MainWindow_PreviewKeyDown;
ViewModel = new MainWindowViewModel(MainSnackbar.MessageQueue, null);
_noticeHandler = new NoticeHandler(MainSnackbar.MessageQueue);
Locator.CurrentMutable.RegisterLazySingleton(() => _noticeHandler, typeof(NoticeHandler));
ViewModel = new MainWindowViewModel(UpdateViewHandler);
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));
this.WhenActivated(disposables =>
@ -178,6 +182,42 @@ namespace v2rayN.Views
AddHelpMenuItem();
}
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.AddServerWindow)
{
if (obj is null) return false;
return (new AddServerWindow((ProfileItem)obj)).ShowDialog() ?? false;
}
else if (action == EViewAction.AddServer2Window)
{
if (obj is null) return false;
return (new AddServer2Window((ProfileItem)obj)).ShowDialog() ?? false;
}
else if (action == EViewAction.DNSSettingWindow)
{
return (new DNSSettingWindow().ShowDialog() ?? false);
}
else if (action == EViewAction.RoutingSettingWindow)
{
return (new RoutingSettingWindow().ShowDialog() ?? false);
}
else if (action == EViewAction.OptionSettingWindow)
{
return (new OptionSettingWindow().ShowDialog() ?? false);
}
else if (action == EViewAction.GlobalHotkeySettingWindow)
{
return (new GlobalHotkeySettingWindow().ShowDialog() ?? false);
}
else if (action == EViewAction.SubSettingWindow)
{
return (new SubSettingWindow().ShowDialog() ?? false);
}
return true;
}
#region Event
private void MainWindow_Closing(object? sender, CancelEventArgs e)

View File

@ -171,7 +171,7 @@ namespace v2rayN.Views
});
}
private bool UpdateViewHandler(EViewAction action)
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.CloseWindow)
{

View File

@ -1,3 +1,4 @@
using MaterialDesignThemes.Wpf;
using ReactiveUI;
using Splat;
using System.Reactive.Disposables;
@ -97,7 +98,7 @@ namespace v2rayN.Views
StorageUI();
}
private bool UpdateViewHandler(EViewAction action)
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.AdjustMainLvColWidth)
{
@ -117,10 +118,42 @@ namespace v2rayN.Views
return false;
}
}
else if (action == EViewAction.AddServerWindow)
{
if (obj is null) return false;
return (new AddServerWindow((ProfileItem)obj)).ShowDialog() ?? false;
}
else if (action == EViewAction.AddServer2Window)
{
if (obj is null) return false;
return (new AddServer2Window((ProfileItem)obj)).ShowDialog() ?? false;
}
else if (action == EViewAction.ShareServer)
{
if (obj is null) return false;
ShareServer((string)obj);
}
else if (action == EViewAction.SubEditWindow)
{
if (obj is null) return false;
return (new SubEditWindow((SubItem)obj)).ShowDialog() ?? false;
}
return true;
}
public async void ShareServer(string url)
{
var img = QRCodeHelper.GetQRCode(url);
var dialog = new QrcodeView()
{
imgQrcode = { Source = img },
txtContent = { Text = url },
};
await DialogHost.Show(dialog, "RootDialog");
}
private void lstProfiles_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
ViewModel.SelectedProfiles = lstProfiles.SelectedItems.Cast<ProfileItemModel>().ToList();

View File

@ -62,7 +62,7 @@ namespace v2rayN.Views
});
}
private bool UpdateViewHandler(EViewAction action)
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.CloseWindow)
{

View File

@ -63,7 +63,7 @@ namespace v2rayN.Views
});
}
private bool UpdateViewHandler(EViewAction action)
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.CloseWindow)
{
@ -83,7 +83,11 @@ namespace v2rayN.Views
return false;
}
}
else if (action == EViewAction.RoutingRuleDetailsWindow)
{
if (obj is null) return false;
return (new RoutingRuleDetailsWindow((RulesItem)obj)).ShowDialog() ?? false;
}
return true;
}

View File

@ -70,7 +70,7 @@ namespace v2rayN.Views
});
}
private bool UpdateViewHandler(EViewAction action)
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.CloseWindow)
{
@ -83,6 +83,11 @@ namespace v2rayN.Views
return false;
}
}
else if (action == EViewAction.RoutingRuleSettingWindow)
{
if (obj is null) return false;
return (new RoutingRuleSettingWindow((RoutingItem)obj)).ShowDialog() ?? false;
}
return true;
}

View File

@ -41,7 +41,7 @@ namespace v2rayN.Views
});
}
private bool UpdateViewHandler(EViewAction action)
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.CloseWindow)
{

View File

@ -1,4 +1,5 @@
using ReactiveUI;
using MaterialDesignThemes.Wpf;
using ReactiveUI;
using System.ComponentModel;
using System.Reactive.Disposables;
using System.Windows;
@ -35,7 +36,7 @@ namespace v2rayN.Views
});
}
private bool UpdateViewHandler(EViewAction action)
private bool UpdateViewHandler(EViewAction action, object? obj)
{
if (action == EViewAction.CloseWindow)
{
@ -48,9 +49,35 @@ namespace v2rayN.Views
return false;
}
}
else if (action == EViewAction.SubEditWindow)
{
if (obj is null) return false;
return (new SubEditWindow((SubItem)obj)).ShowDialog() ?? false;
}
else if (action == EViewAction.SubShare)
{
if (obj is null) return false;
SubShare((string)obj);
}
return true;
}
private async void SubShare(string url)
{
if (Utils.IsNullOrEmpty(url))
{
return;
}
var img = QRCodeHelper.GetQRCode(url);
var dialog = new QrcodeView()
{
imgQrcode = { Source = img },
txtContent = { Text = url },
};
await DialogHost.Show(dialog, "SubDialog");
}
private void SubSettingWindow_Closing(object? sender, CancelEventArgs e)
{
if (ViewModel?.IsModified == true)