fixing clients

new frontend
This commit is contained in:
stefan
2025-09-26 14:29:31 +02:00
parent 97d0af1b07
commit 0da4d87823
5 changed files with 34 additions and 12 deletions
+3 -1
View File
@@ -2,10 +2,12 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.ComposeViewport import androidx.compose.ui.window.ComposeViewport
import at.mocode.clients.app.App import at.mocode.clients.app.App
import kotlinx.browser.document import kotlinx.browser.document
import org.w3c.dom.HTMLElement
@OptIn(ExperimentalComposeUiApi::class) @OptIn(ExperimentalComposeUiApi::class)
fun main() { fun main() {
ComposeViewport(document.getElementById("ComposeTarget")!!) { val root = document.getElementById("ComposeTarget") as HTMLElement
ComposeViewport(root) {
App() App()
} }
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 560 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 KiB

+1 -1
View File
@@ -13,7 +13,7 @@
<script> <script>
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
window.addEventListener('load', () => { window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js').catch(console.error); navigator.serviceWorker.register('sw.js').catch(console.error);
}); });
} }
</script> </script>
+30 -10
View File
@@ -23,14 +23,30 @@ self.addEventListener('activate', (event) => {
self.addEventListener('fetch', (event) => { self.addEventListener('fetch', (event) => {
const req = event.request; const req = event.request;
const url = new URL(req.url);
const isHttp = url.protocol === 'http:' || url.protocol === 'https:';
const sameOrigin = url.origin === self.location.origin;
const isExtension = url.protocol === 'chrome-extension:';
const isHotUpdate = url.pathname.includes('hot-update');
// Ignore non-GET, cross-origin, browser extensions, and HMR/hot-update requests
if (req.method !== 'GET' || !isHttp || !sameOrigin || isExtension || isHotUpdate) {
return; // Let the browser handle it
}
if (req.mode === 'navigate') { if (req.mode === 'navigate') {
// Network-first for navigation // Network-first for navigation
event.respondWith( event.respondWith(
fetch(req).then((resp) => { fetch(req)
const copy = resp.clone(); .then((resp) => {
caches.open(CACHE_NAME).then((cache) => cache.put('/', copy)); if (resp && resp.status === 200 && resp.type === 'basic') {
return resp; const copy = resp.clone();
}).catch(() => caches.match('/index.html')) caches.open(CACHE_NAME).then((cache) => cache.put('/index.html', copy)).catch(() => {});
}
return resp;
})
.catch(() => caches.match('/index.html'))
); );
return; return;
} }
@@ -39,11 +55,15 @@ self.addEventListener('fetch', (event) => {
event.respondWith( event.respondWith(
caches.match(req).then((cached) => { caches.match(req).then((cached) => {
if (cached) return cached; if (cached) return cached;
return fetch(req).then((resp) => { return fetch(req)
const copy = resp.clone(); .then((resp) => {
caches.open(CACHE_NAME).then((cache) => cache.put(req, copy)); if (resp && resp.status === 200 && resp.type === 'basic') {
return resp; const copy = resp.clone();
}); caches.open(CACHE_NAME).then((cache) => cache.put(req, copy)).catch(() => {});
}
return resp;
})
.catch(() => caches.match(req));
}) })
); );
}); });