Add service worker and offline page (needed to install the webapp on mobile devices)

This commit is contained in:
Lorenzo Breda
2021-09-10 22:35:59 +02:00
parent e9f2f56634
commit 16d39ff9d0
14 changed files with 250 additions and 2 deletions

View File

@@ -19,5 +19,17 @@
<body class="hold-transition login-page">
{% block content %}{% endblock %}
{% block scripts %}{% endblock %}
<script nonce="{{ JS_NONCE }}">
// Initialize the service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('serviceworker.js?v={{ FF_VERSION }}', {
scope: '{{ route('index') }}'
}).then(
() => console.log('ServiceWorker registration successful'),
(err) => console.log('ServiceWorker registration failed: ', err)
);
}
</script>
</body>
</html>

View File

@@ -46,9 +46,11 @@
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">
{% if mainTitleIcon|default(false) %}<span class="fa fas {{ mainTitleIcon }}"></span>{% endif %}
{% if mainTitleIcon|default(false) %}<span
class="fa fas {{ mainTitleIcon }}"></span>{% endif %}
{{ title }} <small class="text-muted">
{% if subTitleIcon|default(false) %}<span class="fa fas {{ subTitleIcon }}"></span>{% endif %}
{% if subTitleIcon|default(false) %}<span
class="fa fas {{ subTitleIcon }}"></span>{% endif %}
{{ subTitle|default('') }}</small></h1>
</div><!-- /.col -->
<div class="col-sm-6">
@@ -91,6 +93,18 @@
<script src="v2/js/vendor.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
{% block scripts %}{% endblock %}
<script nonce="{{ JS_NONCE }}">
// Initialize the service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('serviceworker.js?v={{ FF_VERSION }}', {
scope: '{{ route('index') }}'
}).then(
() => console.log('ServiceWorker registration successful'),
(err) => console.log('ServiceWorker registration failed: ', err)
);
}
</script>
</body>
</html>