88using osu . Framework . Allocation ;
99using osu . Framework . Extensions ;
1010using osu . Framework . Extensions . Color4Extensions ;
11+ using osu . Framework . Extensions . ObjectExtensions ;
1112using osu . Framework . Graphics ;
1213using osu . Framework . Graphics . Containers ;
1314using osu . Framework . Graphics . Shapes ;
@@ -47,6 +48,7 @@ public partial class ExternalEditOverlay : OsuFocusedOverlayContainer
4748
4849 private ExternalEditOperation < SkinInfo > ? editOperation ;
4950 private TaskCompletionSource ? taskCompletionSource ;
51+ private bool finishingEdit ;
5052
5153 protected override bool DimMainContent => false ;
5254
@@ -95,6 +97,8 @@ private void load()
9597 }
9698 }
9799 } ;
100+
101+ gameHost . ExitRequested += tryFinishOnExit ;
98102 }
99103
100104 public async Task < Task > Begin ( SkinInfo skinInfo )
@@ -179,8 +183,19 @@ private void openDirectory()
179183 gameHost . OpenFileExternally ( editOperation . MountedPath . TrimDirectorySeparator ( ) + Path . DirectorySeparatorChar ) ;
180184 }
181185
186+ private void tryFinishOnExit ( )
187+ {
188+ if ( editOperation != null && ! finishingEdit )
189+ finish ( ) . FireAndForget ( onSuccess : ( ) => Schedule ( ( ) => finishingEdit = false ) ) ;
190+ }
191+
182192 private async Task finish ( )
183193 {
194+ if ( finishingEdit )
195+ return ;
196+
197+ finishingEdit = true ;
198+
184199 Debug . Assert ( taskCompletionSource != null ) ;
185200
186201 showSpinner ( "Cleaning up..." ) ;
@@ -236,6 +251,7 @@ protected override void PopOut()
236251 {
237252 // Set everything to a clean state
238253 editOperation = null ;
254+ finishingEdit = false ;
239255 flow . Children = Array . Empty < Drawable > ( ) ;
240256 } ) ;
241257 }
@@ -249,7 +265,8 @@ public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
249265 {
250266 case GlobalAction . Back :
251267 case GlobalAction . Select :
252- if ( editOperation == null ) return base . OnPressed ( e ) ;
268+ if ( editOperation == null )
269+ return false ;
253270
254271 finish ( ) . FireAndForget ( ) ;
255272 return true ;
@@ -280,5 +297,13 @@ private void showSpinner(string text)
280297 } ,
281298 } ;
282299 }
300+
301+ protected override void Dispose ( bool isDisposing )
302+ {
303+ if ( gameHost . IsNotNull ( ) )
304+ gameHost . ExitRequested -= tryFinishOnExit ;
305+
306+ base . Dispose ( isDisposing ) ;
307+ }
283308 }
284309}
0 commit comments