From 1fcfb88d2aa0126c4b3c878c8e310311ea57d04d Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 26 Oct 2024 20:48:00 -0700 Subject: [PATCH] New: Use instance name in PWA manifest Closes #7315 --- frontend/src/Content/manifest.json | 2 +- .../Frontend/Mappers/ManifestMapper.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/frontend/src/Content/manifest.json b/frontend/src/Content/manifest.json index 5cb58dc0d..5c2b3d59d 100644 --- a/frontend/src/Content/manifest.json +++ b/frontend/src/Content/manifest.json @@ -1,5 +1,5 @@ { - "name": "Sonarr", + "name": "__INSTANCE_NAME__", "icons": [ { "src": "__URL_BASE__/Content/Images/Icons/android-chrome-192x192.png", diff --git a/src/Sonarr.Http/Frontend/Mappers/ManifestMapper.cs b/src/Sonarr.Http/Frontend/Mappers/ManifestMapper.cs index 424af1cda..ca69d0430 100644 --- a/src/Sonarr.Http/Frontend/Mappers/ManifestMapper.cs +++ b/src/Sonarr.Http/Frontend/Mappers/ManifestMapper.cs @@ -8,9 +8,14 @@ namespace Sonarr.Http.Frontend.Mappers { public class ManifestMapper : UrlBaseReplacementResourceMapperBase { + private readonly IConfigFileProvider _configFileProvider; + + private string _generatedContent; + public ManifestMapper(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, IConfigFileProvider configFileProvider, Logger logger) : base(diskProvider, configFileProvider, logger) { + _configFileProvider = configFileProvider; FilePath = Path.Combine(appFolderInfo.StartUpFolder, configFileProvider.UiFolder, "Content", "manifest.json"); } @@ -23,5 +28,21 @@ namespace Sonarr.Http.Frontend.Mappers { return resourceUrl.StartsWith("/Content/manifest"); } + + protected override string GetFileText() + { + if (RuntimeInfo.IsProduction && _generatedContent != null) + { + return _generatedContent; + } + + var text = base.GetFileText(); + + text = text.Replace("__INSTANCE_NAME__", _configFileProvider.InstanceName); + + _generatedContent = text; + + return _generatedContent; + } } }