1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-28 00:47:20 +08:00

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. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -96,33 +95,37 @@ namespace osu.Desktop.Overlays
var version = game.Version; var version = game.Version;
var lastVersion = config.Get<string>(OsuSetting.Version); var lastVersion = config.Get<string>(OsuSetting.Version);
if (game.IsDeployedBuild && version != lastVersion) //if (game.IsDeployedBuild && version != lastVersion)
{ {
config.Set(OsuSetting.Version, version); 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). // only show a notification if we've previously saved a version to the config file (ie. not the first run).
if (!string.IsNullOrEmpty(lastVersion)) if (!string.IsNullOrEmpty(lastVersion))
notificationOverlay.Post(new UpdateCompleteNotification(version, host.OpenUrlExternally)); notificationOverlay.Post(new UpdateCompleteNotification(version));
} }
} }
private class UpdateCompleteNotification : SimpleNotification 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!"; 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] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours, ChangelogOverlay changelog)
{ {
Icon = FontAwesome.Solid.CheckSquare;
IconBackgound.Colour = colours.BlueDark; IconBackgound.Colour = colours.BlueDark;
Activated = delegate
{
changelog.ShowBuild("lazer", version);
return true;
};
} }
} }

View File

@ -34,6 +34,8 @@ namespace osu.Game.Overlays
private List<APIChangelogBuild> builds; private List<APIChangelogBuild> builds;
private List<APIUpdateStream> streams;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colour) 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;
}
/// <summary> /// <summary>
/// Fetches and shows a specific build from a specific update stream. /// 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)); if (build == null) throw new ArgumentNullException(nameof(build));
Current.Value = 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) public override bool OnPressed(GlobalAction action)
@ -127,15 +154,23 @@ namespace osu.Game.Overlays
{ {
base.PopIn(); base.PopIn();
if (!initialFetchPerformed) if (initialFetchTask == null)
fetchListing(); // 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(() => 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)); res.Streams.ForEach(s => s.LatestBuild.UpdateStream = res.Streams.Find(s2 => s2.Id == s.LatestBuild.UpdateStream.Id));
builds = res.Builds; builds = res.Builds;
streams = res.Streams;
header.Streams.Populate(res.Streams); header.Streams.Populate(res.Streams);
Current.TriggerChange(); tcs.SetResult(true);
}; };
req.Failure += _ => initialFetchPerformed = false; req.Failure += _ => initialFetchTask = null;
req.Perform(API); req.Perform(API);
}); });
return initialFetchTask;
} }
private CancellationTokenSource loadContentTask; private CancellationTokenSource loadContentTask;