1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Auto reload when server has been updated

New: Updating will reload UI on navigation
This commit is contained in:
Mark McDowall 2014-05-11 17:44:42 -07:00
parent 99f2b07a11
commit eff7c4b7b7
10 changed files with 98 additions and 31 deletions

View File

@ -1,18 +1,11 @@
using Nancy;
using Nancy.Bootstrapper;
using NzbDrone.Api.Frontend;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Api.Extensions.Pipelines
{
public class CacheHeaderPipeline : IRegisterNancyPipeline
public class NzbDroneVersionPipeline : IRegisterNancyPipeline
{
private readonly ICacheableSpecification _cacheableSpecification;
public CacheHeaderPipeline(ICacheableSpecification cacheableSpecification)
{
_cacheableSpecification = cacheableSpecification;
}
public void Register(IPipelines pipelines)
{
pipelines.AfterRequest.AddItemToStartOfPipeline(Handle);
@ -20,14 +13,7 @@ public void Register(IPipelines pipelines)
private void Handle(NancyContext context)
{
if (_cacheableSpecification.IsCacheable(context))
{
context.Response.Headers.EnableCache();
}
else
{
context.Response.Headers.DisableCache();
}
context.Response.Headers.Add("X-ApplicationVersion", BuildInfo.Version.ToString());
}
}
}

View File

@ -0,0 +1,33 @@
using Nancy;
using Nancy.Bootstrapper;
using NzbDrone.Api.Frontend;
namespace NzbDrone.Api.Extensions.Pipelines
{
public class CacheHeaderPipeline : IRegisterNancyPipeline
{
private readonly ICacheableSpecification _cacheableSpecification;
public CacheHeaderPipeline(ICacheableSpecification cacheableSpecification)
{
_cacheableSpecification = cacheableSpecification;
}
public void Register(IPipelines pipelines)
{
pipelines.AfterRequest.AddItemToStartOfPipeline(Handle);
}
private void Handle(NancyContext context)
{
if (_cacheableSpecification.IsCacheable(context))
{
context.Response.Headers.EnableCache();
}
else
{
context.Response.Headers.DisableCache();
}
}
}
}

View File

@ -122,6 +122,7 @@
<Compile Include="Episodes\RenameEpisodeModule.cs" />
<Compile Include="Episodes\RenameEpisodeResource.cs" />
<Compile Include="Extensions\Pipelines\CacheHeaderPipeline.cs" />
<Compile Include="Extensions\Pipelines\NzbDroneVersionPipeline.cs" />
<Compile Include="Extensions\Pipelines\GZipPipeline.cs" />
<Compile Include="Extensions\Pipelines\IfModifiedPipeline.cs" />
<Compile Include="Extensions\Pipelines\IRegisterNancyPipeline.cs" />

View File

@ -101,6 +101,7 @@
<Compile Include="AccessControl\FirewallAdapter.cs" />
<Compile Include="AccessControl\UrlAclAdapter.cs" />
<Compile Include="BrowserService.cs" />
<Compile Include="Owin\MiddleWare\NzbDroneVersionMiddleWare.cs" />
<Compile Include="SpinService.cs" />
<Compile Include="SingleInstancePolicy.cs" />
<Compile Include="IUserAlert.cs" />

View File

@ -13,7 +13,7 @@ public NancyMiddleWare(INancyBootstrapper nancyBootstrapper)
_nancyBootstrapper = nancyBootstrapper;
}
public int Order { get { return 1; } }
public int Order { get { return 2; } }
public void Attach(IAppBuilder appBuilder)
{

View File

@ -0,0 +1,32 @@
using System.Threading.Tasks;
using Microsoft.Owin;
using NzbDrone.Common.EnvironmentInfo;
using Owin;
namespace NzbDrone.Host.Owin.MiddleWare
{
public class NzbDroneVersionMiddleWare : IOwinMiddleWare
{
public int Order { get { return 0; } }
public void Attach(IAppBuilder appBuilder)
{
appBuilder.Use(typeof (AddApplicationVersionHeader));
}
}
public class AddApplicationVersionHeader : OwinMiddleware
{
public AddApplicationVersionHeader(OwinMiddleware next)
: base(next)
{
}
public override Task Invoke(OwinRequest request, OwinResponse response)
{
response.AddHeader("X-ApplicationVersion", BuildInfo.Version.ToString());
return Next.Invoke(request, response);
}
}
}

View File

@ -8,7 +8,7 @@ namespace NzbDrone.Host.Owin.MiddleWare
{
public class SignalRMiddleWare : IOwinMiddleWare
{
public int Order { get { return 0; } }
public int Order { get { return 1; } }
public SignalRMiddleWare(IContainer container)
{

View File

@ -28,6 +28,29 @@ define(
xhr.headers['X-Api-Key'] = window.NzbDrone.ApiKey;
}
return original.apply(this, arguments);
return original.apply(this, arguments).done(function (response, status, xhr){
var version = xhr.getResponseHeader('X-ApplicationVersion');
if (!window.NzbDrone || !window.NzbDrone.Version) {
return;
}
if (version !== window.NzbDrone.Version) {
var vent = require('vent');
var messenger = require('Shared/Messenger');
if (!vent || !messenger) {
return;
}
messenger.show({
message : 'NzbDrone has been updated',
hideAfter : 0,
id : 'droneUpdated'
});
vent.trigger(vent.Events.ServerUpdated);
}
});
};
});

View File

@ -19,7 +19,7 @@ define(
series: function () {
this.setTitle('NzbDrone');
AppLayout.mainRegion.show(new SeriesIndexLayout());
this.showMainRegion(new SeriesIndexLayout());
},
seriesDetails: function (query) {
@ -28,7 +28,7 @@ define(
if (series.length !== 0) {
var targetSeries = series[0];
this.setTitle(targetSeries.get('title'));
AppLayout.mainRegion.show(new SeriesDetailsLayout({ model: targetSeries }));
this.showMainRegion(new SeriesDetailsLayout({ model: targetSeries }));
}
else {
this.showNotFound();

View File

@ -50,15 +50,6 @@ define(
this.signalRconnection.reconnected(function() {
tryingToReconnect = false;
var currentVersion = StatusModel.get('version');
var promise = StatusModel.fetch();
promise.done(function () {
if (StatusModel.get('version') !== currentVersion) {
vent.trigger(vent.Events.ServerUpdated);
}
});
});
this.signalRconnection.disconnected(function () {