1010using System . Reflection ;
1111using System . Threading ;
1212using System . Threading . Tasks ;
13+ using JetBrains . Annotations ;
1314using osu . Framework . Allocation ;
1415using osu . Framework . Audio ;
1516using osu . Framework . Audio . Track ;
@@ -517,6 +518,8 @@ public override void SetHost(GameHost host)
517518 host . ExceptionThrown += onExceptionThrown ;
518519 }
519520
521+ #region Exit handling
522+
520523 /// <summary>
521524 /// Use to programatically exit the game as if the user was triggering via alt-f4.
522525 /// By default, will keep persisting until an exit occurs (exit may be blocked multiple times).
@@ -530,12 +533,28 @@ public virtual void AttemptExit()
530533 Scheduler . AddDelayed ( AttemptExit , 2000 ) ;
531534 }
532535
536+ /// <summary>
537+ /// An action that restarts the application after it has exited.
538+ /// </summary>
539+ [ CanBeNull ]
540+ public Action RestartOnExitAction { private get ; set ; }
541+
542+ /// <summary>
543+ /// Signals that the application should not be restarted after it is exited.
544+ /// </summary>
545+ public void CancelRestartOnExit ( )
546+ {
547+ RestartOnExitAction = null ;
548+ }
549+
533550 /// <summary>
534551 /// If supported by the platform, the game will automatically restart after the next exit.
535552 /// </summary>
536553 /// <returns>Whether a restart operation was queued.</returns>
537554 public virtual bool RestartAppWhenExited ( ) => false ;
538555
556+ #endregion
557+
539558 /// <summary>
540559 /// Perform migration of user data to a specified path.
541560 /// </summary>
@@ -742,6 +761,8 @@ protected override void Dispose(bool isDisposing)
742761
743762 if ( Host != null )
744763 Host . ExceptionThrown -= onExceptionThrown ;
764+
765+ RestartOnExitAction ? . Invoke ( ) ;
745766 }
746767
747768 ControlPointInfo IBeatSyncProvider . ControlPoints => Beatmap . Value . BeatmapLoaded ? Beatmap . Value . Beatmap . ControlPointInfo : null ;
0 commit comments