aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2015-05-16 15:09:02 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2015-05-16 15:09:02 -0400
commitc8a38c139f2d7e854c8dfc9c38641e1ceeff6d9e (patch)
treeaa29157d30c8514dc7f6641ceb7217724e254443
parent477a182efd632d83f8e2c481011fdfc96d82aa0f (diff)
lazy load scripts
-rw-r--r--MediaBrowser.Api/PackageService.cs7
-rw-r--r--MediaBrowser.Api/PluginService.cs20
-rw-r--r--MediaBrowser.Model/Updates/PackageInfo.cs6
-rw-r--r--MediaBrowser.WebDashboard/Api/DashboardService.cs8
-rw-r--r--MediaBrowser.WebDashboard/Api/PackageCreator.cs146
-rw-r--r--MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj6
6 files changed, 180 insertions, 13 deletions
diff --git a/MediaBrowser.Api/PackageService.cs b/MediaBrowser.Api/PackageService.cs
index 1d792fbc1..5ef8b0987 100644
--- a/MediaBrowser.Api/PackageService.cs
+++ b/MediaBrowser.Api/PackageService.cs
@@ -56,6 +56,8 @@ namespace MediaBrowser.Api
[ApiMember(Name = "IsAdult", Description = "Optional. Filter by package that contain adult content.", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
public bool? IsAdult { get; set; }
+
+ public bool? IsAppStoreEnabled { get; set; }
}
/// <summary>
@@ -207,6 +209,11 @@ namespace MediaBrowser.Api
packages = packages.Where(p => p.adult == request.IsAdult.Value);
}
+ if (request.IsAppStoreEnabled.HasValue)
+ {
+ packages = packages.Where(p => p.enableInAppStore == request.IsAppStoreEnabled.Value);
+ }
+
return ToOptimizedResult(packages.ToList());
}
diff --git a/MediaBrowser.Api/PluginService.cs b/MediaBrowser.Api/PluginService.cs
index 4bd78f1f5..2fbf65f3f 100644
--- a/MediaBrowser.Api/PluginService.cs
+++ b/MediaBrowser.Api/PluginService.cs
@@ -25,6 +25,7 @@ namespace MediaBrowser.Api
[Authenticated]
public class GetPlugins : IReturn<List<PluginInfo>>
{
+ public bool? IsAppStoreEnabled { get; set; }
}
/// <summary>
@@ -181,6 +182,7 @@ namespace MediaBrowser.Api
public async Task<object> Get(GetPlugins request)
{
var result = _appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo()).ToList();
+ var requireAppStoreEnabled = request.IsAppStoreEnabled.HasValue && request.IsAppStoreEnabled.Value;
// Don't fail just on account of image url's
try
@@ -197,10 +199,26 @@ namespace MediaBrowser.Api
plugin.ImageUrl = pkg.thumbImage;
}
}
+
+ if (requireAppStoreEnabled)
+ {
+ result = result
+ .Where(plugin =>
+ {
+ var pkg = packages.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.guid) && new Guid(plugin.Id).Equals(new Guid(i.guid)));
+ return pkg != null && pkg.enableInAppStore;
+
+ })
+ .ToList();
+ }
}
catch
{
-
+ // Play it safe here
+ if (requireAppStoreEnabled)
+ {
+ result = new List<PluginInfo>();
+ }
}
return ToOptimizedSerializedResultUsingCache(result);
diff --git a/MediaBrowser.Model/Updates/PackageInfo.cs b/MediaBrowser.Model/Updates/PackageInfo.cs
index 429144f36..5945f87ad 100644
--- a/MediaBrowser.Model/Updates/PackageInfo.cs
+++ b/MediaBrowser.Model/Updates/PackageInfo.cs
@@ -154,6 +154,12 @@ namespace MediaBrowser.Model.Updates
public List<PackageVersionInfo> versions { get; set; }
/// <summary>
+ /// Gets or sets a value indicating whether [enable in application store].
+ /// </summary>
+ /// <value><c>true</c> if [enable in application store]; otherwise, <c>false</c>.</value>
+ public bool enableInAppStore { get; set; }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="PackageInfo"/> class.
/// </summary>
public PackageInfo()
diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs
index 663949459..07d9ed497 100644
--- a/MediaBrowser.WebDashboard/Api/DashboardService.cs
+++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs
@@ -295,6 +295,14 @@ namespace MediaBrowser.WebDashboard.Api
var mode = request.Mode;
+ if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase))
+ {
+ // Overwrite certain files with cordova specific versions
+ var cordovaVersion = Path.Combine(path, "thirdparty", "cordova", "registrationservices.js");
+ File.Copy(cordovaVersion, Path.Combine(path, "scripts", "registrationservices.js"), true);
+ File.Delete(cordovaVersion);
+ }
+
await DumpHtml(creator.DashboardUIPath, path, mode, culture, appVersion);
await DumpJs(creator.DashboardUIPath, path, mode, culture, appVersion);
diff --git a/MediaBrowser.WebDashboard/Api/PackageCreator.cs b/MediaBrowser.WebDashboard/Api/PackageCreator.cs
index f058b421d..52f96e371 100644
--- a/MediaBrowser.WebDashboard/Api/PackageCreator.cs
+++ b/MediaBrowser.WebDashboard/Api/PackageCreator.cs
@@ -38,17 +38,17 @@ namespace MediaBrowser.WebDashboard.Api
string appVersion,
bool enableMinification)
{
- var isHtml = IsHtml(path);
-
Stream resourceStream;
if (path.Equals("scripts/all.js", StringComparison.OrdinalIgnoreCase))
{
resourceStream = await GetAllJavascript(mode, localizationCulture, appVersion, enableMinification).ConfigureAwait(false);
+ enableMinification = false;
}
else if (path.Equals("css/all.css", StringComparison.OrdinalIgnoreCase))
{
resourceStream = await GetAllCss(enableMinification).ConfigureAwait(false);
+ enableMinification = false;
}
else
{
@@ -59,7 +59,7 @@ namespace MediaBrowser.WebDashboard.Api
{
// Don't apply any caching for html pages
// jQuery ajax doesn't seem to handle if-modified-since correctly
- if (isHtml && path.IndexOf("cordovaindex.html", StringComparison.OrdinalIgnoreCase) == -1)
+ if (IsHtml(path) && path.IndexOf("cordovaindex.html", StringComparison.OrdinalIgnoreCase) == -1)
{
resourceStream = await ModifyHtml(resourceStream, mode, localizationCulture, enableMinification).ConfigureAwait(false);
}
@@ -115,6 +115,86 @@ namespace MediaBrowser.WebDashboard.Api
return fullPath;
}
+ public async Task<Stream> ModifyCss(Stream sourceStream, bool enableMinification)
+ {
+ using (sourceStream)
+ {
+ string content;
+
+ using (var memoryStream = new MemoryStream())
+ {
+ await sourceStream.CopyToAsync(memoryStream).ConfigureAwait(false);
+
+ content = Encoding.UTF8.GetString(memoryStream.ToArray());
+
+ if (enableMinification)
+ {
+ try
+ {
+ var result = new KristensenCssMinifier().Minify(content, false, Encoding.UTF8);
+
+ if (result.Errors.Count > 0)
+ {
+ _logger.Error("Error minifying css: " + result.Errors[0].Message);
+ }
+ else
+ {
+ content = result.MinifiedContent;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error minifying css", ex);
+ }
+ }
+ }
+
+ var bytes = Encoding.UTF8.GetBytes(content);
+
+ return new MemoryStream(bytes);
+ }
+ }
+
+ public async Task<Stream> ModifyJs(Stream sourceStream, bool enableMinification)
+ {
+ using (sourceStream)
+ {
+ string content;
+
+ using (var memoryStream = new MemoryStream())
+ {
+ await sourceStream.CopyToAsync(memoryStream).ConfigureAwait(false);
+
+ content = Encoding.UTF8.GetString(memoryStream.ToArray());
+
+ if (enableMinification)
+ {
+ try
+ {
+ var result = new CrockfordJsMinifier().Minify(content, false, Encoding.UTF8);
+
+ if (result.Errors.Count > 0)
+ {
+ _logger.Error("Error minifying javascript: " + result.Errors[0].Message);
+ }
+ else
+ {
+ content = result.MinifiedContent;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error minifying javascript", ex);
+ }
+ }
+ }
+
+ var bytes = Encoding.UTF8.GetBytes(content);
+
+ return new MemoryStream(bytes);
+ }
+ }
+
/// <summary>
/// Modifies the HTML by adding common meta tags, css and js.
/// </summary>
@@ -135,6 +215,11 @@ namespace MediaBrowser.WebDashboard.Api
html = Encoding.UTF8.GetString(memoryStream.ToArray());
+ if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase))
+ {
+ html = ModifyForCordova(html);
+ }
+
if (!string.IsNullOrWhiteSpace(localizationCulture))
{
var lang = localizationCulture.Split('-').FirstOrDefault();
@@ -182,6 +267,22 @@ namespace MediaBrowser.WebDashboard.Api
}
}
+ private string ModifyForCordova(string html)
+ {
+ // Strip everything between CORDOVA_EXCLUDE_START and CORDOVA_EXCLUDE_END
+ html = ReplaceBetween(html, "CORDOVA_EXCLUDE_START", "CORDOVA_EXCLUDE_END", string.Empty);
+
+ // Replace CORDOVA_REPLACE_SUPPORTER_SUBMIT_START
+ html = ReplaceBetween(html, "CORDOVA_REPLACE_SUPPORTER_SUBMIT_START", "CORDOVA_REPLACE_SUPPORTER_SUBMIT_END", "<i class=\"fa fa-check\"></i><span>${ButtonDonate}</span>");
+
+ return html;
+ }
+
+ private string ReplaceBetween(string html, string startToken, string endToken, string newHtml)
+ {
+ return html;
+ }
+
private string GetLocalizationToken(string phrase)
{
return "${" + phrase + "}";
@@ -293,7 +394,14 @@ namespace MediaBrowser.WebDashboard.Api
await AppendResource(memoryStream, "thirdparty/jquery.unveil-custom.js", newLineBytes).ConfigureAwait(false);
- await AppendLocalization(memoryStream, culture).ConfigureAwait(false);
+ var excludePhrases = new List<string>();
+
+ if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase))
+ {
+ excludePhrases.Add("paypal");
+ }
+
+ await AppendLocalization(memoryStream, culture, excludePhrases).ConfigureAwait(false);
await memoryStream.WriteAsync(newLineBytes, 0, newLineBytes.Length).ConfigureAwait(false);
if (!string.IsNullOrWhiteSpace(mode))
@@ -424,13 +532,11 @@ namespace MediaBrowser.WebDashboard.Api
"taskbutton.js",
"ratingdialog.js",
- "aboutpage.js",
"alphapicker.js",
"addpluginpage.js",
"metadataadvanced.js",
"autoorganizetv.js",
"autoorganizelog.js",
- "channels.js",
"channelslatest.js",
"channelitems.js",
"channelsettings.js",
@@ -489,10 +595,6 @@ namespace MediaBrowser.WebDashboard.Api
"moviepeople.js",
"moviestudios.js",
"movietrailers.js",
- "musicalbums.js",
- "musicalbumartists.js",
- "musicartists.js",
- "musicrecommended.js",
"mypreferencesdisplay.js",
"mypreferenceslanguages.js",
@@ -538,9 +640,29 @@ namespace MediaBrowser.WebDashboard.Api
};
}
- private async Task AppendLocalization(Stream stream, string culture)
+ private async Task AppendLocalization(Stream stream, string culture, List<string> excludePhrases)
{
- var js = "window.localizationGlossary=" + _jsonSerializer.SerializeToString(_localization.GetJavaScriptLocalizationDictionary(culture));
+ var dictionary = _localization.GetJavaScriptLocalizationDictionary(culture);
+
+ if (excludePhrases.Count > 0)
+ {
+ var removes = new List<string>();
+
+ foreach (var pair in dictionary)
+ {
+ if (excludePhrases.Any(i => pair.Key.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1 || pair.Value.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1))
+ {
+ removes.Add(pair.Key);
+ }
+ }
+
+ foreach (var remove in removes)
+ {
+ dictionary.Remove(remove);
+ }
+ }
+
+ var js = "window.localizationGlossary=" + _jsonSerializer.SerializeToString(dictionary);
var bytes = Encoding.UTF8.GetBytes(js);
await stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj
index b45b3dc3a..8d52f178f 100644
--- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj
+++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj
@@ -156,6 +156,9 @@
<Content Include="dashboard-ui\scripts\photos.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Content Include="dashboard-ui\scripts\registrationservices.js">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="dashboard-ui\scripts\reports.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@@ -222,6 +225,9 @@
<Content Include="dashboard-ui\thirdparty\cordova\imagestore.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Content Include="dashboard-ui\thirdparty\cordova\registrationservices.js">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="dashboard-ui\thirdparty\cordova\remotecontrols.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>