From 3e1e7a5ce2b4a3d654ccb32966e0605a7a98c603 Mon Sep 17 00:00:00 2001 From: Karl Date: Thu, 17 Jul 2025 15:41:16 +0100 Subject: [PATCH] notification support --- app.py | 2 +- static/service-worker.js | 13 +++++++++ templates/base.html | 58 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 027c549..a72ba23 100644 --- a/app.py +++ b/app.py @@ -58,7 +58,7 @@ def get_version() -> str: @app.context_processor def inject_version() -> Dict[str, str]: """Injects the version into all templates.""" - return dict(version=get_version()) + return dict(version=get_version(), config=app.config, session=session) @app.before_request def make_session_permanent() -> None: diff --git a/static/service-worker.js b/static/service-worker.js index 524322d..84495ce 100644 --- a/static/service-worker.js +++ b/static/service-worker.js @@ -21,6 +21,19 @@ self.addEventListener('install', function(event) { ); }); +self.addEventListener('push', function(event) { + const data = event.data.json(); + const options = { + body: data.body, + icon: '/static/web-app-manifest-192x192.png', + badge: '/static/favicon-96x96.png' + }; + + event.waitUntil( + self.registration.showNotification(data.title, options) + ); +}); + self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request) diff --git a/templates/base.html b/templates/base.html index 7d897ce..f5bb5f7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -54,8 +54,62 @@ {% block scripts %}{% endblock %}