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;
|
2022-09-12 13:52:11 +08:00
|
|
|
using osu.Framework.Graphics;
|
2019-09-24 17:03:01 +08:00
|
|
|
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;
|
2022-09-12 13:52:11 +08:00
|
|
|
using osuTK;
|
2019-09-24 17:03:01 +08:00
|
|
|
|
|
|
|
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 partial 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]
|
2022-09-12 13:52:11 +08:00
|
|
|
private OsuConfigManager config { get; set; } = null!;
|
2019-09-24 17:03:01 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2022-09-12 13:52:11 +08:00
|
|
|
private OsuGameBase game { get; set; } = null!;
|
2019-09-24 17:03:01 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2022-09-12 13:52:11 +08:00
|
|
|
protected INotificationOverlay Notifications { get; private set; } = null!;
|
2019-09-24 17:03:01 +08:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-06-08 06:39:33 +08:00
|
|
|
Schedule(() => Task.Run(CheckForUpdateAsync));
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
string version = game.Version;
|
2020-06-12 18:20:45 +08:00
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
string lastVersion = config.Get<string>(OsuSetting.Version);
|
2020-06-12 18:32:32 +08:00
|
|
|
|
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).
|
2021-03-17 15:10:16 +08:00
|
|
|
config.SetValue(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();
|
|
|
|
|
2022-09-12 13:52:11 +08:00
|
|
|
private Task<bool>? updateCheckTask;
|
2020-06-12 17:29:21 +08:00
|
|
|
|
2020-10-06 12:00:02 +08:00
|
|
|
public async Task<bool> CheckForUpdateAsync()
|
2020-06-08 06:39:33 +08:00
|
|
|
{
|
2020-10-07 17:40:09 +08:00
|
|
|
if (!CanCheckForUpdate)
|
|
|
|
return false;
|
|
|
|
|
2020-10-06 12:00:02 +08:00
|
|
|
Task<bool> waitTask;
|
2020-06-15 21:19:02 +08:00
|
|
|
|
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
|
|
|
|
2021-03-08 11:57:16 +08:00
|
|
|
bool hasUpdates = await waitTask.ConfigureAwait(false);
|
2020-06-12 17:29:21 +08:00
|
|
|
|
|
|
|
lock (updateTaskLock)
|
|
|
|
updateCheckTask = null;
|
2020-10-06 12:00:02 +08:00
|
|
|
|
|
|
|
return hasUpdates;
|
2020-06-08 06:39:33 +08:00
|
|
|
}
|
|
|
|
|
2020-10-06 12:00:02 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Performs an asynchronous check for application updates.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Whether any update is waiting. May return true if an error occured (there is potentially an update available).</returns>
|
|
|
|
protected virtual Task<bool> PerformUpdateCheck() => Task.FromResult(false);
|
2020-05-07 14:07:22 +08:00
|
|
|
|
2019-09-24 17:03:01 +08:00
|
|
|
private partial class UpdateCompleteNotification : SimpleNotification
|
|
|
|
{
|
|
|
|
private readonly string version;
|
|
|
|
|
|
|
|
public UpdateCompleteNotification(string version)
|
|
|
|
{
|
|
|
|
this.version = version;
|
2021-07-04 11:39:50 +08:00
|
|
|
Text = $"You are now running osu! {version}.\nClick to see what's new!";
|
2019-09-24 17:03:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-04-18 18:59:57 +08:00
|
|
|
private void load(OsuColour colours, ChangelogOverlay changelog, INotificationOverlay notificationOverlay)
|
2019-09-24 17:03:01 +08:00
|
|
|
{
|
|
|
|
Icon = FontAwesome.Solid.CheckSquare;
|
2022-08-30 16:40:35 +08:00
|
|
|
IconContent.Colour = colours.BlueDark;
|
2019-09-24 17:03:01 +08:00
|
|
|
|
|
|
|
Activated = delegate
|
|
|
|
{
|
|
|
|
notificationOverlay.Hide();
|
|
|
|
changelog.ShowBuild(OsuGameBase.CLIENT_STREAM_NAME, version);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2022-09-12 13:52:11 +08:00
|
|
|
|
2022-09-12 14:04:30 +08:00
|
|
|
public partial class UpdateApplicationCompleteNotification : ProgressCompletionNotification
|
2022-09-12 13:52:11 +08:00
|
|
|
{
|
|
|
|
public UpdateApplicationCompleteNotification()
|
|
|
|
{
|
|
|
|
Text = @"Update ready to install. Click to restart!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public partial class UpdateProgressNotification : ProgressNotification
|
|
|
|
{
|
2022-09-12 14:04:30 +08:00
|
|
|
protected override Notification CreateCompletionNotification() => new UpdateApplicationCompleteNotification
|
|
|
|
{
|
|
|
|
Activated = CompletionClickAction
|
|
|
|
};
|
2022-09-12 13:52:11 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
IconContent.AddRange(new Drawable[]
|
|
|
|
{
|
|
|
|
new SpriteIcon
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Icon = FontAwesome.Solid.Upload,
|
2022-09-12 13:58:46 +08:00
|
|
|
Size = new Vector2(34),
|
|
|
|
Colour = OsuColour.Gray(0.2f),
|
|
|
|
Depth = float.MaxValue,
|
2022-09-12 13:52:11 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-12 13:58:46 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
StartDownload();
|
|
|
|
}
|
|
|
|
|
2022-09-12 17:57:18 +08:00
|
|
|
public override void Close(bool runFlingAnimation)
|
2022-09-12 13:52:11 +08:00
|
|
|
{
|
|
|
|
// cancelling updates is not currently supported by the underlying updater.
|
|
|
|
// only allow dismissing for now.
|
|
|
|
|
|
|
|
switch (State)
|
|
|
|
{
|
|
|
|
case ProgressNotificationState.Cancelled:
|
2022-09-23 21:30:07 +08:00
|
|
|
case ProgressNotificationState.Completed:
|
2022-09-12 17:57:18 +08:00
|
|
|
base.Close(runFlingAnimation);
|
2022-09-12 13:52:11 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void StartDownload()
|
|
|
|
{
|
|
|
|
State = ProgressNotificationState.Active;
|
|
|
|
Progress = 0;
|
|
|
|
Text = @"Downloading update...";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void StartInstall()
|
|
|
|
{
|
|
|
|
Progress = 0;
|
|
|
|
Text = @"Installing update...";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void FailDownload()
|
|
|
|
{
|
|
|
|
State = ProgressNotificationState.Cancelled;
|
2022-09-12 15:54:25 +08:00
|
|
|
Close(false);
|
2022-09-12 13:52:11 +08:00
|
|
|
}
|
|
|
|
}
|
2019-09-24 17:03:01 +08:00
|
|
|
}
|
|
|
|
}
|