Added Favicon support, Progressive Web App support, page title and url support, and private/public user registration options

This commit is contained in:
Shaun Walker
2020-03-30 20:42:43 -04:00
parent 928111dbac
commit 35f87d25be
23 changed files with 422 additions and 47 deletions

View File

@ -185,16 +185,21 @@
};
Installation installation = await InstallationService.Install(config);
//TODO: Should be moved to Database manager
//TODO: Should be moved to Database manager
if (installation.Success)
{
Site site = new Site();
site.TenantId = -1; // will be populated on server
site.Name = "Default Site";
site.LogoFileId = null;
site.FaviconFileId = null;
site.DefaultThemeType = Constants.DefaultTheme;
site.DefaultLayoutType = Constants.DefaultLayout;
site.DefaultContainerType = Constants.DefaultContainer;
site.PwaIsEnabled = false;
site.PwaAppIconFileId = null;
site.PwaSplashIconFileId = null;
site.AllowRegistration = false;
site = await SiteService.AddSiteAsync(site, null);
User user = new User();

View File

@ -58,12 +58,12 @@ namespace Oqtane.UI
}
}
public Task UpdateMeta(string id, string attribute, string name, string content)
public Task IncludeMeta(string id, string attribute, string name, string content)
{
try
{
_jsRuntime.InvokeAsync<string>(
"interop.updateMeta",
"interop.includeMeta",
id, attribute, name, content);
return Task.CompletedTask;
}
@ -73,13 +73,28 @@ namespace Oqtane.UI
}
}
public Task UpdateLink(string id, string rel, string type, string url)
public Task IncludeLink(string id, string rel, string url, string type)
{
try
{
_jsRuntime.InvokeAsync<string>(
"interop.updateLink",
id, rel, type, url);
"interop.includeLink",
id, rel, url, type);
return Task.CompletedTask;
}
catch
{
return Task.CompletedTask;
}
}
public Task IncludeScript(string id, string src, string content, string location)
{
try
{
_jsRuntime.InvokeAsync<string>(
"interop.includeScript",
id, src, content, location);
return Task.CompletedTask;
}
catch
@ -93,8 +108,8 @@ namespace Oqtane.UI
try
{
_jsRuntime.InvokeAsync<string>(
"interop.updateLink",
id, "stylesheet", "text/css", url);
"interop.includeLink",
id, "stylesheet", url, "text/css");
return Task.CompletedTask;
}
catch

View File

@ -1,5 +1,6 @@
@namespace Oqtane.UI
@inject IJSRuntime JsRuntime
@inject NavigationManager NavigationManager
@DynamicComponent
@ -8,8 +9,26 @@
RenderFragment DynamicComponent { get; set; }
protected override void OnParametersSet()
protected override async Task OnParametersSetAsync()
{
var interop = new Interop(JsRuntime);
if (!string.IsNullOrEmpty(PageState.Page.Title))
{
await interop.UpdateTitle(PageState.Page.Title);
}
else
{
await interop.UpdateTitle(PageState.Site.Name + " - " + PageState.Page.Name);
}
if (PageState.Site.FaviconFileId != null)
{
await interop.IncludeLink("fav-icon", "shortcut icon", Utilities.ContentUrl(PageState.Alias.Path, PageState.Site.FaviconFileId.Value), "image/x-icon");
}
if (PageState.Site.PwaIsEnabled)
{
await InitializePwa(interop);
}
DynamicComponent = builder =>
{
Type themeType = Type.GetType(PageState.Page.ThemeType);
@ -27,4 +46,44 @@
}
};
}
private async Task InitializePwa(Interop interop)
{
// dynamically create manifest.json and add to page
string manifest = "setTimeout(() => { " +
"var manifest = { " +
"\"name\": \"" + PageState.Site.Name + "\", " +
"\"short_name\": \"" + PageState.Site.Name + "\", " +
"\"start_url\": \"/\", " +
"\"display\": \"standalone\", " +
"\"background_color\": \"#fff\", " +
"\"description\": \"" + PageState.Site.Name + "\", " +
"\"icons\": [{ " +
"\"src\": \"" + Utilities.ContentUrl(PageState.Alias.Path, PageState.Site.PwaAppIconFileId.Value) + "\", " +
"\"sizes\": \"192x192\", " +
"\"type\": \"image/png\" " +
"}, { " +
"\"src\": \"" + Utilities.ContentUrl(PageState.Alias.Path, PageState.Site.PwaSplashIconFileId.Value) + "\", " +
"\"sizes\": \"512x512\", " +
"\"type\": \"image/png\" " +
"}] " +
"} " +
"const serialized = JSON.stringify(manifest); " +
"const blob = new Blob([serialized], {type: 'application/javascript'}); " +
"const url = URL.createObjectURL(blob); " +
"document.getElementById('pwa-manifest').setAttribute('href', url); " +
"} " +
", 1000);";
await interop.IncludeScript("pwa-manifestscript", "", manifest, "body");
// service worker must be in root of site
string serviceworker = "if ('serviceWorker' in navigator) { " +
"navigator.serviceWorker.register('/service-worker.js').then(function(registration) { " +
"console.log('ServiceWorker Registration Successful'); " +
"}).catch (function(err) { " +
"console.log('ServiceWorker Registration Failed ', err); " +
"}); " +
"}";
await interop.IncludeScript("pwa-serviceworker", "", serviceworker, "body");
}
}