@@ -18,9 +18,20 @@ namespace Files.App
1818 public partial class App : Application
1919 {
2020 public static TaskCompletionSource ? SplashScreenLoadingTCS { get ; private set ; }
21- public static CommandBarFlyout ? LastOpenedFlyout { get ; set ; }
2221 public static string ? OutputPath { get ; set ; }
2322
23+ private static CommandBarFlyout ? _LastOpenedFlyout ;
24+ public static CommandBarFlyout ? LastOpenedFlyout
25+ {
26+ set
27+ {
28+ _LastOpenedFlyout = value ;
29+
30+ if ( _LastOpenedFlyout is not null )
31+ _LastOpenedFlyout . Closed += LastOpenedFlyout_Closed ;
32+ }
33+ }
34+
2435 // TODO: Replace with DI
2536 public static QuickAccessManager QuickAccessManager { get ; private set ; } = null ! ;
2637 public static StorageHistoryWrapper HistoryWrapper { get ; private set ; } = null ! ;
@@ -137,11 +148,11 @@ private async void Window_Closed(object sender, WindowEventArgs args)
137148 StatusCenterViewModel statusCenterViewModel = Ioc . Default . GetRequiredService < StatusCenterViewModel > ( ) ;
138149
139150 // A Workaround for the crash (#10110)
140- if ( LastOpenedFlyout ? . IsOpen ?? false )
151+ if ( _LastOpenedFlyout ? . IsOpen ?? false )
141152 {
142153 args . Handled = true ;
143- LastOpenedFlyout . Closed += ( sender , e ) => App . Current . Exit ( ) ;
144- LastOpenedFlyout . Hide ( ) ;
154+ _LastOpenedFlyout . Closed += ( sender , e ) => App . Current . Exit ( ) ;
155+ _LastOpenedFlyout . Hide ( ) ;
145156 return ;
146157 }
147158
@@ -225,5 +236,15 @@ await SafetyExtensions.IgnoreExceptions(async () =>
225236 // Wait for ongoing file operations
226237 FileOperationsHelpers . WaitForCompletion ( ) ;
227238 }
239+
240+ private static void LastOpenedFlyout_Closed ( object ? sender , object e )
241+ {
242+ if ( sender is not CommandBarFlyout commandBarFlyout )
243+ return ;
244+
245+ commandBarFlyout . Closed -= LastOpenedFlyout_Closed ;
246+ if ( _LastOpenedFlyout == commandBarFlyout )
247+ _LastOpenedFlyout = null ;
248+ }
228249 }
229250}
0 commit comments