From a0286ff810b1632096d85082f709c326fd45471a Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 11 Oct 2024 10:17:44 +0800 Subject: [PATCH] Improved MessageBus contract --- v2rayN/ServiceLib/Enums/EMsgCommand.cs | 10 ++++++++++ v2rayN/ServiceLib/Global.cs | 5 ----- v2rayN/ServiceLib/Handler/NoticeHandler.cs | 4 ++-- v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs | 4 ++-- v2rayN/ServiceLib/ViewModels/MsgViewModel.cs | 2 +- v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs | 4 ++-- v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs | 2 +- v2rayN/v2rayN/Views/MainWindow.xaml.cs | 2 +- 8 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 v2rayN/ServiceLib/Enums/EMsgCommand.cs diff --git a/v2rayN/ServiceLib/Enums/EMsgCommand.cs b/v2rayN/ServiceLib/Enums/EMsgCommand.cs new file mode 100644 index 00000000..31d7556f --- /dev/null +++ b/v2rayN/ServiceLib/Enums/EMsgCommand.cs @@ -0,0 +1,10 @@ +namespace ServiceLib.Enums +{ + public enum EMsgCommand + { + ClearMsg, + SendMsgView, + SendSnackMsg, + RefreshProfiles + } +} \ No newline at end of file diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 56ccaa38..d39955dd 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -68,11 +68,6 @@ public const string GrpcGunMode = "gun"; public const string GrpcMultiMode = "multi"; public const int MaxPort = 65536; - public const string CommandClearMsg = "CommandClearMsg"; - public const string CommandSendMsgView = "CommandSendMsgView"; - public const string CommandSendSnackMsg = "CommandSendSnackMsg"; - public const string CommandStopSpeedTest = "CommandStopSpeedTest"; - public const string CommandRefreshProfiles = "CommandRefreshProfiles"; public const string DelayUnit = ""; public const string SpeedUnit = ""; public const int MinFontSize = 10; diff --git a/v2rayN/ServiceLib/Handler/NoticeHandler.cs b/v2rayN/ServiceLib/Handler/NoticeHandler.cs index 2a8aff68..948fc81c 100644 --- a/v2rayN/ServiceLib/Handler/NoticeHandler.cs +++ b/v2rayN/ServiceLib/Handler/NoticeHandler.cs @@ -13,7 +13,7 @@ namespace ServiceLib.Handler { return; } - MessageBus.Current.SendMessage(content, Global.CommandSendSnackMsg); + MessageBus.Current.SendMessage(content, EMsgCommand.SendSnackMsg.ToString()); } public void SendMessage(string? content) @@ -22,7 +22,7 @@ namespace ServiceLib.Handler { return; } - MessageBus.Current.SendMessage(content, Global.CommandSendMsgView); + MessageBus.Current.SendMessage(content, EMsgCommand.SendMsgView.ToString()); } public void SendMessageEx(string? content) diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index f88f0e99..ea8db5e2 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -150,7 +150,7 @@ namespace ServiceLib.ViewModels _updateView = updateView; _isAdministrator = isAdministrator; - MessageBus.Current.Listen(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null)); + MessageBus.Current.Listen(EMsgCommand.RefreshProfiles.ToString()).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null)); SelectedRouting = new(); SelectedServer = new(); @@ -453,7 +453,7 @@ namespace ServiceLib.ViewModels private void RefreshServers() { - MessageBus.Current.SendMessage("", Global.CommandRefreshProfiles); + MessageBus.Current.SendMessage("", EMsgCommand.RefreshProfiles.ToString()); } public void RefreshServersBiz() diff --git a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs index 8a329939..1c9b5ce5 100644 --- a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs @@ -24,7 +24,7 @@ namespace ServiceLib.ViewModels _config = AppHandler.Instance.Config; _updateView = updateView; - MessageBus.Current.Listen(Global.CommandSendMsgView).Subscribe(async x => await AppendQueueMsg(x)); + MessageBus.Current.Listen(EMsgCommand.SendMsgView.ToString()).Subscribe(async x => await AppendQueueMsg(x)); MsgFilter = _config.msgUIItem.mainMsgFilter ?? string.Empty; AutoRefresh = _config.msgUIItem.autoRefresh ?? true; diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index fc3d6f23..fc121d93 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -101,7 +101,7 @@ namespace ServiceLib.ViewModels _updateView = updateView; - MessageBus.Current.Listen(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null)); + MessageBus.Current.Listen(EMsgCommand.RefreshProfiles.ToString()).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null)); SelectedProfile = new(); SelectedSub = new(); @@ -345,7 +345,7 @@ namespace ServiceLib.ViewModels public void RefreshServers() { - MessageBus.Current.SendMessage("", Global.CommandRefreshProfiles); + MessageBus.Current.SendMessage("", EMsgCommand.RefreshProfiles.ToString()); } public void RefreshServersBiz() diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index b4ccc9d2..c41bfdb3 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -41,7 +41,7 @@ namespace v2rayN.Desktop.Views menuBackupAndRestore.Click += MenuBackupAndRestore_Click; var IsAdministrator = Utils.IsAdministrator(); - MessageBus.Current.Listen(Global.CommandSendSnackMsg).Subscribe(x => DelegateSnackMsg(x)); + MessageBus.Current.Listen(EMsgCommand.SendSnackMsg.ToString()).Subscribe(x => DelegateSnackMsg(x)); ViewModel = new MainWindowViewModel(IsAdministrator, UpdateViewHandler); Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel)); diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index 88846358..40936791 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -37,7 +37,7 @@ namespace v2rayN.Views menuBackupAndRestore.Click += MenuBackupAndRestore_Click; var IsAdministrator = Utils.IsAdministrator(); - MessageBus.Current.Listen(Global.CommandSendSnackMsg).Subscribe(x => DelegateSnackMsg(x)); + MessageBus.Current.Listen(EMsgCommand.SendSnackMsg.ToString()).Subscribe(x => DelegateSnackMsg(x)); ViewModel = new MainWindowViewModel(IsAdministrator, UpdateViewHandler); Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));