1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 15:27:24 +08:00

Add method to queue a restart after app is exited (when supported)

This commit is contained in:
Dean Herbert 2023-06-21 18:29:34 +09:00
parent c815f8cd23
commit c3f772f0da
4 changed files with 41 additions and 4 deletions

View File

@ -17,6 +17,7 @@ using osu.Game.Updater;
using osu.Desktop.Windows;
using osu.Game.IO;
using osu.Game.IPC;
using osu.Game.Online.Multiplayer;
using osu.Game.Utils;
using SDL2;
@ -108,6 +109,25 @@ namespace osu.Desktop
}
}
public override bool RestartAppWhenExited()
{
switch (RuntimeInfo.OS)
{
case RuntimeInfo.Platform.Windows:
Debug.Assert(OperatingSystem.IsWindows());
// Of note, this is an async method in squirrel that adds an arbitrary delay before returning
// likely to ensure the external process is in a good state.
//
// We're not waiting on that here, but the outro playing before the actual exit should be enough
// to cover this.
Squirrel.UpdateManager.RestartAppWhenExited().FireAndForget();
return true;
}
return base.RestartAppWhenExited();
}
protected override void LoadComplete()
{
base.LoadComplete();

View File

@ -28,7 +28,11 @@ namespace osu.Game.Tournament.Screens.Setup
dropdown.Items = storage.ListTournaments();
dropdown.Current.BindValueChanged(v => Button.Enabled.Value = v.NewValue != startupTournament, true);
Action = () => game.AttemptExit();
Action = () =>
{
game.RestartAppWhenExited();
game.AttemptExit();
};
folderButton.Action = () => storage.PresentExternally();
ButtonText = "Close osu!";

View File

@ -515,6 +515,12 @@ namespace osu.Game
Scheduler.AddDelayed(AttemptExit, 2000);
}
/// <summary>
/// If supported by the platform, the game will automatically restart after the next exit.
/// </summary>
/// <returns>Whether a restart operation was queued.</returns>
public virtual bool RestartAppWhenExited() => false;
public bool Migrate(string path)
{
Logger.Log($@"Migrating osu! data from ""{Storage.GetFullPath(string.Empty)}"" to ""{path}""...");

View File

@ -67,10 +67,17 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
if (r.NewValue == RendererType.Automatic && automaticRendererInUse)
return;
dialogOverlay?.Push(new ConfirmDialog(GraphicsSettingsStrings.ChangeRendererConfirmation, () => game?.AttemptExit(), () =>
if (game?.RestartAppWhenExited() == true)
{
renderer.Value = automaticRendererInUse ? RendererType.Automatic : host.ResolvedRenderer;
}));
game.AttemptExit();
}
else
{
dialogOverlay?.Push(new ConfirmDialog(GraphicsSettingsStrings.ChangeRendererConfirmation, () => game?.AttemptExit(), () =>
{
renderer.Value = automaticRendererInUse ? RendererType.Automatic : host.ResolvedRenderer;
}));
}
});
// TODO: remove this once we support SDL+android.