diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index dcafa94171..119e92cd12 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -52,6 +52,7 @@ namespace MediaBrowser.WebDashboard.Api [Route("/dashboard/Package", "GET")] public class GetDashboardPackage { + public string Mode { get; set; } } /// @@ -134,7 +135,7 @@ namespace MediaBrowser.WebDashboard.Api { var page = ServerEntryPoint.Instance.PluginConfigurationPages.First(p => p.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); - return ResultFactory.GetStaticResult(Request, page.Plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => GetPackageCreator().ModifyHtml(page.GetHtmlStream(), null, false)); + return ResultFactory.GetStaticResult(Request, page.Plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => GetPackageCreator().ModifyHtml(page.GetHtmlStream(), null, null, false)); } /// @@ -252,7 +253,7 @@ namespace MediaBrowser.WebDashboard.Api var minify = _serverConfigurationManager.Configuration.EnableDashboardResourceMinification; return GetPackageCreator() - .GetResource(path, localizationCulture, _appHost.ApplicationVersion.ToString(), minify); + .GetResource(path, null, localizationCulture, _appHost.ApplicationVersion.ToString(), minify); } private PackageCreator GetPackageCreator() @@ -292,38 +293,40 @@ namespace MediaBrowser.WebDashboard.Api var appVersion = DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture); - await DumpHtml(creator.DashboardUIPath, path, culture, appVersion); - await DumpJs(creator.DashboardUIPath, path, culture, appVersion); + var mode = request.Mode; - await DumpFile("scripts/all.js", Path.Combine(path, "scripts", "all.js"), culture, appVersion).ConfigureAwait(false); - await DumpFile("css/all.css", Path.Combine(path, "css", "all.css"), culture, appVersion).ConfigureAwait(false); + await DumpHtml(creator.DashboardUIPath, path, mode, culture, appVersion); + await DumpJs(creator.DashboardUIPath, path, mode, culture, appVersion); + + await DumpFile("scripts/all.js", Path.Combine(path, "scripts", "all.js"), mode, culture, appVersion).ConfigureAwait(false); + await DumpFile("css/all.css", Path.Combine(path, "css", "all.css"), mode, culture, appVersion).ConfigureAwait(false); return ""; } - private async Task DumpHtml(string source, string destination, string culture, string appVersion) + private async Task DumpHtml(string source, string destination, string mode, string culture, string appVersion) { foreach (var file in Directory.GetFiles(source, "*.html", SearchOption.TopDirectoryOnly)) { var filename = Path.GetFileName(file); - await DumpFile(filename, Path.Combine(destination, filename), culture, appVersion).ConfigureAwait(false); + await DumpFile(filename, Path.Combine(destination, filename), mode, culture, appVersion).ConfigureAwait(false); } } - private async Task DumpJs(string source, string destination, string culture, string appVersion) + private async Task DumpJs(string source, string mode, string destination, string culture, string appVersion) { foreach (var file in Directory.GetFiles(source, "*.js", SearchOption.TopDirectoryOnly)) { var filename = Path.GetFileName(file); - await DumpFile("scripts/" + filename, Path.Combine(destination, "scripts", filename), culture, appVersion).ConfigureAwait(false); + await DumpFile("scripts/" + filename, Path.Combine(destination, "scripts", filename), mode, culture, appVersion).ConfigureAwait(false); } } - private async Task DumpFile(string resourceVirtualPath, string destinationFilePath, string culture, string appVersion) + private async Task DumpFile(string resourceVirtualPath, string destinationFilePath, string mode, string culture, string appVersion) { - using (var stream = await GetPackageCreator().GetResource(resourceVirtualPath, culture, appVersion, true).ConfigureAwait(false)) + using (var stream = await GetPackageCreator().GetResource(resourceVirtualPath, mode, culture, appVersion, true).ConfigureAwait(false)) { using (var fs = _fileSystem.GetFileStream(destinationFilePath, FileMode.Create, FileAccess.Write, FileShare.Read)) { diff --git a/MediaBrowser.WebDashboard/Api/PackageCreator.cs b/MediaBrowser.WebDashboard/Api/PackageCreator.cs index 8f4d2ae8b7..26f2f8babd 100644 --- a/MediaBrowser.WebDashboard/Api/PackageCreator.cs +++ b/MediaBrowser.WebDashboard/Api/PackageCreator.cs @@ -32,8 +32,10 @@ namespace MediaBrowser.WebDashboard.Api } public async Task GetResource(string path, + string mode, string localizationCulture, - string appVersion, bool enableMinification) + string appVersion, + bool enableMinification) { var isHtml = IsHtml(path); @@ -41,7 +43,7 @@ namespace MediaBrowser.WebDashboard.Api if (path.Equals("scripts/all.js", StringComparison.OrdinalIgnoreCase)) { - resourceStream = await GetAllJavascript(localizationCulture, appVersion, enableMinification).ConfigureAwait(false); + resourceStream = await GetAllJavascript(mode, localizationCulture, appVersion, enableMinification).ConfigureAwait(false); } else if (path.Equals("css/all.css", StringComparison.OrdinalIgnoreCase)) { @@ -58,7 +60,7 @@ namespace MediaBrowser.WebDashboard.Api // jQuery ajax doesn't seem to handle if-modified-since correctly if (isHtml) { - resourceStream = await ModifyHtml(resourceStream, localizationCulture, enableMinification).ConfigureAwait(false); + resourceStream = await ModifyHtml(resourceStream, mode, localizationCulture, enableMinification).ConfigureAwait(false); } } @@ -106,10 +108,11 @@ namespace MediaBrowser.WebDashboard.Api /// Modifies the HTML by adding common meta tags, css and js. /// /// The source stream. + /// The mode. /// The localization culture. /// if set to true [enable minification]. /// Task{Stream}. - public async Task ModifyHtml(Stream sourceStream, string localizationCulture, bool enableMinification) + public async Task ModifyHtml(Stream sourceStream, string mode, string localizationCulture, bool enableMinification) { using (sourceStream) { @@ -155,7 +158,7 @@ namespace MediaBrowser.WebDashboard.Api var version = GetType().Assembly.GetName().Version; - html = html.Replace("", "" + GetMetaTags() + GetCommonCss(version) + GetCommonJavascript(version)); + html = html.Replace("", "" + GetMetaTags(mode) + GetCommonCss(mode, version) + GetCommonJavascript(mode, version)); var bytes = Encoding.UTF8.GetBytes(html); @@ -172,12 +175,19 @@ namespace MediaBrowser.WebDashboard.Api /// Gets the meta tags. /// /// System.String. - private static string GetMetaTags() + private static string GetMetaTags(string mode) { var sb = new StringBuilder(); + if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase)) + { + sb.Append(""); + } + sb.Append(""); - sb.Append(""); + sb.Append(""); + sb.Append(""); + sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); @@ -200,11 +210,12 @@ namespace MediaBrowser.WebDashboard.Api /// /// Gets the common CSS. /// + /// The mode. /// The version. /// System.String. - private string GetCommonCss(Version version) + private string GetCommonCss(string mode, Version version) { - var versionString = "?v=" + version; + var versionString = !string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase) ? "?v=" + version : string.Empty; var files = new[] { @@ -223,20 +234,26 @@ namespace MediaBrowser.WebDashboard.Api /// /// Gets the common javascript. /// + /// The mode. /// The version. /// System.String. - private string GetCommonJavascript(Version version) + private string GetCommonJavascript(string mode, Version version) { var builder = new StringBuilder(); - var versionString = "?v=" + version; + var versionString = !string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase) ? "?v=" + version : string.Empty; - var files = new[] - { - "scripts/all.js" + versionString, - "thirdparty/swipebox-master/js/jquery.swipebox.min.js" + versionString + var files = new List + { + "scripts/all.js" + versionString, + "thirdparty/swipebox-master/js/jquery.swipebox.min.js" + versionString }; + if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase)) + { + files.Insert(0, "cordova.js"); + } + var tags = files.Select(s => string.Format("", s)).ToArray(); builder.Append(string.Join(string.Empty, tags)); @@ -248,7 +265,7 @@ namespace MediaBrowser.WebDashboard.Api /// Gets a stream containing all concatenated javascript /// /// Task{Stream}. - private async Task GetAllJavascript(string culture, string version, bool enableMinification) + private async Task GetAllJavascript(string mode, string culture, string version, bool enableMinification) { var memoryStream = new MemoryStream(); var newLineBytes = Encoding.UTF8.GetBytes(Environment.NewLine); @@ -267,6 +284,12 @@ namespace MediaBrowser.WebDashboard.Api await AppendLocalization(memoryStream, culture).ConfigureAwait(false); await memoryStream.WriteAsync(newLineBytes, 0, newLineBytes.Length).ConfigureAwait(false); + if (!string.IsNullOrWhiteSpace(mode)) + { + var appModeBytes = Encoding.UTF8.GetBytes(string.Format("window.appMode='{0}';", mode)); + await memoryStream.WriteAsync(appModeBytes, 0, appModeBytes.Length).ConfigureAwait(false); + } + // Write the version string for the dashboard comparison function var versionString = string.Format("window.dashboardVersion='{0}';", version); var versionBytes = Encoding.UTF8.GetBytes(versionString);