Browse Source

update snackbar if new versionis available

master
Flo Smilari 4 years ago
parent
commit
f72f2e3deb
5 changed files with 24 additions and 17 deletions
  1. 0
    1
      Shared/Services/InputCursorHandler.cs
  2. 1
    1
      cwebplusApp.csproj
  3. 11
    5
      wwwroot/css/app.css
  4. 11
    9
      wwwroot/index.html
  5. 1
    1
      wwwroot/service-worker.js

+ 0
- 1
Shared/Services/InputCursorHandler.cs View File

using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
using Microsoft.JSInterop; using Microsoft.JSInterop;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace cwebplusApp.Shared.Services { namespace cwebplusApp.Shared.Services {

+ 1
- 1
cwebplusApp.csproj View File

<PropertyGroup> <PropertyGroup>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest> <ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<Version>0.9.3</Version>
<Version>0.9.8</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

+ 11
- 5
wwwroot/css/app.css View File

width: var(--mat-drawer-custom-width, 300px); width: var(--mat-drawer-custom-width, 300px);
} }
#snackbarDiv {
bottom: 30px;
width: 100%;
justify-content: center;
padding: 0 40px;
}
#snackbarDiv.show {
position: absolute;
}
#snackbar { #snackbar {
visibility: hidden; visibility: hidden;
min-width: 50%;
margin: 40px;
background-color: #333; background-color: #333;
color: #fff; color: #fff;
text-align: center; text-align: center;
border-radius: 10px; border-radius: 10px;
padding: 16px; padding: 16px;
position: sticky;
z-index: 1; z-index: 1;
left: 50%;
bottom: 30px;
} }
#snackbar.show { #snackbar.show {

+ 11
- 9
wwwroot/index.html View File

<a href="" class="reload">Reload</a> <a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a> <a class="dismiss">🗙</a>
</div> </div>
<!-- The actual snackbar --> <!-- The actual snackbar -->
<div id="snackbar">A new version of this app is available. Click <a id="reload" style="color:deepskyblue">here</a> to update.</div>
<div id="snackbarDiv">
<div id="snackbar">A new version of this app is available. Click <a id="reload" style="color:deepskyblue">here</a> to update. Eventually you have to restart the App manually.</div>
</div>
<script src="_framework/blazor.webassembly.js"></script> <script src="_framework/blazor.webassembly.js"></script>
<script src="_content/TG.Blazor.IndexedDB/indexedDb.Blazor.js"></script> <script src="_content/TG.Blazor.IndexedDB/indexedDb.Blazor.js"></script>
let newWorker; let newWorker;
function showUpdateBar() { function showUpdateBar() {
let snackbarDiv = document.getElementById('snackbarDiv');
let snackbar = document.getElementById('snackbar'); let snackbar = document.getElementById('snackbar');
snackbar.className = 'show'; snackbar.className = 'show';
snackbarDiv.className = 'show';
} }
function hideUpdateBar() { function hideUpdateBar() {
let snackbarDiv = document.getElementById('snackbarDiv');
let snackbar = document.getElementById('snackbar'); let snackbar = document.getElementById('snackbar');
snackbar.className = ''; snackbar.className = '';
snackbarDiv.className = '';
} }
// The click event on the pop up notification // The click event on the pop up notification
let refreshing; let refreshing;
navigator.serviceWorker.addEventListener('controllerchange', function () { navigator.serviceWorker.addEventListener('controllerchange', function () {
if (refreshing) return; if (refreshing) return;
window.location.reload();
window.location = window.location.origin;
refreshing = true; refreshing = true;
console.log('Reload to page ' + window.location.origin + ' on controller change.');
}); });
} }
//if ('serviceWorker' in navigator) {
// navigator.serviceWorker.register('service-worker.js')
// .then((reg) => console.log('Service worker registered.', reg))
// .catch((err) => console.log('Failed to register Service worker.', err));
//}
</script> </script>
<script> <script>
function BlazorSetLocalStorage(key, value) { function BlazorSetLocalStorage(key, value) {
localStorage.setItem(key, value); localStorage.setItem(key, value);

+ 1
- 1
wwwroot/service-worker.js View File

// This is because caching would make development more difficult (changes would not // This is because caching would make development more difficult (changes would not
// be reflected on the first load after each change). // be reflected on the first load after each change).
const staticCacheName = 'site-static-v-0-9-3'; // IMPORTANT: CHANGE THE VERSION IN THIS NAME EVERY TIME THE APP IS DEPLOYED ON SERVER WITH CHANGES!!!
const staticCacheName = 'site-static-v-0-9-8'; // IMPORTANT: CHANGE THE VERSION IN THIS NAME EVERY TIME THE APP IS DEPLOYED ON SERVER WITH CHANGES!!!
const appsettings_url = 'appsettings.json'; const appsettings_url = 'appsettings.json';
const assets = [ const assets = [
'./', './',

Loading…
Cancel
Save