Use Rx event subscription instead of MessageBus to send information
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
@@ -39,7 +40,6 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
|
||||
menuClose.Click += MenuClose_Click;
|
||||
|
||||
MessageBus.Current.Listen<string>(EMsgCommand.SendSnackMsg.ToString()).Subscribe(DelegateSnackMsg);
|
||||
ViewModel = new MainWindowViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));
|
||||
|
||||
@@ -136,6 +136,18 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||
this.Bind(ViewModel, vm => vm.TabMainSelectedIndex, v => v.tabMain2.SelectedIndex).DisposeWith(disposables);
|
||||
break;
|
||||
}
|
||||
|
||||
AppEvents.SendSnackMsgRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async content => await DelegateSnackMsg(content))
|
||||
.DisposeWith(disposables);
|
||||
|
||||
AppEvents.AppExitRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(_ => StorageUI())
|
||||
.DisposeWith(disposables);
|
||||
});
|
||||
|
||||
if (Utils.IsWindows())
|
||||
@@ -156,7 +168,6 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||
menuAddServerViaScan.IsVisible = false;
|
||||
|
||||
AddHelpMenuItem();
|
||||
MessageBus.Current.Listen<string>(EMsgCommand.AppExit.ToString()).Subscribe(StorageUI);
|
||||
}
|
||||
|
||||
#region Event
|
||||
@@ -168,11 +179,9 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||
DispatcherPriority.Default);
|
||||
}
|
||||
|
||||
private void DelegateSnackMsg(string content)
|
||||
private async Task DelegateSnackMsg(string content)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
_manager?.Show(new Notification(null, content, NotificationType.Information)),
|
||||
DispatcherPriority.Normal);
|
||||
_manager?.Show(new Notification(null, content, NotificationType.Information));
|
||||
}
|
||||
|
||||
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
||||
@@ -462,7 +471,7 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||
}
|
||||
}
|
||||
|
||||
private void StorageUI(string? n = null)
|
||||
private void StorageUI()
|
||||
{
|
||||
ConfigHandler.SaveWindowSizeItem(_config, GetType().Name, Width, Height);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user