notification fix
This commit is contained in:
parent
6b30769d96
commit
be49a31e54
@ -35,6 +35,11 @@
|
|||||||
<a class="nav-link" href="/urls">URLs</a>
|
<a class="nav-link" href="/urls">URLs</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
<li class="nav-item">
|
||||||
|
<button id="enable-notifications" class="btn btn-outline-light">Enable Notifications</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
@ -55,13 +60,19 @@
|
|||||||
{% block scripts %}{% endblock %}
|
{% block scripts %}{% endblock %}
|
||||||
<script>
|
<script>
|
||||||
if ('serviceWorker' in navigator && 'PushManager' in window) {
|
if ('serviceWorker' in navigator && 'PushManager' in window) {
|
||||||
window.addEventListener('load', function() {
|
let swRegistration = null;
|
||||||
navigator.serviceWorker.register('{{ url_for("static", filename="service-worker.js") }}').then(function(registration) {
|
navigator.serviceWorker.register('{{ url_for("static", filename="service-worker.js") }}').then(function(registration) {
|
||||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
||||||
askPermission(registration);
|
swRegistration = registration;
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
console.log('ServiceWorker registration failed: ', err);
|
console.log('ServiceWorker registration failed: ', err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const enableNotificationsButton = document.getElementById('enable-notifications');
|
||||||
|
enableNotificationsButton.addEventListener('click', function() {
|
||||||
|
if (swRegistration) {
|
||||||
|
askPermission(swRegistration);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user