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:
parent
99f2b07a11
commit
eff7c4b7b7
@ -1,18 +1,11 @@
|
|||||||
using Nancy;
|
using Nancy;
|
||||||
using Nancy.Bootstrapper;
|
using Nancy.Bootstrapper;
|
||||||
using NzbDrone.Api.Frontend;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
namespace NzbDrone.Api.Extensions.Pipelines
|
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)
|
public void Register(IPipelines pipelines)
|
||||||
{
|
{
|
||||||
pipelines.AfterRequest.AddItemToStartOfPipeline(Handle);
|
pipelines.AfterRequest.AddItemToStartOfPipeline(Handle);
|
||||||
@ -20,14 +13,7 @@ public void Register(IPipelines pipelines)
|
|||||||
|
|
||||||
private void Handle(NancyContext context)
|
private void Handle(NancyContext context)
|
||||||
{
|
{
|
||||||
if (_cacheableSpecification.IsCacheable(context))
|
context.Response.Headers.Add("X-ApplicationVersion", BuildInfo.Version.ToString());
|
||||||
{
|
|
||||||
context.Response.Headers.EnableCache();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.Headers.DisableCache();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -122,6 +122,7 @@
|
|||||||
<Compile Include="Episodes\RenameEpisodeModule.cs" />
|
<Compile Include="Episodes\RenameEpisodeModule.cs" />
|
||||||
<Compile Include="Episodes\RenameEpisodeResource.cs" />
|
<Compile Include="Episodes\RenameEpisodeResource.cs" />
|
||||||
<Compile Include="Extensions\Pipelines\CacheHeaderPipeline.cs" />
|
<Compile Include="Extensions\Pipelines\CacheHeaderPipeline.cs" />
|
||||||
|
<Compile Include="Extensions\Pipelines\NzbDroneVersionPipeline.cs" />
|
||||||
<Compile Include="Extensions\Pipelines\GZipPipeline.cs" />
|
<Compile Include="Extensions\Pipelines\GZipPipeline.cs" />
|
||||||
<Compile Include="Extensions\Pipelines\IfModifiedPipeline.cs" />
|
<Compile Include="Extensions\Pipelines\IfModifiedPipeline.cs" />
|
||||||
<Compile Include="Extensions\Pipelines\IRegisterNancyPipeline.cs" />
|
<Compile Include="Extensions\Pipelines\IRegisterNancyPipeline.cs" />
|
||||||
|
@ -101,6 +101,7 @@
|
|||||||
<Compile Include="AccessControl\FirewallAdapter.cs" />
|
<Compile Include="AccessControl\FirewallAdapter.cs" />
|
||||||
<Compile Include="AccessControl\UrlAclAdapter.cs" />
|
<Compile Include="AccessControl\UrlAclAdapter.cs" />
|
||||||
<Compile Include="BrowserService.cs" />
|
<Compile Include="BrowserService.cs" />
|
||||||
|
<Compile Include="Owin\MiddleWare\NzbDroneVersionMiddleWare.cs" />
|
||||||
<Compile Include="SpinService.cs" />
|
<Compile Include="SpinService.cs" />
|
||||||
<Compile Include="SingleInstancePolicy.cs" />
|
<Compile Include="SingleInstancePolicy.cs" />
|
||||||
<Compile Include="IUserAlert.cs" />
|
<Compile Include="IUserAlert.cs" />
|
||||||
|
@ -13,7 +13,7 @@ public NancyMiddleWare(INancyBootstrapper nancyBootstrapper)
|
|||||||
_nancyBootstrapper = nancyBootstrapper;
|
_nancyBootstrapper = nancyBootstrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Order { get { return 1; } }
|
public int Order { get { return 2; } }
|
||||||
|
|
||||||
public void Attach(IAppBuilder appBuilder)
|
public void Attach(IAppBuilder appBuilder)
|
||||||
{
|
{
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@ namespace NzbDrone.Host.Owin.MiddleWare
|
|||||||
{
|
{
|
||||||
public class SignalRMiddleWare : IOwinMiddleWare
|
public class SignalRMiddleWare : IOwinMiddleWare
|
||||||
{
|
{
|
||||||
public int Order { get { return 0; } }
|
public int Order { get { return 1; } }
|
||||||
|
|
||||||
public SignalRMiddleWare(IContainer container)
|
public SignalRMiddleWare(IContainer container)
|
||||||
{
|
{
|
||||||
|
@ -28,6 +28,29 @@ define(
|
|||||||
xhr.headers['X-Api-Key'] = window.NzbDrone.ApiKey;
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,7 @@ define(
|
|||||||
|
|
||||||
series: function () {
|
series: function () {
|
||||||
this.setTitle('NzbDrone');
|
this.setTitle('NzbDrone');
|
||||||
AppLayout.mainRegion.show(new SeriesIndexLayout());
|
this.showMainRegion(new SeriesIndexLayout());
|
||||||
},
|
},
|
||||||
|
|
||||||
seriesDetails: function (query) {
|
seriesDetails: function (query) {
|
||||||
@ -28,7 +28,7 @@ define(
|
|||||||
if (series.length !== 0) {
|
if (series.length !== 0) {
|
||||||
var targetSeries = series[0];
|
var targetSeries = series[0];
|
||||||
this.setTitle(targetSeries.get('title'));
|
this.setTitle(targetSeries.get('title'));
|
||||||
AppLayout.mainRegion.show(new SeriesDetailsLayout({ model: targetSeries }));
|
this.showMainRegion(new SeriesDetailsLayout({ model: targetSeries }));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showNotFound();
|
this.showNotFound();
|
||||||
|
@ -50,15 +50,6 @@ define(
|
|||||||
|
|
||||||
this.signalRconnection.reconnected(function() {
|
this.signalRconnection.reconnected(function() {
|
||||||
tryingToReconnect = false;
|
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 () {
|
this.signalRconnection.disconnected(function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user