Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show an ongoing operation when checking for updates #30953

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions osu.Game/Localisation/GeneralSettingsStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public static class GeneralSettingsStrings
/// </summary>
public static LocalisableString CheckUpdate => new TranslatableString(getKey(@"check_update"), @"Check for updates");

/// <summary>
/// "Checking for updates"
/// </summary>
public static LocalisableString CheckingForUpdates => new TranslatableString(getKey(@"checking_for_updates"), @"Checking for updates");

/// <summary>
/// "Open osu! folder"
/// </summary>
Expand Down
63 changes: 44 additions & 19 deletions osu.Game/Overlays/Settings/Sections/General/UpdateSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading.Tasks;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Framework.Logging;
Expand All @@ -13,6 +12,7 @@
using osu.Framework.Statistics;
using osu.Game.Configuration;
using osu.Game.Localisation;
using osu.Game.Online.Multiplayer;
using osu.Game.Overlays.Notifications;
using osu.Game.Overlays.Settings.Sections.Maintenance;
using osu.Game.Updater;
Expand All @@ -36,8 +36,11 @@ public partial class UpdateSettings : SettingsSubsection
[Resolved]
private Storage storage { get; set; } = null!;

[Resolved]
private OsuGame? game { get; set; }

[BackgroundDependencyLoader]
private void load(OsuConfigManager config, OsuGame? game)
private void load(OsuConfigManager config)
{
Add(new SettingsEnumDropdown<ReleaseStream>
{
Expand All @@ -50,23 +53,7 @@ private void load(OsuConfigManager config, OsuGame? game)
Add(checkForUpdatesButton = new SettingsButton
{
Text = GeneralSettingsStrings.CheckUpdate,
Action = () =>
{
checkForUpdatesButton.Enabled.Value = false;
Task.Run(updateManager.CheckForUpdateAsync).ContinueWith(task => Schedule(() =>
{
if (!task.GetResultSafely())
{
notifications?.Post(new SimpleNotification
{
Text = GeneralSettingsStrings.RunningLatestRelease(game!.Version),
Icon = FontAwesome.Solid.CheckCircle,
});
}

checkForUpdatesButton.Enabled.Value = true;
}));
}
Action = () => checkForUpdates().FireAndForget()
});
}

Expand Down Expand Up @@ -94,6 +81,44 @@ private void load(OsuConfigManager config, OsuGame? game)
}
}

private async Task checkForUpdates()
{
if (updateManager == null || game == null)
return;

checkForUpdatesButton.Enabled.Value = false;

var checkingNotification = new ProgressNotification
{
Text = GeneralSettingsStrings.CheckingForUpdates,
};
notifications?.Post(checkingNotification);

try
{
bool foundUpdate = await updateManager.CheckForUpdateAsync().ConfigureAwait(true);

if (!foundUpdate)
{
notifications?.Post(new SimpleNotification
{
Text = GeneralSettingsStrings.RunningLatestRelease(game.Version),
Icon = FontAwesome.Solid.CheckCircle,
});
}
}
catch
{
}
finally
{
// This sequence allows the notification to be immediately dismissed.
checkingNotification.State = ProgressNotificationState.Cancelled;
checkingNotification.Close(false);
checkForUpdatesButton.Enabled.Value = true;
}
}

private void exportLogs()
{
ProgressNotification notification = new ProgressNotification
Expand Down
Loading