From acaf2f9fbb538a3aa335ce1319ea624a33486a91 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 23 May 2019 18:54:42 +0900 Subject: [PATCH] Show changelog from new build notification --- osu.Desktop/Overlays/VersionManager.cs | 25 +++++++----- osu.Game/Overlays/ChangelogOverlay.cs | 56 +++++++++++++++++++++----- 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/osu.Desktop/Overlays/VersionManager.cs b/osu.Desktop/Overlays/VersionManager.cs index e9c5d06f3c..7e4257c23b 100644 --- a/osu.Desktop/Overlays/VersionManager.cs +++ b/osu.Desktop/Overlays/VersionManager.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . 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 @@ namespace osu.Desktop.Overlays var version = game.Version; var lastVersion = config.Get(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 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; + }; } } diff --git a/osu.Game/Overlays/ChangelogOverlay.cs b/osu.Game/Overlays/ChangelogOverlay.cs index 6ce82d342a..a957227c6b 100644 --- a/osu.Game/Overlays/ChangelogOverlay.cs +++ b/osu.Game/Overlays/ChangelogOverlay.cs @@ -34,6 +34,8 @@ namespace osu.Game.Overlays private List builds; + private List streams; + [BackgroundDependencyLoader] private void load(AudioManager audio, OsuColour colour) { @@ -87,7 +89,11 @@ namespace osu.Game.Overlays }); } - public void ShowListing() => Current.Value = null; + public void ShowListing() + { + Current.Value = null; + State = Visibility.Visible; + } /// /// Fetches and shows a specific build from a specific update stream. @@ -100,6 +106,27 @@ namespace osu.Game.Overlays 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 @@ namespace osu.Game.Overlays { 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(); + + initialFetchTask = tcs.Task; Task.Run(() => { @@ -147,14 +182,17 @@ namespace osu.Game.Overlays 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;