@@ -18,9 +18,20 @@ namespace Files.App
18
18
public partial class App : Application
19
19
{
20
20
public static TaskCompletionSource ? SplashScreenLoadingTCS { get ; private set ; }
21
- public static CommandBarFlyout ? LastOpenedFlyout { get ; set ; }
22
21
public static string ? OutputPath { get ; set ; }
23
22
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
+
24
35
// TODO: Replace with DI
25
36
public static QuickAccessManager QuickAccessManager { get ; private set ; } = null ! ;
26
37
public static StorageHistoryWrapper HistoryWrapper { get ; private set ; } = null ! ;
@@ -137,11 +148,11 @@ private async void Window_Closed(object sender, WindowEventArgs args)
137
148
StatusCenterViewModel statusCenterViewModel = Ioc . Default . GetRequiredService < StatusCenterViewModel > ( ) ;
138
149
139
150
// A Workaround for the crash (#10110)
140
- if ( LastOpenedFlyout ? . IsOpen ?? false )
151
+ if ( _LastOpenedFlyout ? . IsOpen ?? false )
141
152
{
142
153
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 ( ) ;
145
156
return ;
146
157
}
147
158
@@ -225,5 +236,15 @@ await SafetyExtensions.IgnoreExceptions(async () =>
225
236
// Wait for ongoing file operations
226
237
FileOperationsHelpers . WaitForCompletion ( ) ;
227
238
}
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
+ }
228
249
}
229
250
}
0 commit comments