Skip to content

Commit

Permalink
Improved MessageBus contract
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 11, 2024
1 parent b172b03 commit a0286ff
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
10 changes: 10 additions & 0 deletions v2rayN/ServiceLib/Enums/EMsgCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ServiceLib.Enums
{
public enum EMsgCommand
{
ClearMsg,
SendMsgView,
SendSnackMsg,
RefreshProfiles
}
}
5 changes: 0 additions & 5 deletions v2rayN/ServiceLib/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ public class Global
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;
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Handler/NoticeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void Enqueue(string? content)
{
return;
}
MessageBus.Current.SendMessage(content, Global.CommandSendSnackMsg);
MessageBus.Current.SendMessage(content, EMsgCommand.SendSnackMsg.ToString());
}

public void SendMessage(string? content)
Expand All @@ -22,7 +22,7 @@ public void SendMessage(string? content)
{
return;
}
MessageBus.Current.SendMessage(content, Global.CommandSendMsgView);
MessageBus.Current.SendMessage(content, EMsgCommand.SendMsgView.ToString());
}

public void SendMessageEx(string? content)
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public MainWindowViewModel(bool isAdministrator, Func<EViewAction, object?, Task
_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();
Expand Down Expand Up @@ -453,7 +453,7 @@ public async Task UpgradeApp(string fileName)

private void RefreshServers()
{
MessageBus.Current.SendMessage("", Global.CommandRefreshProfiles);
MessageBus.Current.SendMessage("", EMsgCommand.RefreshProfiles.ToString());
}

public void RefreshServersBiz()
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/ServiceLib/ViewModels/MsgViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public MsgViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
_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;
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public ProfilesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)

_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();
Expand Down Expand Up @@ -345,7 +345,7 @@ private void ServerFilterChanged(bool c)

public void RefreshServers()
{
MessageBus.Current.SendMessage("", Global.CommandRefreshProfiles);
MessageBus.Current.SendMessage("", EMsgCommand.RefreshProfiles.ToString());
}

public void RefreshServersBiz()
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MainWindow()
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));

Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public MainWindow()
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));

Expand Down

0 comments on commit a0286ff

Please sign in to comment.