Improved MessageBus contract

pull/5829/head
2dust 2024-10-11 10:17:44 +08:00
parent b172b03927
commit a0286ff810
8 changed files with 19 additions and 14 deletions

View File

@ -0,0 +1,10 @@
namespace ServiceLib.Enums
{
public enum EMsgCommand
{
ClearMsg,
SendMsgView,
SendSnackMsg,
RefreshProfiles
}
}

View File

@ -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;

View File

@ -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)

View File

@ -150,7 +150,7 @@ namespace ServiceLib.ViewModels
_updateView = updateView;
_isAdministrator = isAdministrator;
MessageBus.Current.Listen<string>(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null));
MessageBus.Current.Listen<string>(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()

View File

@ -24,7 +24,7 @@ namespace ServiceLib.ViewModels
_config = AppHandler.Instance.Config;
_updateView = updateView;
MessageBus.Current.Listen<string>(Global.CommandSendMsgView).Subscribe(async x => await AppendQueueMsg(x));
MessageBus.Current.Listen<string>(EMsgCommand.SendMsgView.ToString()).Subscribe(async x => await AppendQueueMsg(x));
MsgFilter = _config.msgUIItem.mainMsgFilter ?? string.Empty;
AutoRefresh = _config.msgUIItem.autoRefresh ?? true;

View File

@ -101,7 +101,7 @@ namespace ServiceLib.ViewModels
_updateView = updateView;
MessageBus.Current.Listen<string>(Global.CommandRefreshProfiles).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null));
MessageBus.Current.Listen<string>(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()

View File

@ -41,7 +41,7 @@ namespace v2rayN.Desktop.Views
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
var IsAdministrator = Utils.IsAdministrator();
MessageBus.Current.Listen<string>(Global.CommandSendSnackMsg).Subscribe(x => DelegateSnackMsg(x));
MessageBus.Current.Listen<string>(EMsgCommand.SendSnackMsg.ToString()).Subscribe(x => DelegateSnackMsg(x));
ViewModel = new MainWindowViewModel(IsAdministrator, UpdateViewHandler);
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));

View File

@ -37,7 +37,7 @@ namespace v2rayN.Views
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
var IsAdministrator = Utils.IsAdministrator();
MessageBus.Current.Listen<string>(Global.CommandSendSnackMsg).Subscribe(x => DelegateSnackMsg(x));
MessageBus.Current.Listen<string>(EMsgCommand.SendSnackMsg.ToString()).Subscribe(x => DelegateSnackMsg(x));
ViewModel = new MainWindowViewModel(IsAdministrator, UpdateViewHandler);
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));