diff --git a/src/NzbDrone.Api/Frontend/Mappers/IndexHtmlMapper.cs b/src/NzbDrone.Api/Frontend/Mappers/IndexHtmlMapper.cs index 3b2b30cb9..a8172845a 100644 --- a/src/NzbDrone.Api/Frontend/Mappers/IndexHtmlMapper.cs +++ b/src/NzbDrone.Api/Frontend/Mappers/IndexHtmlMapper.cs @@ -6,6 +6,7 @@ using Nancy; using NLog; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Core.Analytics; using NzbDrone.Core.Configuration; namespace NzbDrone.Api.Frontend.Mappers @@ -14,6 +15,7 @@ namespace NzbDrone.Api.Frontend.Mappers { private readonly IDiskProvider _diskProvider; private readonly IConfigFileProvider _configFileProvider; + private readonly IAnalyticsService _analyticsService; private readonly Func _cacheBreakProviderFactory; private readonly string _indexPath; private static readonly Regex ReplaceRegex = new Regex("(?<=(?:href|src|data-main)=\").*?(?=\")", RegexOptions.Compiled | RegexOptions.IgnoreCase); @@ -26,12 +28,14 @@ namespace NzbDrone.Api.Frontend.Mappers public IndexHtmlMapper(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, IConfigFileProvider configFileProvider, + IAnalyticsService analyticsService, Func cacheBreakProviderFactory, Logger logger) : base(diskProvider, logger) { _diskProvider = diskProvider; _configFileProvider = configFileProvider; + _analyticsService = analyticsService; _cacheBreakProviderFactory = cacheBreakProviderFactory; _indexPath = Path.Combine(appFolderInfo.StartUpFolder, "UI", "index.html"); @@ -89,7 +93,8 @@ namespace NzbDrone.Api.Frontend.Mappers text = text.Replace("API_ROOT", URL_BASE + "/api"); text = text.Replace("API_KEY", API_KEY); text = text.Replace("APP_VERSION", BuildInfo.Version.ToString()); - text = text.Replace("APP_ANALYTICS", _configFileProvider.AnalyticsEnabled.ToString().ToLowerInvariant()); + + text = text.Replace("APP_ANALYTICS", _analyticsService.IsEnabled.ToString().ToLowerInvariant()); _generatedContent = text; diff --git a/src/NzbDrone.Core/Analytics/AnalyticsService.cs b/src/NzbDrone.Core/Analytics/AnalyticsService.cs new file mode 100644 index 000000000..8901817a9 --- /dev/null +++ b/src/NzbDrone.Core/Analytics/AnalyticsService.cs @@ -0,0 +1,28 @@ +using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Core.Configuration; + +namespace NzbDrone.Core.Analytics +{ + public interface IAnalyticsService + { + bool IsEnabled { get; } + } + + public class AnalyticsService : IAnalyticsService + { + private readonly IConfigFileProvider _configFileProvider; + + public AnalyticsService(IConfigFileProvider configFileProvider) + { + _configFileProvider = configFileProvider; + } + + public bool IsEnabled + { + get + { + return _configFileProvider.AnalyticsEnabled && RuntimeInfoBase.IsProduction; + } + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 459a5b9f8..e6140d5a2 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -109,6 +109,7 @@ Properties\SharedAssemblyInfo.cs +