Show changelog from new build notification

This commit is contained in:
Dean Herbert 2019-05-23 18:54:42 +09:00
parent 774ef87868
commit acaf2f9fbb
2 changed files with 61 additions and 20 deletions

View File

@ -1,7 +1,6 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -96,33 +95,37 @@ protected override void LoadComplete()
var version = game.Version;
var lastVersion = config.Get<string>(OsuSetting.Version);
if (game.IsDeployedBuild && version != lastVersion)
//if (game.IsDeployedBuild && version != lastVersion)
{
config.Set(OsuSetting.Version, version);
// only show a notification if we've previously saved a version to the config file (ie. not the first run).
if (!string.IsNullOrEmpty(lastVersion))
notificationOverlay.Post(new UpdateCompleteNotification(version, host.OpenUrlExternally));
notificationOverlay.Post(new UpdateCompleteNotification(version));
}
}
private class UpdateCompleteNotification : SimpleNotification
{
public UpdateCompleteNotification(string version, Action<string> openUrl = null)
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!";
Icon = FontAwesome.Solid.CheckSquare;
Activated = delegate
{
openUrl?.Invoke($"https://osu.ppy.sh/home/changelog/lazer/{version}");
return true;
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OsuColour colours, ChangelogOverlay changelog)
{
Icon = FontAwesome.Solid.CheckSquare;
IconBackgound.Colour = colours.BlueDark;
Activated = delegate
{
changelog.ShowBuild("lazer", version);
return true;
};
}
}

View File

@ -34,6 +34,8 @@ public class ChangelogOverlay : FullscreenOverlay
private List<APIChangelogBuild> builds;
private List<APIUpdateStream> streams;
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colour)
{
@ -87,7 +89,11 @@ private void load(AudioManager audio, OsuColour colour)
});
}
public void ShowListing() => Current.Value = null;
public void ShowListing()
{
Current.Value = null;
State = Visibility.Visible;
}
/// <summary>
/// Fetches and shows a specific build from a specific update stream.
@ -100,6 +106,27 @@ public void ShowBuild([NotNull] APIChangelogBuild build)
if (build == null) throw new ArgumentNullException(nameof(build));
Current.Value = build;
State = Visibility.Visible;
}
public void ShowBuild([NotNull] string updateStream, [NotNull] string version)
{
if (updateStream == null) throw new ArgumentNullException(nameof(updateStream));
if (version == null) throw new ArgumentNullException(nameof(version));
performAfterFetch(() =>
{
var build = builds.Find(b => b.Version == version && b.UpdateStream.Name == updateStream)
?? streams.Find(s => s.Name == updateStream)?.LatestBuild;
if (build != null)
{
Current.Value = build;
State = Visibility.Visible;
}
});
State = Visibility.Visible;
}
public override bool OnPressed(GlobalAction action)
@ -127,15 +154,23 @@ protected override void PopIn()
{
base.PopIn();
if (!initialFetchPerformed)
fetchListing();
if (initialFetchTask == null)
// fetch and refresh to show listing, if no other request was made via Show methods
performAfterFetch(() => Current.TriggerChange());
}
private bool initialFetchPerformed;
private Task initialFetchTask;
private void fetchListing()
private void performAfterFetch(Action action) => fetchListing()?.ContinueWith(_ => Schedule(action));
private Task fetchListing()
{
initialFetchPerformed = true;
if (initialFetchTask != null)
return initialFetchTask;
var tcs = new TaskCompletionSource<bool>();
initialFetchTask = tcs.Task;
Task.Run(() =>
{
@ -147,14 +182,17 @@ private void fetchListing()
res.Streams.ForEach(s => s.LatestBuild.UpdateStream = res.Streams.Find(s2 => s2.Id == s.LatestBuild.UpdateStream.Id));
builds = res.Builds;
streams = res.Streams;
header.Streams.Populate(res.Streams);
Current.TriggerChange();
tcs.SetResult(true);
};
req.Failure += _ => initialFetchPerformed = false;
req.Failure += _ => initialFetchTask = null;
req.Perform(API);
});
return initialFetchTask;
}
private CancellationTokenSource loadContentTask;