Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/mapviewer/src/modules/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@
"offline_refresh": "Seite aktualisieren",
"offline_save": "Karte Speichern",
"offline_save_new_data": "Neue Karte speichern ",
"offline_sw_configuration_error": "Fehler in der Service-Worker-Konfiguration. Die Offline-Funktionalität funktioniert möglicherweise nicht korrekt.",
"offline_sw_secure_context_required": "Der Service Worker erfordert einen sicheren Kontext (HTTPS mit einem vertrauenswürdigen Zertifikat).",
"offline_save_warning": "- ~50MB Kartenmaterial wird heruntergeladen werden (bis Massstab 1:25'000) - Bitte diese Seite während dem Speichervorgang nicht verlassen und das Gerät nicht sperren. \\\"Private\\\" mode des Browsers muss deaktiviert sein.",
"offline_show": "Zeige Offline Menu",
"offline_show_extent": "Ausschnitt anzeigen",
Expand Down Expand Up @@ -755,4 +757,4 @@
"zoom_in": "Vergrössere Kartenausschnitt",
"zoom_out": "Verkleinere Kartenausschnitt",
"zooming_mode_warning": "Zum Zoomen der Karte Strg/Cmd gedrückt halten"
}
}
4 changes: 3 additions & 1 deletion packages/mapviewer/src/modules/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@
"offline_refresh": "Refresh the page",
"offline_save": "Save map",
"offline_save_new_data": "Save new map",
"offline_sw_configuration_error": "Service worker configuration error. Offline functionality may not work correctly.",
"offline_sw_secure_context_required": "Service worker requires a secure context (HTTPS with a trusted certificate).",
"offline_save_warning": "- ~50MB of maps will be downloaded (until scale 1:25'000) - Don't lock your device or navigate away from this site during the download process. Deactivate \\\"private\\\" mode of your browser.",
"offline_show": "Show offline menu",
"offline_show_extent": "Show extent",
Expand Down Expand Up @@ -755,4 +757,4 @@
"zoom_in": "Zoom in",
"zoom_out": "Zoom out",
"zooming_mode_warning": "Hold Ctrl/Cmd while scrolling to zoom the map"
}
}
4 changes: 3 additions & 1 deletion packages/mapviewer/src/modules/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@
"offline_refresh": "Rafraîchir la page",
"offline_save": "Enregistrer carte",
"offline_save_new_data": "Sauvegarder une nouvelle carte",
"offline_sw_configuration_error": "Erreur de configuration du service worker. Le mode hors ligne pourrait ne pas fonctionner correctement.",
"offline_sw_secure_context_required": "Le service worker nécessite un contexte sécurisé (HTTPS avec un certificat de confiance).",
"offline_save_warning": "- Vous allez télécharger ~50MB de carte (jusqu'à l'échelle 1:25'000) - Ne lockez pas votre appareil et ne quittez pas ce site durant le processus de téléchargement. Désactivez le mode « privé »",
"offline_show": "Afficher le menu hors-ligne",
"offline_show_extent": "Afficher l'étendue",
Expand Down Expand Up @@ -755,4 +757,4 @@
"zoom_in": "Zoomer plus",
"zoom_out": "Zoomer moins",
"zooming_mode_warning": "Maintenir Ctrl/Cmd pour zoomer sur la carte"
}
}
4 changes: 3 additions & 1 deletion packages/mapviewer/src/modules/i18n/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@
"offline_refresh": "Ricarica la pagina",
"offline_save": "Salvare la mappa",
"offline_save_new_data": "Salvare una nuova mappa",
"offline_sw_configuration_error": "Errore di configurazione del service worker. La funzionalità offline potrebbe non funzionare correttamente.",
"offline_sw_secure_context_required": "Il service worker richiede un contesto sicuro (HTTPS con un certificato attendibile).",
"offline_save_warning": "- Saranno scaricati ~50MB di carte (fino alla scala 1:25000) - Non bloccare il dispositivo e non abbandonare questa pagina durante il download. Disattivare la modalità \\\"privata\\\"",
"offline_show": "Mostra il menu offline",
"offline_show_extent": "Mostrare l'estensione",
Expand Down Expand Up @@ -755,4 +757,4 @@
"zoom_in": "Zoom in avanti",
"zoom_out": "Zoom indietro",
"zooming_mode_warning": "Mantenere Ctrl/Cmd premuto per zoomare la mappa"
}
}
4 changes: 3 additions & 1 deletion packages/mapviewer/src/modules/i18n/locales/rm.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@
"offline_refresh": "Chargiar giu la pagina",
"offline_save": "Arcurnar charta",
"offline_save_new_data": "Memorisar la nova charta",
"offline_sw_configuration_error": "Errur da configuraziun dal service worker. La funcziunalitad offline pudess betg funcziunar correctamain.",
"offline_sw_secure_context_required": "Il service worker pretenda in context segir (HTTPS cun in certificat fidà).",
"offline_save_warning": "Chargiar e memorisar la charta d'ina grondezza da ~50MB?",
"offline_show": "Mussar il menu offline",
"offline_show_extent": "Mussar l'extract",
Expand Down Expand Up @@ -755,4 +757,4 @@
"zoom_in": "Engrondir l'extract da la charta",
"zoom_out": "Empitschnir l'extract da la charta",
"zooming_mode_warning": "egnair Ctrl/Cmd cuntschaint per zoomar la charta"
}
}
65 changes: 37 additions & 28 deletions packages/mapviewer/src/service-workers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference lib="webworker" />

import log, { LogPreDefinedColor } from '@geoadmin/log'
import { CacheableResponsePlugin } from 'workbox-cacheable-response'
import { clientsClaim } from 'workbox-core'
import { ExpirationPlugin } from 'workbox-expiration'
Expand All @@ -12,54 +13,62 @@ import { NavigationRoute, registerRoute, Route } from 'workbox-routing'
import { NetworkFirst } from 'workbox-strategies'

import { getWmsBaseUrl, getWmtsBaseUrl } from '@/config/baseUrl.config'
import { IS_TESTING_WITH_CYPRESS } from '@/config/staging.config'

declare let self: ServiceWorkerGlobalScope

// disabling workbox's console.debug (comment that line if you need them)
self.__WB_DISABLE_DEV_LOGS = true

log.debug({
title: 'Service Worker: dev logs disabled',
titleColor: LogPreDefinedColor.Sky,
messages: [
'Service Worker: workbox dev logs are disabled',
String(self.__WB_DISABLE_DEV_LOGS),
],
})
// Setting up Service Worker API to have a client-side cache.
// This means the app can mostly function in offline mode, so long as the initial load has happened naturally before.
// This is the first step to get a proper offline mode, where users will be able to select
// a zone on the map, and make it available offline (like it was the case with mf-geoadmin3 back then).

// Cypress doesn't handle well Service Worker API being active, so we skip the setup if we
// are testing things with Cypress
if (!IS_TESTING_WITH_CYPRESS) {
if (import.meta.env.MODE !== 'test') {
log.debug({
title: 'Service Worker: starting initialization',
titleColor: LogPreDefinedColor.Sky,
messages: ['Service Worker: initializing the service worker...'],
})
// self.__WB_MANIFEST is the default injection point
precacheAndRoute(self.__WB_MANIFEST)

// clean old assets
cleanupOutdatedCaches()

let allowlist: RegExp[] | undefined
// in dev mode, we disable precaching to avoid caching issues
if (import.meta.env.DEV) {
allowlist = [/^\/$/]
// in dev mode, we disable navigation fallback registration to avoid runtime errors
// with an empty precache manifest in Vite's dev service worker
if (!import.meta.env.DEV) {
// setting up a cache instance for offline app assets (HTML/JS/CSS)
registerRoute(
new NavigationRoute(createHandlerBoundToURL(`index.html`), {
denylist: [
// exclude all api calls, as the service worker might interacts with those in a way
// that can shut down the service from the user's perspective
// (injecting the cached index.html file instead of providing the expected output)
/^\/api\//,
// excluding the embed legacy endpoint, as it stops the redirection to the
// `legacyEmbed` route and display map views instead of embed views
/^\/embed/,
// preview sites must be excluded too (we want the latest code, not some cached version)
/^\/preview\//,
],
}),
new NetworkFirst({
cacheName: 'geoadmin-app-cache',
})
)
}

// setting up a cache instance for offline app assets (HTML/JS/CSS)
registerRoute(
new NavigationRoute(createHandlerBoundToURL(`index.html`), {
allowlist,
denylist: [
// exclude all api calls, as the service worker might interacts with those in a way
// that can shut down the service from the user's perspective
// (injecting the cached index.html file instead of providing the expected output)
/^\/api\//,
// excluding the embed legacy endpoint, as it stops the redirection to the
// `legacyEmbed` route and display map views instead of embed views
/^\/embed/,
// preview sites must be excluded too (we want the latest code, not some cached version)
/^\/preview\//,
],
}),
new NetworkFirst({
cacheName: 'geoadmin-app-cache',
})
)

// caching essential backend items (layers config, topic list, etc...)
const configItemPathNames = [
// layers config
Expand Down
Loading
Loading