2019-09-24 17:03:01 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2020-06-08 06:39:33 +08:00
|
|
|
using System.Threading.Tasks;
|
2019-09-24 17:03:01 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.Notifications;
|
|
|
|
|
|
|
|
namespace osu.Game.Updater
|
|
|
|
{
|
2019-12-20 12:50:57 +08:00
|
|
|
/// <summary>
|
|
|
|
/// An update manager which only shows notifications after an update completes.
|
|
|
|
/// </summary>
|
|
|
|
public class UpdateManager : CompositeDrawable
|
2019-09-24 17:03:01 +08:00
|
|
|
{
|
2020-05-08 08:50:58 +08:00
|
|
|
/// <summary>
|
2020-06-08 06:39:33 +08:00
|
|
|
/// Whether this UpdateManager should be or is capable of checking for updates.
|
2020-05-08 08:50:58 +08:00
|
|
|
/// </summary>
|
2020-06-12 18:24:50 +08:00
|
|
|
public bool CanCheckForUpdate => game.IsDeployedBuild &&
|
|
|
|
// only implementations will actually check for updates.
|
|
|
|
GetType() != typeof(UpdateManager);
|
2020-06-08 06:39:33 +08:00
|
|
|
|
2019-09-24 17:03:01 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuConfigManager config { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuGameBase game { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
protected NotificationOverlay Notifications { get; private set; }
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-06-08 06:39:33 +08:00
|
|
|
Schedule(() => Task.Run(CheckForUpdateAsync));
|
|
|
|
|
2020-06-12 18:20:45 +08:00
|
|
|
var version = game.Version;
|
|
|
|
|
2020-06-12 18:32:32 +08:00
|
|
|
var lastVersion = config.Get<string>(OsuSetting.Version);
|
|
|
|
|
2020-06-12 18:20:45 +08:00
|
|
|
if (game.IsDeployedBuild && version != lastVersion)
|
|
|
|
{
|
|
|
|
// only show a notification if we've previously saved a version to the config file (ie. not the first run).
|
|
|
|
if (!string.IsNullOrEmpty(lastVersion))
|
|
|
|
Notifications.Post(new UpdateCompleteNotification(version));
|
|
|
|
}
|
|
|
|
|
2020-06-08 06:39:33 +08:00
|
|
|
// debug / local compilations will reset to a non-release string.
|
|
|
|
// can be useful to check when an install has transitioned between release and otherwise (see OsuConfigManager's migrations).
|
2020-06-12 18:26:46 +08:00
|
|
|
config.Set(OsuSetting.Version, version);
|
2020-06-08 06:39:33 +08:00
|
|
|
}
|
|
|
|
|
2020-06-12 17:29:21 +08:00
|
|
|
private readonly object updateTaskLock = new object();
|
|
|
|
|
|
|
|
private Task updateCheckTask;
|
|
|
|
|
2020-06-08 06:39:33 +08:00
|
|
|
public async Task CheckForUpdateAsync()
|
|
|
|
{
|
|
|
|
if (!CanCheckForUpdate)
|
|
|
|
return;
|
|
|
|
|
2020-06-15 21:19:02 +08:00
|
|
|
Task waitTask;
|
|
|
|
|
2020-06-12 17:29:21 +08:00
|
|
|
lock (updateTaskLock)
|
2020-06-15 21:19:02 +08:00
|
|
|
waitTask = (updateCheckTask ??= PerformUpdateCheck());
|
2020-06-12 17:29:21 +08:00
|
|
|
|
2020-06-15 21:19:02 +08:00
|
|
|
await waitTask;
|
2020-06-12 17:29:21 +08:00
|
|
|
|
|
|
|
lock (updateTaskLock)
|
|
|
|
updateCheckTask = null;
|
2020-06-08 06:39:33 +08:00
|
|
|
}
|
|
|
|
|
2020-06-12 18:20:45 +08:00
|
|
|
protected virtual Task PerformUpdateCheck() => Task.CompletedTask;
|
2020-05-07 14:07:22 +08:00
|
|
|
|
2019-09-24 17:03:01 +08:00
|
|
|
private class UpdateCompleteNotification : SimpleNotification
|
|
|
|
{
|
|
|
|
private readonly string version;
|
|
|
|
|
|
|
|
public UpdateCompleteNotification(string version)
|
|
|
|
{
|
|
|
|
this.version = version;
|
|
|
|
Text = $"You are now running osu!lazer {version}.\nClick to see what's new!";
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours, ChangelogOverlay changelog, NotificationOverlay notificationOverlay)
|
|
|
|
{
|
|
|
|
Icon = FontAwesome.Solid.CheckSquare;
|
|
|
|
IconBackgound.Colour = colours.BlueDark;
|
|
|
|
|
|
|
|
Activated = delegate
|
|
|
|
{
|
|
|
|
notificationOverlay.Hide();
|
|
|
|
changelog.ShowBuild(OsuGameBase.CLIENT_STREAM_NAME, version);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|