diff --git a/v2rayN/v2rayN/Base/MyReactiveObject.cs b/v2rayN/v2rayN/Base/MyReactiveObject.cs index 0cd30b1c69..8464e1ee14 100644 --- a/v2rayN/v2rayN/Base/MyReactiveObject.cs +++ b/v2rayN/v2rayN/Base/MyReactiveObject.cs @@ -8,7 +8,7 @@ namespace v2rayN.Base public class MyReactiveObject : ReactiveObject { protected static Config? _config; - protected Func? _updateView; + protected Func? _updateView; protected NoticeHandler? _noticeHandler; } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Enums/EViewAction.cs b/v2rayN/v2rayN/Enums/EViewAction.cs index d7c3935821..d52fdbf0d8 100644 --- a/v2rayN/v2rayN/Enums/EViewAction.cs +++ b/v2rayN/v2rayN/Enums/EViewAction.cs @@ -7,5 +7,17 @@ public enum EViewAction CloseWindow, ShowYesNo, AddBatchRoutingRulesYesNo, + SubEditWindow, + SubShare, + RoutingRuleSettingWindow, + RoutingRuleDetailsWindow, + AddServerWindow, + AddServer2Window, + ShareServer, + DNSSettingWindow, + RoutingSettingWindow, + OptionSettingWindow, + GlobalHotkeySettingWindow, + SubSettingWindow, } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Handler/NoticeHandler.cs b/v2rayN/v2rayN/Handler/NoticeHandler.cs index 35fa8fa637..900756d5fa 100644 --- a/v2rayN/v2rayN/Handler/NoticeHandler.cs +++ b/v2rayN/v2rayN/Handler/NoticeHandler.cs @@ -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)); } diff --git a/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs b/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs index 9a5c1ba3a9..061cca797a 100644 --- a/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs @@ -21,7 +21,7 @@ public class AddServer2ViewModel : MyReactiveObject public ReactiveCommand SaveServerCmd { get; } public bool IsModified { get; set; } - public AddServer2ViewModel(ProfileItem profileItem, Func? updateView) + public AddServer2ViewModel(ProfileItem profileItem, Func? updateView) { _noticeHandler = Locator.Current.GetService(); _config = LazyConfig.Instance.GetConfig(); @@ -84,7 +84,7 @@ private void SaveServer() if (ConfigHandler.EditCustomServer(_config, item) == 0) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow); + _updateView?.Invoke(EViewAction.CloseWindow, null); } else { diff --git a/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs b/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs index e2170b7351..9987f0980c 100644 --- a/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs @@ -17,7 +17,7 @@ public class AddServerViewModel : MyReactiveObject public ReactiveCommand SaveCmd { get; } - public AddServerViewModel(ProfileItem profileItem, Func? updateView) + public AddServerViewModel(ProfileItem profileItem, Func? updateView) { _config = LazyConfig.Instance.GetConfig(); _noticeHandler = Locator.Current.GetService(); @@ -135,7 +135,7 @@ private void SaveServer() if (ret == 0) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow); + _updateView?.Invoke(EViewAction.CloseWindow, null); } else { diff --git a/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs index 4fef5f06eb..48351d2309 100644 --- a/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs @@ -26,7 +26,7 @@ public class DNSSettingViewModel : MyReactiveObject public ReactiveCommand ImportDefConfig4V2rayCmd { get; } public ReactiveCommand ImportDefConfig4SingboxCmd { get; } - public DNSSettingViewModel(Func? updateView) + public DNSSettingViewModel(Func? updateView) { _config = LazyConfig.Instance.GetConfig(); _noticeHandler = Locator.Current.GetService(); @@ -112,7 +112,7 @@ private void SaveSetting() ConfigHandler.SaveDNSItems(_config, item2); _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow); + _updateView?.Invoke(EViewAction.CloseWindow, null); } } } \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index 7cf7b708f0..76b99e4322 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -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.Statistics; using v2rayN.Models; using v2rayN.Resx; -using v2rayN.Views; namespace v2rayN.ViewModels { @@ -170,14 +168,13 @@ public class MainWindowViewModel : MyReactiveObject #region Init - public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, Func? updateView) + public MainWindowViewModel(Func? updateView) { _config = LazyConfig.Instance.GetConfig(); _noticeHandler = Locator.Current.GetService(); _updateView = updateView; - + ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); - Locator.CurrentMutable.RegisterLazySingleton(() => _noticeHandler, typeof(NoticeHandler)); MessageBus.Current.Listen(Global.CommandRefreshProfiles).Subscribe(x => RefreshServersBiz()); SelectedRouting = new(); @@ -307,7 +304,7 @@ public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, Func { - if ((new GlobalHotkeySettingWindow()).ShowDialog() == true) + if (_updateView?.Invoke(EViewAction.GlobalHotkeySettingWindow, null) == true) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); } @@ -444,7 +441,7 @@ private void UpdateTaskHandler(bool success, string msg) } if (_config.uiItem.enableAutoAdjustMainLvColWidth) { - _updateView(EViewAction.AdjustMainLvColWidth); + _updateView?.Invoke(EViewAction.AdjustMainLvColWidth, null); } } } @@ -610,11 +607,11 @@ public void AddServer(bool blNew, EConfigType eConfigType) 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 @@ public void TestServerAvailability() private void SubSetting() { - if ((new SubSettingWindow()).ShowDialog() == true) + if (_updateView?.Invoke(EViewAction.SubSettingWindow, null) == true) { RefreshSubscriptions(); } @@ -751,7 +748,7 @@ private void UpdateSubscriptionProcess(string subId, bool blProxy) private void OptionSetting() { - var ret = (new OptionSettingWindow()).ShowDialog(); + var ret = _updateView?.Invoke(EViewAction.OptionSettingWindow, null); if (ret == true) { //RefreshServers(); @@ -761,7 +758,7 @@ private void OptionSetting() 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 @@ private void RoutingSetting() private void DNSSetting() { - var ret = (new DNSSettingWindow()).ShowDialog(); + var ret = _updateView?.Invoke(EViewAction.DNSSettingWindow, null); if (ret == true) { Reload(); diff --git a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs index 67331a0c85..d9e6591ebe 100644 --- a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs @@ -105,7 +105,7 @@ public class OptionSettingViewModel : MyReactiveObject public ReactiveCommand SaveCmd { get; } - public OptionSettingViewModel(Func? updateView) + public OptionSettingViewModel(Func? updateView) { _config = LazyConfig.Instance.GetConfig(); _noticeHandler = Locator.Current.GetService(); @@ -359,7 +359,7 @@ private void SaveSetting() { _noticeHandler?.Enqueue(ResUI.OperationSuccess); } - _updateView?.Invoke(EViewAction.CloseWindow); + _updateView?.Invoke(EViewAction.CloseWindow, null); } else { diff --git a/v2rayN/v2rayN/ViewModels/ProfilesViewModel.cs b/v2rayN/v2rayN/ViewModels/ProfilesViewModel.cs index 90232e9a05..3e4db0e906 100644 --- a/v2rayN/v2rayN/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/ProfilesViewModel.cs @@ -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.Statistics; using v2rayN.Models; using v2rayN.Resx; -using v2rayN.Views; namespace v2rayN.ViewModels { @@ -102,7 +100,7 @@ public class ProfilesViewModel : MyReactiveObject #region Init - public ProfilesViewModel(Func? updateView) + public ProfilesViewModel(Func? updateView) { _config = LazyConfig.Instance.GetConfig(); _noticeHandler = Locator.Current.GetService(); @@ -327,7 +325,7 @@ private void SubSelectedChanged(bool c) RefreshServers(); - _updateView(EViewAction.ProfilesFocus); + _updateView?.Invoke(EViewAction.ProfilesFocus, null); } private void ServerFilterChanged(bool c) @@ -484,11 +482,11 @@ public void EditServer(bool blNew, EConfigType eConfigType) 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 @@ public void RemoveServer() { return; } - if (_updateView?.Invoke(EViewAction.ShowYesNo) == false) + if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false) { return; } @@ -593,7 +591,7 @@ private void ServerSelectedChanged(bool c) 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 @@ public async void ShareServer() { 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 @@ private void EditSub(bool blNew) return; } } - var ret = (new SubEditWindow(item)).ShowDialog(); - if (ret == true) + if (_updateView?.Invoke(EViewAction.SubEditWindow, item) == true) { RefreshSubscriptions(); SubSelectedChanged(true); diff --git a/v2rayN/v2rayN/ViewModels/RoutingRuleDetailsViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingRuleDetailsViewModel.cs index 469f183796..8a0491141b 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingRuleDetailsViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingRuleDetailsViewModel.cs @@ -32,7 +32,7 @@ public class RoutingRuleDetailsViewModel : MyReactiveObject public ReactiveCommand SaveCmd { get; } - public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func? updateView) + public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func? updateView) { _config = LazyConfig.Instance.GetConfig(); _noticeHandler = Locator.Current.GetService(); @@ -93,7 +93,7 @@ private void SaveRules() return; } //_noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow); + _updateView?.Invoke(EViewAction.CloseWindow, null); } } } \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs index 17a7243303..caba06a351 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs @@ -8,7 +8,6 @@ using v2rayN.Handler; using v2rayN.Models; using v2rayN.Resx; -using v2rayN.Views; using Application = System.Windows.Application; namespace v2rayN.ViewModels @@ -41,7 +40,7 @@ public class RoutingRuleSettingViewModel : MyReactiveObject public ReactiveCommand SaveCmd { get; } - public RoutingRuleSettingViewModel(RoutingItem routingItem, Func? updateView) + public RoutingRuleSettingViewModel(RoutingItem routingItem, Func? updateView) { _config = LazyConfig.Instance.GetConfig(); _noticeHandler = Locator.Current.GetService(); @@ -151,8 +150,7 @@ public void RuleEdit(bool blNew) return; } } - var ret = (new RoutingRuleDetailsWindow(item)).ShowDialog(); - if (ret == true) + if (_updateView?.Invoke(EViewAction.RoutingRuleDetailsWindow, item) == true) { if (blNew) { @@ -169,7 +167,7 @@ public void RuleRemove() _noticeHandler?.Enqueue(ResUI.PleaseSelectRules); return; } - if (_updateView?.Invoke(EViewAction.ShowYesNo) == false) + if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false) { return; } @@ -249,7 +247,7 @@ private void SaveRouting() if (ConfigHandler.SaveRoutingItem(_config, item) == 0) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow); + _updateView?.Invoke(EViewAction.CloseWindow, null); } else { @@ -318,7 +316,7 @@ private async Task ImportRulesFromUrl() 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; } diff --git a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs index 8dffbda838..47c3cf8fce 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs @@ -8,7 +8,6 @@ using v2rayN.Handler; using v2rayN.Models; using v2rayN.Resx; -using v2rayN.Views; namespace v2rayN.ViewModels { @@ -71,7 +70,7 @@ public class RoutingSettingViewModel : MyReactiveObject #endregion Reactive - public RoutingSettingViewModel(Func? updateView) + public RoutingSettingViewModel(Func? updateView) { _config = LazyConfig.Instance.GetConfig(); _noticeHandler = Locator.Current.GetService(); @@ -207,7 +206,7 @@ private void SaveRouting() if (ConfigHandler.SaveConfig(_config) == 0) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow); + _updateView?.Invoke(EViewAction.CloseWindow, null); } else { @@ -244,8 +243,7 @@ public void RoutingAdvancedEdit(bool blNew) return; } } - var ret = (new RoutingRuleSettingWindow(item)).ShowDialog(); - if (ret == true) + if (_updateView?.Invoke(EViewAction.RoutingRuleSettingWindow, item) == true) { RefreshRoutingItems(); IsModified = true; @@ -259,7 +257,7 @@ public void RoutingAdvancedRemove() _noticeHandler?.Enqueue(ResUI.PleaseSelectRules); return; } - if (_updateView?.Invoke(EViewAction.ShowYesNo) == false) + if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false) { return; } diff --git a/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs b/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs index 659ba07c99..825ed28ead 100644 --- a/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs @@ -17,7 +17,7 @@ public class SubEditViewModel : MyReactiveObject public ReactiveCommand SaveCmd { get; } - public SubEditViewModel(SubItem subItem, Func? updateView) + public SubEditViewModel(SubItem subItem, Func? updateView) { _config = LazyConfig.Instance.GetConfig(); _noticeHandler = Locator.Current.GetService(); @@ -70,7 +70,7 @@ private void SaveSub() if (ConfigHandler.AddSubItem(_config, item) == 0) { _noticeHandler?.Enqueue(ResUI.OperationSuccess); - _updateView?.Invoke(EViewAction.CloseWindow); + _updateView?.Invoke(EViewAction.CloseWindow, null); } else { diff --git a/v2rayN/v2rayN/ViewModels/SubSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/SubSettingViewModel.cs index 1e4c2d6144..cafa7a5f48 100644 --- a/v2rayN/v2rayN/ViewModels/SubSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/SubSettingViewModel.cs @@ -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.Handler; using v2rayN.Models; using v2rayN.Resx; -using v2rayN.Views; namespace v2rayN.ViewModels { @@ -30,7 +28,7 @@ public class SubSettingViewModel : MyReactiveObject public ReactiveCommand SubShareCmd { get; } public bool IsModified { get; set; } - public SubSettingViewModel(Func? updateView) + public SubSettingViewModel(Func? updateView) { _config = LazyConfig.Instance.GetConfig(); _noticeHandler = Locator.Current.GetService(); @@ -58,7 +56,7 @@ public SubSettingViewModel(Func? updateView) }, canEditRemove); SubShareCmd = ReactiveCommand.Create(() => { - SubShare(); + _updateView?.Invoke(EViewAction.SubShare, SelectedSource?.url); }, canEditRemove); } @@ -83,8 +81,7 @@ public void EditSub(bool blNew) return; } } - var ret = (new SubEditWindow(item)).ShowDialog(); - if (ret == true) + if (_updateView?.Invoke(EViewAction.SubEditWindow, item) == true) { RefreshSubItems(); IsModified = true; @@ -93,7 +90,7 @@ public void EditSub(bool blNew) private void DeleteSub() { - if (_updateView?.Invoke(EViewAction.ShowYesNo) == false) + if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false) { return; } @@ -106,21 +103,5 @@ private void DeleteSub() _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"); - } } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs index acd0a73b0e..1ce39b9e75 100644 --- a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs @@ -42,7 +42,7 @@ public AddServer2Window(ProfileItem profileItem) 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) { diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index 54967fa2d1..a04625b991 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -224,7 +224,7 @@ public AddServerWindow(ProfileItem profileItem) this.Title = $"{profileItem.configType}"; } - private bool UpdateViewHandler(EViewAction action) + private bool UpdateViewHandler(EViewAction action, object? obj) { if (action == EViewAction.CloseWindow) { diff --git a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs index cddff33233..77067c77e1 100644 --- a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs @@ -56,7 +56,7 @@ public DNSSettingWindow() }); } - private bool UpdateViewHandler(EViewAction action) + private bool UpdateViewHandler(EViewAction action, object? obj) { if (action == EViewAction.CloseWindow) { diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index 28e99ba257..a2152489de 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -18,6 +18,7 @@ namespace v2rayN.Views public partial class MainWindow { private static Config _config; + private NoticeHandler _noticeHandler; public MainWindow() { @@ -29,7 +30,10 @@ public MainWindow() 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 @@ public MainWindow() 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) diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index c66397ae66..19b705d121 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -171,7 +171,7 @@ public OptionSettingWindow() }); } - private bool UpdateViewHandler(EViewAction action) + private bool UpdateViewHandler(EViewAction action, object? obj) { if (action == EViewAction.CloseWindow) { diff --git a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs index 5e3988b627..9365dbec31 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -1,3 +1,4 @@ +using MaterialDesignThemes.Wpf; using ReactiveUI; using Splat; using System.Reactive.Disposables; @@ -97,7 +98,7 @@ private void Current_Exit(object sender, ExitEventArgs e) StorageUI(); } - private bool UpdateViewHandler(EViewAction action) + private bool UpdateViewHandler(EViewAction action, object? obj) { if (action == EViewAction.AdjustMainLvColWidth) { @@ -117,10 +118,42 @@ private bool UpdateViewHandler(EViewAction action) 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().ToList(); diff --git a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs index 8559b3cd92..0df1db342d 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs @@ -62,7 +62,7 @@ public RoutingRuleDetailsWindow(RulesItem rulesItem) }); } - private bool UpdateViewHandler(EViewAction action) + private bool UpdateViewHandler(EViewAction action, object? obj) { if (action == EViewAction.CloseWindow) { diff --git a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs index 471699fad9..50ad0bbac4 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs @@ -63,7 +63,7 @@ public RoutingRuleSettingWindow(RoutingItem routingItem) }); } - private bool UpdateViewHandler(EViewAction action) + private bool UpdateViewHandler(EViewAction action, object? obj) { if (action == EViewAction.CloseWindow) { @@ -83,7 +83,11 @@ private bool UpdateViewHandler(EViewAction action) return false; } } - + else if (action == EViewAction.RoutingRuleDetailsWindow) + { + if (obj is null) return false; + return (new RoutingRuleDetailsWindow((RulesItem)obj)).ShowDialog() ?? false; + } return true; } diff --git a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs index 537e1fab42..f1d348c290 100644 --- a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs @@ -70,7 +70,7 @@ public RoutingSettingWindow() }); } - private bool UpdateViewHandler(EViewAction action) + private bool UpdateViewHandler(EViewAction action, object? obj) { if (action == EViewAction.CloseWindow) { @@ -83,6 +83,11 @@ private bool UpdateViewHandler(EViewAction action) return false; } } + else if (action == EViewAction.RoutingRuleSettingWindow) + { + if (obj is null) return false; + return (new RoutingRuleSettingWindow((RoutingItem)obj)).ShowDialog() ?? false; + } return true; } diff --git a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs index fc570a668e..c97f3f1e41 100644 --- a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs @@ -41,7 +41,7 @@ public SubEditWindow(SubItem subItem) }); } - private bool UpdateViewHandler(EViewAction action) + private bool UpdateViewHandler(EViewAction action, object? obj) { if (action == EViewAction.CloseWindow) { diff --git a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs index 73d26896b5..403ea404ac 100644 --- a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs @@ -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 @@ public SubSettingWindow() }); } - private bool UpdateViewHandler(EViewAction action) + private bool UpdateViewHandler(EViewAction action, object? obj) { if (action == EViewAction.CloseWindow) { @@ -48,9 +49,35 @@ private bool UpdateViewHandler(EViewAction action) 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)