Skip to content

Commit

Permalink
Move post-update notification logic to UpdateManager base class
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Sep 24, 2019
1 parent 79b64bd commit 42b6041
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 65 deletions.
1 change: 1 addition & 0 deletions osu.Desktop/OsuGameDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using osu.Framework.Platform.Windows;
using osu.Framework.Screens;
using osu.Game.Screens.Menu;
using osu.Game.Updater;

namespace osu.Desktop
{
Expand Down
55 changes: 1 addition & 54 deletions osu.Desktop/Overlays/VersionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,18 @@
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osuTK;
using osuTK.Graphics;

namespace osu.Desktop.Overlays
{
public class VersionManager : OverlayContainer
{
private OsuConfigManager config;
private OsuGameBase game;
private NotificationOverlay notificationOverlay;

[BackgroundDependencyLoader]
private void load(NotificationOverlay notification, OsuColour colours, TextureStore textures, OsuGameBase game, OsuConfigManager config)
private void load(OsuColour colours, TextureStore textures, OsuGameBase game)
{
notificationOverlay = notification;
this.config = config;
this.game = game;

AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
Expand Down Expand Up @@ -85,48 +74,6 @@ private void load(NotificationOverlay notification, OsuColour colours, TextureSt
};
}

protected override void LoadComplete()
{
base.LoadComplete();

var version = game.Version;
var lastVersion = config.Get<string>(OsuSetting.Version);

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));
}
}

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;
};
}
}

protected override void PopIn()
{
this.FadeIn(1400, Easing.OutQuint);
Expand Down
2 changes: 1 addition & 1 deletion osu.Desktop/Updater/SquirrelUpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace osu.Desktop.Updater
{
public class SquirrelUpdateManager : Component
public class SquirrelUpdateManager : osu.Game.Updater.UpdateManager
{
private UpdateManager updateManager;
private NotificationOverlay notificationOverlay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,25 @@
using Newtonsoft.Json;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.IO.Network;
using osu.Framework.Platform;
using osu.Game;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;

namespace osu.Desktop.Updater
namespace osu.Game.Updater
{
/// <summary>
/// An update manager that shows notifications if a newer release is detected.
/// Installation is left up to the user.
/// </summary>
internal class SimpleUpdateManager : CompositeDrawable
public class SimpleUpdateManager : UpdateManager
{
private NotificationOverlay notificationOverlay;
private string version;
private GameHost host;

[BackgroundDependencyLoader]
private void load(NotificationOverlay notification, OsuGameBase game, GameHost host)
private void load(OsuGameBase game, GameHost host)
{
notificationOverlay = notification;

this.host = host;
version = game.Version;

Expand All @@ -50,7 +44,7 @@ private async void checkForUpdateAsync()

if (latest.TagName != version)
{
notificationOverlay.Post(new SimpleNotification
Notifications.Post(new SimpleNotification
{
Text = $"A newer release of osu! has been found ({version}{latest.TagName}).\n\n"
+ "Click here to download the new version, which can be installed over the top of your existing installation",
Expand Down Expand Up @@ -82,6 +76,10 @@ private string getBestUrl(GitHubRelease release)
case RuntimeInfo.Platform.MacOsx:
bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".app.zip"));
break;

case RuntimeInfo.Platform.Android:
bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".apk"));
break;
}

return bestAsset?.BrowserDownloadUrl ?? release.HtmlUrl;
Expand Down
67 changes: 67 additions & 0 deletions osu.Game/Updater/UpdateManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 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
{
public abstract class UpdateManager : CompositeDrawable
{
[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();

var version = game.Version;
var lastVersion = config.Get<string>(OsuSetting.Version);

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))
Notifications.Post(new UpdateCompleteNotification(version));
}
}

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;
};
}
}
}
}

0 comments on commit 42b6041

Please sign in to comment.