mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 16:12:54 +08:00
Move post-update notification logic to UpdateManager base class
This commit is contained in:
parent
c6fe8587e3
commit
1c474de0ed
@ -17,6 +17,7 @@ using osu.Framework.Logging;
|
|||||||
using osu.Framework.Platform.Windows;
|
using osu.Framework.Platform.Windows;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Screens.Menu;
|
using osu.Game.Screens.Menu;
|
||||||
|
using osu.Game.Updater;
|
||||||
|
|
||||||
namespace osu.Desktop
|
namespace osu.Desktop
|
||||||
{
|
{
|
||||||
|
@ -8,11 +8,8 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Game;
|
using osu.Game;
|
||||||
using osu.Game.Configuration;
|
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Overlays;
|
|
||||||
using osu.Game.Overlays.Notifications;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -20,17 +17,9 @@ namespace osu.Desktop.Overlays
|
|||||||
{
|
{
|
||||||
public class VersionManager : OverlayContainer
|
public class VersionManager : OverlayContainer
|
||||||
{
|
{
|
||||||
private OsuConfigManager config;
|
|
||||||
private OsuGameBase game;
|
|
||||||
private NotificationOverlay notificationOverlay;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[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;
|
AutoSizeAxes = Axes.Both;
|
||||||
Anchor = Anchor.BottomCentre;
|
Anchor = Anchor.BottomCentre;
|
||||||
Origin = Anchor.BottomCentre;
|
Origin = Anchor.BottomCentre;
|
||||||
@ -85,48 +74,6 @@ namespace osu.Desktop.Overlays
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
protected override void PopIn()
|
||||||
{
|
{
|
||||||
this.FadeIn(1400, Easing.OutQuint);
|
this.FadeIn(1400, Easing.OutQuint);
|
||||||
|
@ -20,7 +20,7 @@ using LogLevel = Splat.LogLevel;
|
|||||||
|
|
||||||
namespace osu.Desktop.Updater
|
namespace osu.Desktop.Updater
|
||||||
{
|
{
|
||||||
public class SquirrelUpdateManager : Component
|
public class SquirrelUpdateManager : osu.Game.Updater.UpdateManager
|
||||||
{
|
{
|
||||||
private UpdateManager updateManager;
|
private UpdateManager updateManager;
|
||||||
private NotificationOverlay notificationOverlay;
|
private NotificationOverlay notificationOverlay;
|
||||||
|
@ -6,31 +6,25 @@ using System.Threading.Tasks;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.IO.Network;
|
using osu.Framework.IO.Network;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game;
|
|
||||||
using osu.Game.Overlays;
|
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
|
|
||||||
namespace osu.Desktop.Updater
|
namespace osu.Game.Updater
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An update manager that shows notifications if a newer release is detected.
|
/// An update manager that shows notifications if a newer release is detected.
|
||||||
/// Installation is left up to the user.
|
/// Installation is left up to the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class SimpleUpdateManager : CompositeDrawable
|
public class SimpleUpdateManager : UpdateManager
|
||||||
{
|
{
|
||||||
private NotificationOverlay notificationOverlay;
|
|
||||||
private string version;
|
private string version;
|
||||||
private GameHost host;
|
private GameHost host;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(NotificationOverlay notification, OsuGameBase game, GameHost host)
|
private void load(OsuGameBase game, GameHost host)
|
||||||
{
|
{
|
||||||
notificationOverlay = notification;
|
|
||||||
|
|
||||||
this.host = host;
|
this.host = host;
|
||||||
version = game.Version;
|
version = game.Version;
|
||||||
|
|
||||||
@ -50,7 +44,7 @@ namespace osu.Desktop.Updater
|
|||||||
|
|
||||||
if (latest.TagName != version)
|
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"
|
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",
|
+ "Click here to download the new version, which can be installed over the top of your existing installation",
|
||||||
@ -82,6 +76,10 @@ namespace osu.Desktop.Updater
|
|||||||
case RuntimeInfo.Platform.MacOsx:
|
case RuntimeInfo.Platform.MacOsx:
|
||||||
bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".app.zip"));
|
bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".app.zip"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RuntimeInfo.Platform.Android:
|
||||||
|
bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".apk"));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bestAsset?.BrowserDownloadUrl ?? release.HtmlUrl;
|
return bestAsset?.BrowserDownloadUrl ?? release.HtmlUrl;
|
67
osu.Game/Updater/UpdateManager.cs
Normal file
67
osu.Game/Updater/UpdateManager.cs
Normal file
@ -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; 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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user