Skip to content

Commit

Permalink
- Added PWA
Browse files Browse the repository at this point in the history
- Remove obsolete Root Page
  • Loading branch information
Tim Hofmann committed Jul 1, 2020
1 parent c24cebc commit a9e863b
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 31 deletions.
24 changes: 24 additions & 0 deletions LAPS WebUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,36 @@
<None Update="ressources\fontawesome\webfonts\fa-solid-900.woff2">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ressources\images\logo-128x128.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ressources\images\logo-192x192.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ressources\images\logo-512x512.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ressources\images\logo-72x72.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ressources\images\logo-96x96.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ressources\js\app.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ressources\js\helper.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ressources\js\sw.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ressources\manifest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ressources\select2\css\select2-bootstrap4.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 1 addition & 1 deletion LAPS WebUI.csproj.user
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>D:\Programmierung\VB.NET &amp; C#\Diverse Projekte\LAPS-WebUI\Properties\PublishProfiles\Linux x64.pubxml</_LastSelectedProfileId>
<_LastSelectedProfileId>D:\Programmierung\VB.NET &amp; C#\Diverse Projekte\LAPS-WebUI\Properties\PublishProfiles\Windows x64.pubxml</_LastSelectedProfileId>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Pages/LAPS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Task OnGet()

if (!UserSession.LoggedIn)
{
LaraUI.Page.Navigation.Replace("/login");
LaraUI.Page.Navigation.Replace("/");
}
else
{
Expand Down
12 changes: 11 additions & 1 deletion Pages/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace LAPS_WebUI.Pages
{
[LaraPage(Address = "/login")]
[LaraPage(Address = "/")]
class Login : IPage
{

Expand All @@ -20,6 +20,16 @@ public Task OnGet()

var thisDocument = LaraUI.Page.Document;

#region "PWA"

thisDocument.Head.AppendChild(new Script { Src = "/ressources/js/app.js", Defer = true });
thisDocument.Head.AppendChild(new Link { Rel = "manifest", HRef = "/ressources/manifest.json" });
thisDocument.Head.AppendChild(new Link { Rel = "apple-touch-icon", HRef = "/ressources/images/logo-96x96.png" });
thisDocument.Head.AppendChild(new Meta { Name = "theme-color", Content = "#848482" });

#endregion


if (UserSession.LoggedIn)
{
LaraUI.Page.Navigation.Replace("/laps");
Expand Down
25 changes: 0 additions & 25 deletions Pages/Root.cs

This file was deleted.

19 changes: 16 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ await app.Start(new StartServerOptions
Mode = ApplicationMode.Default,
PublishAssembliesOnStart = true,
Port = settings.ListenPort,
IPAddress = IPAddress.Parse(settings.ListenAddress)

IPAddress = IPAddress.Parse(settings.ListenAddress),
});

m_log.Info("Publishing ressources....");

List<string> allowedFileTypes = new List<string>() { ".js", ".css", ".svg", ".woff", ".woff2", ".ttf" };
List<string> allowedFileTypes = new List<string>() { ".js", ".css", ".svg", ".woff", ".woff2", ".ttf", ".png" , ".json" };

foreach(var file in Directory.GetFiles(Path.Combine(currentDir, "ressources"), "*.*", SearchOption.AllDirectories).Where(x => allowedFileTypes.Contains(new FileInfo(x).Extension.ToLower()) == true )){

Expand All @@ -62,6 +61,14 @@ await app.Start(new StartServerOptions
contentType = ContentTypes.ApplicationJavascript;
break;

case ".json":
contentType = ContentTypes.ApplicationJson;
break;

case ".png":
contentType = ContentTypes.ImagePng;
break;

case ".css":
contentType = ContentTypes.TextCss;
break;
Expand Down Expand Up @@ -91,6 +98,12 @@ await app.Start(new StartServerOptions

var publishPath = string.Format("/{0}/{1}", publishDir, fileInfo.Name);

//ServiceWorker must be published at root - this is needed for PWA
if (fileInfo.Name == "sw.js")
{
publishPath = "/sw.js";
}

m_log.Debug("Publishing file {0}", publishPath);

app.PublishFile(publishPath, content);
Expand Down
Binary file added ressources/images/logo-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ressources/images/logo-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ressources/images/logo-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ressources/images/logo-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ressources/images/logo-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions ressources/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/sw.js', { scope: '/' }).then(function (registration) {
console.log('Service worker successfully registered on scope', registration.scope);
}).catch(function (error) {
console.log('Service worker failed to register');
});
});
}
38 changes: 38 additions & 0 deletions ressources/js/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const staticCacheName = 'LAPSWebUI';
const assets = [
'/',
'/laps',
'/ressources/js/helper.js',
'/ressources/images/*.png',
'/ressources/bootstrap/css/bootstrap.min.css',
'/ressources/bootstrap/js/popper.min.js',
'/ressources/bootstrap/js/bootstrap.min.js',
'/ressources/clipboardjs/js/clipboard.min.js',
'/ressources/fontawesome/css/all.min.css',
'/ressources/fontawesome/webfonts/*.(svg|ttf|woff|woff2)',
];// install event
self.addEventListener('install', evt => {
evt.waitUntil(
caches.open(staticCacheName).then((cache) => {
console.log('caching shell assets');
cache.addAll(assets);
})
);
});// activate event
self.addEventListener('activate', evt => {
evt.waitUntil(
caches.keys().then(keys => {
return Promise.all(keys
.filter(key => key !== staticCacheName)
.map(key => caches.delete(key))
);
})
);
});// fetch event
self.addEventListener('fetch', evt => {
evt.respondWith(
caches.match(evt.request).then(cacheRes => {
return cacheRes || fetch(evt.request);
})
);
});
36 changes: 36 additions & 0 deletions ressources/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "LAPS WebUI",
"short_name": "LAPSUI",
"start_url": "/",
"lang": "en-US",
"background_color": "#F4F4F4",
"theme_color": "#F4F4F4",
"display": "standalone",
"icons": [
{
"src": "/ressources/images/logo-72x72.png",
"type": "image/png",
"sizes": "72x72"
},
{
"src": "/ressources/images/logo-96x96.png",
"type": "image/png",
"sizes": "96x96"
},
{
"src": "/ressources/images/logo-128x128.png",
"type": "image/png",
"sizes": "128x128"
},
{
"src": "/ressources/images/logo-192x192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/ressources/images/logo-512x512.png",
"type": "image/png",
"sizes": "512x512"
}
]
}

0 comments on commit a9e863b

Please sign in to comment.