Merge branch 'master' into chat-improvement

This commit is contained in:
Thomas Müller 2017-02-22 07:36:42 +01:00 committed by GitHub
commit 44bedb5407
4 changed files with 96 additions and 32 deletions

View File

@ -1,9 +1,12 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -16,13 +19,14 @@ using osu.Game.Graphics;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using System.Net.Http; using System.Net.Http;
using osu.Framework.Logging;
namespace osu.Desktop.Overlays namespace osu.Desktop.Overlays
{ {
public class VersionManager : OverlayContainer public class VersionManager : OverlayContainer
{ {
private UpdateManager updateManager; private UpdateManager updateManager;
private NotificationManager notification; private NotificationManager notificationManager;
AssemblyName assembly = Assembly.GetEntryAssembly().GetName(); AssemblyName assembly = Assembly.GetEntryAssembly().GetName();
@ -35,7 +39,7 @@ namespace osu.Desktop.Overlays
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(NotificationManager notification, OsuColour colours, TextureStore textures) private void load(NotificationManager notification, OsuColour colours, TextureStore textures)
{ {
this.notification = notification; this.notificationManager = notification;
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomCentre; Anchor = Anchor.BottomCentre;
@ -114,41 +118,71 @@ namespace osu.Desktop.Overlays
updateManager?.Dispose(); updateManager?.Dispose();
} }
private async void updateChecker() private async void updateChecker(bool useDeltaPatching = true, UpdateProgressNotification notification = null)
{ {
//should we schedule a retry on completion of this check?
bool scheduleRetry = true;
try try
{ {
updateManager = await UpdateManager.GitHubUpdateManager(@"https://github.com/ppy/osu", @"osulazer", null, null, true); if (updateManager == null) updateManager = await UpdateManager.GitHubUpdateManager(@"https://github.com/ppy/osu", @"osulazer", null, null, true);
}
catch(HttpRequestException)
{
//check again every 30 minutes.
Scheduler.AddDelayed(updateChecker, 60000 * 30);
return;
}
if (!updateManager.IsInstalledApp) var info = await updateManager.CheckForUpdate(!useDeltaPatching);
return; if (info.ReleasesToApply.Count == 0)
//no updates available. bail and retry later.
return;
var info = await updateManager.CheckForUpdate(); if (notification == null)
if (info.ReleasesToApply.Count > 0)
{
ProgressNotification n = new UpdateProgressNotification
{ {
Text = @"Downloading update..." notification = new UpdateProgressNotification { State = ProgressNotificationState.Active };
}; Schedule(() => notificationManager.Post(notification));
Schedule(() => notification.Post(n)); }
Schedule(() => n.State = ProgressNotificationState.Active);
await updateManager.DownloadReleases(info.ReleasesToApply, (int p) => Schedule(() => n.Progress = p / 100f));
Schedule(() => n.Text = @"Installing update...");
await updateManager.ApplyReleases(info, (int p) => Schedule(() => n.Progress = p / 100f));
Schedule(() => n.State = ProgressNotificationState.Completed);
Schedule(() =>
{
notification.Progress = 0;
notification.Text = @"Downloading update...";
});
try
{
await updateManager.DownloadReleases(info.ReleasesToApply, p => Schedule(() => notification.Progress = p / 100f));
Schedule(() =>
{
notification.Progress = 0;
notification.Text = @"Installing update...";
});
await updateManager.ApplyReleases(info, p => Schedule(() => notification.Progress = p / 100f));
Schedule(() => notification.State = ProgressNotificationState.Completed);
}
catch (Exception)
{
if (useDeltaPatching)
{
//could fail if deltas are unavailable for full update path (https://github.com/Squirrel/Squirrel.Windows/issues/959)
//try again without deltas.
updateChecker(false, notification);
scheduleRetry = false;
}
}
} }
else catch (HttpRequestException)
{ {
//check again every 30 minutes. //likely have no internet connection.
Scheduler.AddDelayed(updateChecker, 60000 * 30); //we'll ignore this and retry later.
}
finally
{
if (scheduleRetry)
{
//check again in 30 minutes.
Scheduler.AddDelayed(() => updateChecker(), 60000 * 30);
if (notification != null)
notification.State = ProgressNotificationState.Cancelled;
}
} }
} }
@ -172,6 +206,25 @@ namespace osu.Desktop.Overlays
return true; return true;
} }
}; };
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
IconContent.Add(new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
ColourInfo = ColourInfo.GradientVertical(colours.YellowDark, colours.Yellow)
},
new TextAwesome
{
Anchor = Anchor.Centre,
Icon = FontAwesome.fa_upload,
Colour = Color4.White,
}
});
}
} }
} }
} }

View File

@ -89,7 +89,6 @@ namespace osu.Game.Overlays.Notifications
IconContent = new Container IconContent = new Container
{ {
Size = new Vector2(40), Size = new Vector2(40),
Colour = Color4.DarkGray,
Masking = true, Masking = true,
CornerRadius = 5, CornerRadius = 5,
}, },

View File

@ -1,7 +1,11 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Framework.Graphics.Colour;
using OpenTK.Graphics;
namespace osu.Game.Overlays.Notifications namespace osu.Game.Overlays.Notifications
{ {
@ -14,5 +18,11 @@ namespace osu.Game.Overlays.Notifications
this.progressNotification = progressNotification; this.progressNotification = progressNotification;
Icon = FontAwesome.fa_check; Icon = FontAwesome.fa_check;
} }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
IconBackgound.ColourInfo = ColourInfo.GradientVertical(colours.GreenDark, colours.GreenLight);
}
} }
} }

View File

@ -37,19 +37,21 @@ namespace osu.Game.Overlays.Notifications
private SpriteText textDrawable; private SpriteText textDrawable;
private TextAwesome iconDrawable; private TextAwesome iconDrawable;
protected Box IconBackgound;
public SimpleNotification() public SimpleNotification()
{ {
IconContent.Add(new Drawable[] IconContent.Add(new Drawable[]
{ {
new Box IconBackgound = new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ColourInfo = ColourInfo.GradientVertical(OsuColour.Gray(0.2f), OsuColour.Gray(0.5f)) ColourInfo = ColourInfo.GradientVertical(OsuColour.Gray(0.2f), OsuColour.Gray(0.6f))
}, },
iconDrawable = new TextAwesome iconDrawable = new TextAwesome
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Icon = icon , Icon = icon,
} }
}); });