diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 2530f34939..a860a0ec2e 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Reflection; using System.Runtime.Versioning; -using System.Threading.Tasks; using Microsoft.Win32; using osu.Desktop.Performance; using osu.Desktop.Security; @@ -20,7 +19,6 @@ using osu.Framework.Allocation; using osu.Game.Configuration; using osu.Game.IO; using osu.Game.IPC; -using osu.Game.Online.Multiplayer; using osu.Game.Performance; using osu.Game.Utils; @@ -123,7 +121,7 @@ namespace osu.Desktop public override bool RestartAppWhenExited() { - Task.Run(() => Velopack.UpdateExe.Start(waitPid: (uint)Environment.ProcessId)).FireAndForget(); + RestartOnExitAction = () => Velopack.UpdateExe.Start(waitPid: (uint)Environment.ProcessId); return true; } diff --git a/osu.Desktop/Updater/VelopackUpdateManager.cs b/osu.Desktop/Updater/VelopackUpdateManager.cs index cba050c638..093eb60f10 100644 --- a/osu.Desktop/Updater/VelopackUpdateManager.cs +++ b/osu.Desktop/Updater/VelopackUpdateManager.cs @@ -146,11 +146,11 @@ namespace osu.Desktop.Updater action(); } - private void restartToApplyUpdate(Velopack.UpdateManager updateManager, UpdateInfo update) => Task.Run(async () => + private void restartToApplyUpdate(Velopack.UpdateManager updateManager, UpdateInfo update) { - await updateManager.WaitExitThenApplyUpdatesAsync(update.TargetFullRelease).ConfigureAwait(false); - Schedule(() => game.AttemptExit()); - }); + game.RestartOnExitAction = () => updateManager.WaitExitThenApplyUpdates(update.TargetFullRelease); + game.AttemptExit(); + } private static void log(string text) => Logger.Log($"VelopackUpdateManager: {text}"); } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 77ccf7edfc..150d084a78 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -193,7 +193,7 @@ namespace osu.Game protected readonly Bindable UserPlayingState = new Bindable(); - protected OsuScreenStack ScreenStack; + public OsuScreenStack ScreenStack { get; private set; } protected BackButton BackButton => screenStackFooter.BackButton; protected ScreenFooter ScreenFooter => screenStackFooter.Footer; diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index f6fa1147ea..e957753c8b 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Track; @@ -517,6 +518,8 @@ namespace osu.Game host.ExceptionThrown += onExceptionThrown; } + #region Exit handling + /// /// Use to programatically exit the game as if the user was triggering via alt-f4. /// By default, will keep persisting until an exit occurs (exit may be blocked multiple times). @@ -530,12 +533,28 @@ namespace osu.Game Scheduler.AddDelayed(AttemptExit, 2000); } + /// + /// An action that restarts the application after it has exited. + /// + [CanBeNull] + public Action RestartOnExitAction { private get; set; } + + /// + /// Signals that the application should not be restarted after it is exited. + /// + public void CancelRestartOnExit() + { + RestartOnExitAction = null; + } + /// /// If supported by the platform, the game will automatically restart after the next exit. /// /// Whether a restart operation was queued. public virtual bool RestartAppWhenExited() => false; + #endregion + /// /// Perform migration of user data to a specified path. /// @@ -742,6 +761,8 @@ namespace osu.Game if (Host != null) Host.ExceptionThrown -= onExceptionThrown; + + RestartOnExitAction?.Invoke(); } ControlPointInfo IBeatSyncProvider.ControlPoints => Beatmap.Value.BeatmapLoaded ? Beatmap.Value.Beatmap.ControlPointInfo : null; diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 6e7e8e7a74..32062409d0 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -429,6 +429,7 @@ namespace osu.Game.Screens.Menu }, () => { holdToExitGameOverlay.Abort(); + Game.CancelRestartOnExit(); })); } diff --git a/osu.Game/Tests/Visual/OsuGameTestScene.cs b/osu.Game/Tests/Visual/OsuGameTestScene.cs index fb229194d9..f0e8a4da4d 100644 --- a/osu.Game/Tests/Visual/OsuGameTestScene.cs +++ b/osu.Game/Tests/Visual/OsuGameTestScene.cs @@ -124,8 +124,6 @@ namespace osu.Game.Tests.Visual { public new const float SIDE_OVERLAY_OFFSET_RATIO = OsuGame.SIDE_OVERLAY_OFFSET_RATIO; - public new ScreenStack ScreenStack => base.ScreenStack; - public RealmAccess Realm => Dependencies.Get(); public new GlobalCursorDisplay GlobalCursorDisplay => base.GlobalCursorDisplay;