From c14a86b190d69941f90bf537cd0b8c6534967ec4 Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Fri, 10 Apr 2026 21:08:45 +0200 Subject: [PATCH] Add PWA manifest and SW --- .streamlit/config.toml | 2 ++ app/components/pwa.py | 21 +++++++++++++++++++++ app/static/manifest.json | 8 ++++++++ app/static/service-worker.js | 7 +++++++ app/streamlit_app.py | 3 +++ 5 files changed, 41 insertions(+) create mode 100644 app/components/pwa.py create mode 100644 app/static/manifest.json create mode 100644 app/static/service-worker.js diff --git a/.streamlit/config.toml b/.streamlit/config.toml index 627038c..bd68ea6 100644 --- a/.streamlit/config.toml +++ b/.streamlit/config.toml @@ -1,12 +1,14 @@ [server] port = 8501 address = "0.0.0.0" +enableStaticServing = true [browser] gatherUsageStats = false [logger] level = "info" +hideWelcomeMessage = true [client] toolbarMode = "viewer" diff --git a/app/components/pwa.py b/app/components/pwa.py new file mode 100644 index 0000000..f6b47e2 --- /dev/null +++ b/app/components/pwa.py @@ -0,0 +1,21 @@ +import streamlit as st + +init = st.components.v2.component( + name="pwa", + isolate_styles=False, + js = """ + export default function() { + + // Manifest + const link = document.createElement("link"); + link.rel = "manifest"; + link.href = "./app/static/manifest.json"; + document.head.appendChild(link); + + // Service Worker + navigator.serviceWorker.register('./app/static/service-worker.js') + .then(reg => console.log('SW registered', reg)) + .catch(err => console.log('SW registration failed', err)); + } + """, +) \ No newline at end of file diff --git a/app/static/manifest.json b/app/static/manifest.json new file mode 100644 index 0000000..1ead28b --- /dev/null +++ b/app/static/manifest.json @@ -0,0 +1,8 @@ +{ + "short_name": "Daily Counter", + "name": "Daily Counter", + "start_url": ".", + "display": "standalone", + "theme_color": "white", + "background_color": "white" +} \ No newline at end of file diff --git a/app/static/service-worker.js b/app/static/service-worker.js new file mode 100644 index 0000000..c131cf1 --- /dev/null +++ b/app/static/service-worker.js @@ -0,0 +1,7 @@ + self.addEventListener('fetch', event => { + event.respondWith( + caches.match(event.request).then(response => { + return response || fetch(event.request); + }) + ); + }); \ No newline at end of file diff --git a/app/streamlit_app.py b/app/streamlit_app.py index bf3a574..ffa7425 100644 --- a/app/streamlit_app.py +++ b/app/streamlit_app.py @@ -2,6 +2,9 @@ import streamlit as st from logger import init_logger from styles import init_styles +from components import pwa + +pwa.init() init_logger() init_styles()