11using System . ComponentModel ;
22using System . Reactive . Disposables ;
3+ using System . Reactive . Linq ;
34using System . Windows ;
45using System . Windows . Controls ;
56using System . Windows . Input ;
@@ -36,7 +37,6 @@ public MainWindow()
3637 menuCheckUpdate . Click += MenuCheckUpdate_Click ;
3738 menuBackupAndRestore . Click += MenuBackupAndRestore_Click ;
3839
39- MessageBus . Current . Listen < string > ( EMsgCommand . SendSnackMsg . ToString ( ) ) . Subscribe ( DelegateSnackMsg ) ;
4040 ViewModel = new MainWindowViewModel ( UpdateViewHandler ) ;
4141 Locator . CurrentMutable . RegisterLazySingleton ( ( ) => ViewModel , typeof ( MainWindowViewModel ) ) ;
4242
@@ -133,6 +133,18 @@ public MainWindow()
133133 this . Bind ( ViewModel , vm => vm . TabMainSelectedIndex , v => v . tabMain2 . SelectedIndex ) . DisposeWith ( disposables ) ;
134134 break ;
135135 }
136+
137+ AppEvents . SendSnackMsgRequested
138+ . AsObservable ( )
139+ . ObserveOn ( RxApp . MainThreadScheduler )
140+ . Subscribe ( async content => await DelegateSnackMsg ( content ) )
141+ . DisposeWith ( disposables ) ;
142+
143+ AppEvents . AppExitRequested
144+ . AsObservable ( )
145+ . ObserveOn ( RxApp . MainThreadScheduler )
146+ . Subscribe ( _ => StorageUI ( ) )
147+ . DisposeWith ( disposables ) ;
136148 } ) ;
137149
138150 this . Title = $ "{ Utils . GetVersion ( ) } - { ( Utils . IsAdministrator ( ) ? ResUI . RunAsAdmin : ResUI . NotRunAsAdmin ) } ";
@@ -144,7 +156,6 @@ public MainWindow()
144156
145157 AddHelpMenuItem ( ) ;
146158 WindowsManager . Instance . RegisterGlobalHotkey ( _config , OnHotkeyHandler , null ) ;
147- MessageBus . Current . Listen < string > ( EMsgCommand . AppExit . ToString ( ) ) . Subscribe ( StorageUI ) ;
148159 }
149160
150161 #region Event
@@ -157,12 +168,9 @@ private void OnProgramStarted(object state, bool timeout)
157168 } ) ) ;
158169 }
159170
160- private void DelegateSnackMsg ( string content )
171+ private async Task DelegateSnackMsg ( string content )
161172 {
162- Application . Current ? . Dispatcher . Invoke ( ( ( ) =>
163- {
164- MainSnackbar . MessageQueue ? . Enqueue ( content ) ;
165- } ) , DispatcherPriority . Normal ) ;
173+ MainSnackbar . MessageQueue ? . Enqueue ( content ) ;
166174 }
167175
168176 private async Task < bool > UpdateViewHandler ( EViewAction action , object ? obj )
@@ -423,7 +431,7 @@ private void RestoreUI()
423431 }
424432 }
425433
426- private void StorageUI ( string ? n = null )
434+ private void StorageUI ( )
427435 {
428436 ConfigHandler . SaveWindowSizeItem ( _config , GetType ( ) . Name , Width , Height ) ;
429437
0 commit comments