Compare commits

...

9 commits

Author SHA1 Message Date
22fad9e1db Fjern shelters.json frå git-sporing
Fila vart lagt til .gitignore i 012da23 men var framleis spora.
Ho vert generert av `bun run fetch-shelters` og skal ikkje versjonerast.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:44:11 +01:00
029cfa45f9 Bump versjon til v1.8.0 (versionCode 12)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:39:16 +01:00
015bc0d926 Bytt djuplenkjer frå tilfluktsrom:// til HTTPS App Links
SMS-appar gjenkjenner ikkje eigendefinerte URI-skjema som klikkbare
lenkjer. Brukar no https://tilfluktsrom.naiv.no/shelter/{id} som
opnar appen direkte (Android App Links med autoVerify) eller fell
tilbake til PWA i nettlesaren.

Android: DEEP_LINK_DOMAIN i build.gradle.kts, HTTPS intent-filter,
oppdatert handleDeepLinkIntent og shareShelter med HTTPS-URL.

PWA: assetlinks.json for Android-verifisering, djuplenkjehandtering
i app.ts, base-sti endra frå './' til '/', config.ts for domene.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:37:13 +01:00
ae249d5d47 Dokumenter arkitektur for Android-app og PWA
Beskriver designprinsipp, datapipeline, plattformspesifikke
implementasjonsdetaljar, delte algoritmar (Haversine, UTM-konvertering),
fråkobla-først-strategi og sikkerheit/personvern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:04:49 +01:00
7d40c9e9a8 Fiks PWA: sivilforsvarsinfo, knappetekst og kompassvisning
- Info-knappen (ℹ) åpner nå sivilforsvarsdialog med alle 5 steg,
  med «Om»-lenke i bunnen (som Android-appen)
- Laste-overleggets knapper («Lagre kart» / «Hopp over») får
  tekst fra i18n i stedet for å være tomme
- Kompassvisningen resizes canvas når den blir synlig, fikser
  0×0-canvas når den initialiseres mens containeren er skjult

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 15:51:42 +01:00
012da23628 Legg shelters.json til .gitignore
Filen genereres ved bygging fra Geonorge-data og skal ikke
spores i git.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 15:41:19 +01:00
85c3d6953c Gjør PWA-stier relative for fleksibel utrulling
Appen kan nå serveres både på / og under en understi som
/tilfluktsrom uten endringer.

- Sett base: './' i vite.config.ts
- Endre alle absolutte stier i index.html til relative
- Oppdater manifest.webmanifest med start_url: "." og scope: "."
- navigateFallback uten ledende skråstrek

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 15:35:39 +01:00
8e6dbb6b24 Dokumenter utgivelsesprosess med PWA-distribusjon
Legger til Release Process-seksjon i CLAUDE.md med:
- Steg-for-steg for å lage ny utgivelse
- Bygging av Android APK-er og PWA-tarball
- fj release create og fj release asset create syntaks
- Oppdatert Distribution-seksjon med PWA-tarball

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 15:30:24 +01:00
4a95e0e23f Fjern unpkg CDN-avhengigheit og legg til slett-buffer-knapp
Leaflet vendora:
- Fjerna CDN <link> for Leaflet CSS (allereie bundla via npm-import)
- Kartmarkør-ikon brukar bundla bilete i staden for unpkg URL-ar
- CSP stramma: unpkg ikkje lenger naudsynt i style-src/img-src

Slett buffer:
- «Slett lagra data»-knapp i om-dialogen
- Slettar localStorage, IndexedDB og tenestararbeidar-bufferar
- Lokalisert til en/nb/nn

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 15:10:30 +01:00
26 changed files with 831 additions and 4485 deletions

455
ARCHITECTURE.md Normal file
View file

@ -0,0 +1,455 @@
# Architecture
This document describes the architecture of Tilfluktsrom, a Norwegian emergency shelter finder available as an Android app and a Progressive Web App (PWA). Both platforms share the same design philosophy — offline-first, no hard external dependencies — but are implemented independently.
## Table of Contents
- [Design Principles](#design-principles)
- [Data Pipeline](#data-pipeline)
- [Android App](#android-app)
- [Package Structure](#package-structure)
- [Data Layer](#data-layer)
- [Location & Navigation](#location--navigation)
- [Compass System](#compass-system)
- [Map & Tile Caching](#map--tile-caching)
- [Build Variants](#build-variants)
- [Home Screen Widget](#home-screen-widget)
- [Deep Linking](#deep-linking)
- [Progressive Web App](#progressive-web-app)
- [Module Structure](#module-structure)
- [Build System](#build-system)
- [Data Layer (PWA)](#data-layer-pwa)
- [Location & Compass (PWA)](#location--compass-pwa)
- [Map & Offline Tiles (PWA)](#map--offline-tiles-pwa)
- [Service Worker](#service-worker)
- [UI Components](#ui-components)
- [Shared Algorithms](#shared-algorithms)
- [UTM33N → WGS84 Conversion](#utm33n--wgs84-conversion)
- [Haversine Distance & Bearing](#haversine-distance--bearing)
- [Offline Capability Summary](#offline-capability-summary)
- [Security & Privacy](#security--privacy)
- [Internationalization](#internationalization)
---
## Design Principles
### Offline-First
This is an emergency app. Core functionality — finding the nearest shelter, compass navigation, distance display — must work without internet after initial setup. Network is used only for initial data download, periodic refresh, and map tile caching.
### De-Google Compatibility (Android)
The Android app runs on devices without Google Play Services (LineageOS, GrapheneOS, /e/OS). Every Google-specific API has an AOSP fallback. Play Services improve accuracy and battery life when available, but are never required.
### Minimal Dependencies
Both platforms use few, well-chosen libraries. No heavy frameworks, no external CDNs at runtime. The PWA bundles everything locally; the Android app uses only OSMDroid, Room, OkHttp, and WorkManager.
### Data Sovereignty
Shelter data comes directly from Geonorge (the Norwegian mapping authority). No intermediate servers. The app fetches, converts, and caches the data locally.
---
## Data Pipeline
Both platforms consume the same upstream data source:
```
Geonorge ZIP (EPSG:25833 UTM33N)
↓ Download (~320KB)
↓ Extract GeoJSON from ZIP
↓ Parse features
↓ Convert UTM33N → WGS84 (Karney method)
↓ Validate (Norway bounding box, required fields)
↓ Store locally
```
**Source URL:** `https://nedlasting.geonorge.no/geonorge/Samfunnssikkerhet/TilfluktsromOffentlige/GeoJSON/Samfunnssikkerhet_0000_Norge_25833_TilfluktsromOffentlige_GeoJSON.zip`
**Fields per shelter:**
| Field | Description |
|------------|--------------------------------------|
| `lokalId` | Unique identifier (UUID) |
| `romnr` | Shelter room number |
| `plasser` | Capacity (number of people) |
| `adresse` | Street address |
| `latitude` | WGS84 latitude (converted from UTM) |
| `longitude`| WGS84 longitude (converted from UTM) |
**When conversion happens:**
- **Android:** At runtime during data download (`ShelterGeoJsonParser`)
- **PWA:** At build time (`scripts/fetch-shelters.ts`), output is pre-converted `shelters.json`
---
## Android App
**Language:** Kotlin · **Min SDK:** 26 (Android 8.0) · **Target SDK:** 35
**Build:** Gradle 8.7, AGP 8.5.2, KSP for Room annotation processing
### Package Structure
```
no.naiv.tilfluktsrom/
├── TilfluktsromApp.kt # Application class (OSMDroid config)
├── MainActivity.kt # Central UI controller (~870 lines)
├── data/
│ ├── Shelter.kt # Room entity
│ ├── ShelterDatabase.kt # Room database singleton
│ ├── ShelterDao.kt # Data access object (Flow queries)
│ ├── ShelterRepository.kt # Repository: bundled seed + network refresh
│ ├── ShelterGeoJsonParser.kt # GeoJSON ZIP → Shelter list
│ └── MapCacheManager.kt # Offline map tile pre-caching
├── location/
│ ├── LocationProvider.kt # GPS provider (flavor-specific)
│ └── ShelterFinder.kt # Nearest N shelters by Haversine
├── ui/
│ ├── DirectionArrowView.kt # Custom compass arrow View
│ ├── ShelterListAdapter.kt # RecyclerView adapter for shelter list
│ ├── CivilDefenseInfoDialog.kt # Emergency instructions
│ └── AboutDialog.kt # Privacy and copyright
├── util/
│ ├── CoordinateConverter.kt # UTM33N → WGS84 (Karney method)
│ └── DistanceUtils.kt # Haversine distance and bearing
└── widget/
├── ShelterWidgetProvider.kt # Home screen widget (flavor-specific)
└── WidgetUpdateWorker.kt # WorkManager periodic update
```
Files under `location/` and `widget/` have separate implementations per build variant:
- `app/src/standard/java/` — Google Play Services variant
- `app/src/fdroid/java/` — AOSP-only variant
### Data Layer
**Storage:** Room (SQLite) with a single `shelters` table.
**Loading strategy (three-layer fallback):**
1. **Bundled asset** (`assets/shelters.json`): Pre-converted WGS84 data, loaded on first launch via `ShelterRepository.seedFromAsset()`. Marked as stale (timestamp=0) so a network refresh is attempted when possible.
2. **Room database**: ~556 shelters cached locally. Reactive updates via Kotlin Flow. Atomic refresh: `deleteAll()` + `insertAll()` in a single transaction.
3. **Network refresh**: Downloads the Geonorge ZIP via OkHttp, parses with `ShelterGeoJsonParser`. Staleness threshold: 7 days. Runs in the background; failure does not block the UI.
**GeoJSON parsing pipeline:**
```
OkHttp response stream
→ ZipInputStream (find .geojson entry, 10MB size limit)
→ JSON parsing (features array)
→ Per feature:
→ Extract UTM33N coordinates
→ CoordinateConverter.utm33nToWgs84()
→ Validate: lokalId not blank, plasser ≥ 0, within Norway bounds
→ Create Shelter entity (skip malformed features with warning)
```
### Location & Navigation
**LocationProvider** abstracts GPS access with two flavor implementations:
| Flavor | Primary | Fallback |
|-----------|----------------------------------|-------------------|
| standard | FusedLocationProviderClient | LocationManager |
| fdroid | LocationManager | — |
Both emit location updates via Kotlin Flow. Update interval: 5 seconds, fastest 2 seconds.
**ShelterFinder** takes the user's position and all shelters, computes Haversine distance and initial bearing for each, sorts by distance, and returns the N nearest (default: 3) as `ShelterWithDistance` objects.
### Compass System
**Sensor priority:**
1. Rotation Vector sensor (`TYPE_ROTATION_VECTOR`) — most accurate, single sensor
2. Accelerometer + Magnetometer — low-pass filtered (α=0.25) for smoothing
3. No compass available — error message shown
**Direction calculation:**
```
arrowAngle = shelterBearing deviceHeading
```
**DirectionArrowView** is a custom View that draws:
- A large arrow rotated by `arrowAngle`, pointing toward the shelter
- An optional north indicator on the perimeter for compass calibration
### Map & Tile Caching
**Map library:** OSMDroid (OpenStreetMap, no Google dependency).
**Tile caching:** OSMDroid's built-in `SqlTileWriter` passively caches every tile loaded. `MapCacheManager` supplements this with active pre-caching:
- Pans the MapView across a 3×3 grid at zoom levels 10, 12, 14, 16
- 300ms delay between pans (respects OSM tile usage policy)
- Covers ~15km radius around the user
- Progress reported via callback for UI display
Tile cache stored in app-specific internal storage (`osmdroidBasePath`).
### Build Variants
```
productFlavors {
standard { } // Google Play Services + AOSP fallback
fdroid { } // AOSP only
}
```
The `standard` flavor adds `com.google.android.gms:play-services-location`. Runtime detection via `GoogleApiAvailability` determines which code path runs.
Both flavors produce identical user experiences — `standard` achieves faster GPS fixes and better battery efficiency when Play Services are present.
### Home Screen Widget
**ShelterWidgetProvider** displays the nearest shelter's address, capacity, and distance. Updated by:
1. **MainActivity** — sends latest location on each GPS update
2. **WorkManager**`WidgetUpdateWorker` runs every 15 minutes, requests a fresh location fix
3. **Manual** — user taps refresh button on the widget
**Location resolution (priority order):**
1. Location from intent (WorkManager or MainActivity)
2. FusedLocationProviderClient cache (standard)
3. Active GPS request (10s timeout)
4. LocationManager cache
5. SharedPreferences saved location (max 24h old)
### Deep Linking
**HTTPS App Links:** `https://tilfluktsrom.naiv.no/shelter/{lokalId}`
The domain is configured in one place: `DEEP_LINK_DOMAIN` in `build.gradle.kts` (exposed as `BuildConfig.DEEP_LINK_DOMAIN` and manifest placeholder `${deepLinkHost}`).
- `autoVerify="true"` on the HTTPS intent filter triggers Android's App Links verification at install time
- Verification requires `/.well-known/assetlinks.json` to be served by the PWA (in `pwa/public/.well-known/`)
- If the app is installed and verified, `/shelter/*` links open the app directly (no disambiguation dialog)
- If not installed, the link opens in the browser, where the PWA handles it
Share messages include the HTTPS URL, which SMS apps auto-link as a tappable URL.
---
## Progressive Web App
**Stack:** TypeScript, Vite 5, Leaflet, idb (IndexedDB wrapper), vite-plugin-pwa
**Package manager:** bun
### Module Structure
```
pwa/
├── index.html # SPA shell, CSP headers, semantic layout
├── vite.config.ts # Build config, PWA plugin, tile caching rules
├── manifest.webmanifest # PWA metadata and icons
├── scripts/
│ └── fetch-shelters.ts # Build-time: download + convert shelter data
├── public/
│ └── data/shelters.json # Pre-processed shelter data (build artifact)
└── src/
├── main.ts # Entry point, SW registration, locale init
├── app.ts # Main controller (~400 lines)
├── types.ts # Shelter, ShelterWithDistance, LatLon interfaces
├── data/
│ ├── shelter-repository.ts # Fetch + IndexedDB storage
│ └── shelter-db.ts # IndexedDB wrapper (idb library)
├── location/
│ ├── location-provider.ts # navigator.geolocation wrapper
│ ├── compass-provider.ts # DeviceOrientationEvent (iOS/Android)
│ └── shelter-finder.ts # Haversine nearest-N calculation
├── ui/
│ ├── map-view.ts # Leaflet map, custom SVG markers
│ ├── compass-view.ts # Canvas-based direction arrow
│ ├── shelter-list.ts # Bottom sheet shelter list
│ ├── loading-overlay.ts # Modal spinner / cache prompt
│ ├── about-dialog.ts # Privacy, data info, cache clear
│ ├── civil-defense-dialog.ts # DSB 5-step emergency guide
│ └── status-bar.ts # Status text and refresh button
├── cache/
│ └── map-cache-manager.ts # Tile pre-caching via programmatic panning
├── i18n/
│ ├── i18n.ts # Locale detection, string substitution
│ ├── en.ts # English strings
│ ├── nb.ts # Bokmål strings
│ └── nn.ts # Nynorsk strings
├── util/
│ └── distance-utils.ts # Haversine distance, bearing, formatting
└── main.css # Dark theme, Leaflet overrides, dialogs
```
### Build System
**Vite** bundles the app with content-hashed filenames for cache busting.
**Key configuration:**
- Base path: `./` (relative, deployable anywhere)
- `__BUILD_REVISION__` define: ISO timestamp injected at build time, used to invalidate service worker caches
- **vite-plugin-pwa**: Generates the service worker with Workbox. Precaches all static assets. Runtime-caches OSM tile requests with CacheFirst strategy (30-day expiry, max 5000 entries).
**Build-time data preprocessing:**
`scripts/fetch-shelters.ts` downloads the Geonorge ZIP, extracts the GeoJSON, converts UTM33N→WGS84, validates, and writes `public/data/shelters.json`. This means coordinate conversion is a build step, not a runtime cost.
```bash
bun run fetch-shelters # Download and convert shelter data
bun run build # TypeScript check + Vite build + SW generation
```
### Data Layer (PWA)
**Storage:** IndexedDB via the `idb` library.
**Schema:**
- Object store `shelters` (keyPath: `lokalId`) — full shelter records
- Object store `metadata``lastUpdate` timestamp
**Loading strategy:**
1. Check IndexedDB for cached shelters
2. If empty or stale (>7 days): fetch `shelters.json` (precached by service worker)
3. Replace all records in a single transaction
4. Reactive: UI reads from IndexedDB after load
Unlike the Android app, the PWA does not perform coordinate conversion at runtime — `shelters.json` is pre-converted at build time and served as a static asset.
### Location & Compass (PWA)
**Location:** `navigator.geolocation.watchPosition()` with high accuracy enabled, 10s maximum age, 30s timeout.
**Compass:** DeviceOrientationEvent with platform-specific handling:
| Platform | API | Heading Source |
|----------------|------------------------------|--------------------------|
| iOS Safari | `deviceorientation` | `webkitCompassHeading` |
| Android Chrome | `deviceorientationabsolute` | `(360 alpha) % 360` |
iOS 13+ requires an explicit permission request (`DeviceOrientationEvent.requestPermission()`), triggered by a user gesture.
Low-pass filter (smoothing factor 0.3) with 0/360° wraparound handling ensures fluid rotation.
### Map & Offline Tiles (PWA)
**Map library:** Leaflet with OpenStreetMap tiles. No CDN — Leaflet is bundled from `node_modules`.
**Custom markers:** SVG-based `divIcon` elements — orange house with "T" for shelters, blue circle for user location. Selected shelter uses a larger yellow marker.
**Auto-fit logic:** When a shelter is selected, the map fits bounds to show both user and shelter (30% padding), unless the user has manually panned or zoomed. A "reset view" button appears after manual interaction.
**Tile pre-caching:** `MapCacheManager` uses the same approach as the Android app — programmatically pans the map across a 3×3 grid at 4 zoom levels. The service worker's runtime cache intercepts and stores the tile requests. Cache location stored in localStorage (rounded to ~11km precision for privacy).
### Service Worker
Generated by vite-plugin-pwa (Workbox):
- **Precaching:** All static assets (JS, CSS, HTML, JSON, images) with content-hash versioning
- **Runtime caching:** OSM tiles from `{a,b,c}.tile.openstreetmap.org` with CacheFirst strategy, 30-day TTL, max 5000 entries
- **Navigation fallback:** Serves `index.html` for all navigation requests (SPA behavior)
- **Auto-update:** New service worker activates automatically; `controllerchange` event notifies the user
`main.ts` injects the build revision into the service worker context, ensuring each build invalidates stale caches. It also requests persistent storage (`navigator.storage.persist()`) to prevent the browser from evicting cached data.
### UI Components
The PWA uses no framework — all UI is vanilla TypeScript manipulating the DOM.
| Component | Description |
|--------------------------|----------------------------------------------------------|
| `app.ts` | Main controller: wires components, manages state |
| `map-view.ts` | Leaflet map with custom markers, auto-fit, interaction tracking |
| `compass-view.ts` | Canvas-rendered arrow with north indicator, requestAnimationFrame |
| `shelter-list.ts` | Bottom sheet with 3 nearest shelters, click selection |
| `loading-overlay.ts` | Modal: spinner during load, OK/Skip for cache prompt |
| `about-dialog.ts` | Privacy statement, data sources, "clear cache" button |
| `civil-defense-dialog.ts`| DSB emergency instructions (5 steps) |
| `status-bar.ts` | Data freshness indicator, refresh button |
Dialogs are created dynamically and implement focus management (save/restore previous focus, trap focus inside modal).
---
## Shared Algorithms
Both platforms implement these algorithms independently (no shared code), ensuring each platform has zero runtime dependencies on the other.
### UTM33N → WGS84 Conversion
**Algorithm:** Karney series expansion method.
Converts EUREF89 / UTM zone 33N (EPSG:25833) to WGS84 (EPSG:4326).
**Constants:**
- Semi-major axis: 6,378,137 m
- Flattening: 1/298.257223563
- UTM zone 33 central meridian: 15° E
- Scale factor: 0.9996
- False easting: 500,000 m
**Steps:**
1. Remove false easting/northing
2. Compute footprint latitude using series expansion
3. Apply iterative corrections for latitude and longitude
4. Add central meridian offset
**Validation:** Reject results outside Norway bounding box (5772°N, 333°E).
**Implementations:**
- Android: `util/CoordinateConverter.kt` (runtime)
- PWA: `scripts/fetch-shelters.ts` (build-time)
### Haversine Distance & Bearing
**Distance** between two WGS84 points:
```
a = sin²(Δφ/2) + cos(φ₁) · cos(φ₂) · sin²(Δλ/2)
d = 2R · atan2(√a, √(1a))
```
Where R = 6,371 km (Earth mean radius).
**Initial bearing** from point 1 to point 2:
```
θ = atan2(sin(Δλ) · cos(φ₂), cos(φ₁) · sin(φ₂) sin(φ₁) · cos(φ₂) · cos(Δλ))
```
Result in degrees: 0° = north, 90° = east, 180° = south, 270° = west.
**Implementations:**
- Android: `util/DistanceUtils.kt`
- PWA: `util/distance-utils.ts`
---
## Offline Capability Summary
| Capability | Android | PWA |
|-------------------------|----------------------------------|------------------------------------|
| Shelter data | Room DB + bundled asset seed | IndexedDB + precached JSON |
| Map tiles | OSMDroid SqlTileWriter + active pre-cache | Service worker CacheFirst + active pre-cache |
| GPS | Device hardware (no network) | Device hardware (no network) |
| Compass | Device sensors | DeviceOrientationEvent |
| Distance/bearing math | Local computation | Local computation |
| Network required for | Initial refresh, new tiles | Initial page load, new tiles |
| Staleness threshold | 7 days | 7 days |
---
## Security & Privacy
- **No tracking:** No analytics, no telemetry, no external requests beyond Geonorge data and OSM tiles
- **No user accounts:** No registration, no login, no server-side storage
- **Location stays local:** GPS coordinates are used only for distance calculation and never transmitted
- **HTTPS enforced:** Android network security config restricts to TLS; PWA CSP headers restrict connections
- **ZIP bomb protection:** 10MB limit on uncompressed GeoJSON (Android parser)
- **CSP headers (PWA):** Restrictive Content-Security-Policy blocks external scripts; `img-src` allows only OSM tile servers
- **Input validation:** Shelter data validated at parse time (bounds check, required fields, non-negative capacity)
- **Minimal permissions:** Location only; no contacts, camera, storage (except legacy tile cache on Android ≤9)
---
## Internationalization
Both platforms support three languages:
| Language | Android | PWA |
|---------------------|----------------------|----------------|
| English (default) | `values/strings.xml` | `i18n/en.ts` |
| Norwegian Bokmål | `values-nb/strings.xml` | `i18n/nb.ts` |
| Norwegian Nynorsk | `values-nn/strings.xml` | `i18n/nn.ts` |
**Android:** Uses Android's built-in locale resolution. Per-app language selection supported on Android 13+ via `locales_config.xml`.
**PWA:** Detects browser language (`navigator.language`). String substitution supports `%d` (number) and `%s` (string) placeholders. Falls back to English for unsupported locales.

View file

@ -58,10 +58,26 @@ no.naiv.tilfluktsrom/
- **fdroid**: AOSP-only, no Google dependencies - **fdroid**: AOSP-only, no Google dependencies
## Distribution ## Distribution
- **Forgejo** (primary): `kode.naiv.no/olemd/tilfluktsrom` — releases with both APK variants - **Forgejo** (primary): `kode.naiv.no/olemd/tilfluktsrom` — releases with both APK variants + PWA tarball
- **GitHub** (mirror): `github.com/olemd/tilfluktsrom` — automatically mirrored from Forgejo, do not push manually - **GitHub** (mirror): `github.com/olemd/tilfluktsrom` — automatically mirrored from Forgejo, do not push manually
- **F-Droid**: Metadata maintained in a separate fdroiddata repo (GitLab fork). F-Droid builds from source using the `fdroid` variant and signs with the F-Droid key. - **F-Droid**: Metadata maintained in a separate fdroiddata repo (GitLab fork). F-Droid builds from source using the `fdroid` variant and signs with the F-Droid key.
## Release Process
When creating a new release:
1. Bump `versionCode` and `versionName` in `app/build.gradle.kts`
2. Update User-Agent string in `ShelterRepository.kt` to match new version
3. Build Android APKs: `./gradlew assembleStandardRelease assembleFdroidRelease`
4. Build PWA: `cd pwa && bun scripts/fetch-shelters.ts && bun run build && tar -czf /tmp/tilfluktsrom-vX.Y.Z-pwa.tar.gz -C dist .`
5. Commit, push, then create Forgejo release with all three artifacts:
```bash
fj release create --create-tag vX.Y.Z --branch main \
--attach "/tmp/tilfluktsrom-vX.Y.Z-standard.apk:tilfluktsrom-vX.Y.Z-standard.apk" \
--attach "/tmp/tilfluktsrom-vX.Y.Z-fdroid.apk:tilfluktsrom-vX.Y.Z-fdroid.apk" \
--body "release notes" "vX.Y.Z"
fj release asset create vX.Y.Z /tmp/tilfluktsrom-vX.Y.Z-pwa.tar.gz tilfluktsrom-vX.Y.Z-pwa.tar.gz
```
6. Install on phone: `adb install -r app/build/outputs/apk/standard/release/app-standard-release.apk`
## Screenshots ## Screenshots
Use the Android emulator and Maestro to take screenshots for the README and fastlane metadata. Use the Android emulator and Maestro to take screenshots for the README and fastlane metadata.

View file

@ -14,8 +14,13 @@ android {
applicationId = "no.naiv.tilfluktsrom" applicationId = "no.naiv.tilfluktsrom"
minSdk = 26 minSdk = 26
targetSdk = 35 targetSdk = 35
versionCode = 11 versionCode = 12
versionName = "1.7.0" versionName = "1.8.0"
// Deep link domain — single source of truth for manifest + Kotlin code
val deepLinkDomain = "tilfluktsrom.naiv.no"
buildConfigField("String", "DEEP_LINK_DOMAIN", "\"$deepLinkDomain\"")
manifestPlaceholders["deepLinkHost"] = deepLinkDomain
} }
dependenciesInfo { dependenciesInfo {

View file

@ -29,13 +29,14 @@
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<data <data
android:scheme="tilfluktsrom" android:scheme="https"
android:host="shelter" /> android:host="${deepLinkHost}"
android:pathPrefix="/shelter/" />
</intent-filter> </intent-filter>
</activity> </activity>

View file

@ -143,12 +143,14 @@ class MainActivity : AppCompatActivity(), SensorEventListener {
} }
/** /**
* Handle tilfluktsrom://shelter/{lokalId} deep link. * Handle https://{domain}/shelter/{lokalId} deep link.
* If shelters are already loaded, select immediately; otherwise store as pending. * If shelters are already loaded, select immediately; otherwise store as pending.
*/ */
private fun handleDeepLinkIntent(intent: Intent?) { private fun handleDeepLinkIntent(intent: Intent?) {
val uri = intent?.data ?: return val uri = intent?.data ?: return
if (uri.scheme != "tilfluktsrom" || uri.host != "shelter") return if (uri.scheme != "https" ||
uri.host != BuildConfig.DEEP_LINK_DOMAIN ||
uri.path?.startsWith("/shelter/") != true) return
val lokalId = uri.lastPathSegment ?: return val lokalId = uri.lastPathSegment ?: return
// Clear intent data so config changes don't re-trigger // Clear intent data so config changes don't re-trigger
@ -669,8 +671,8 @@ class MainActivity : AppCompatActivity(), SensorEventListener {
/** /**
* Share the currently selected shelter via ACTION_SEND. * Share the currently selected shelter via ACTION_SEND.
* Includes address, capacity, geo: URI (for non-app recipients), * Includes address, capacity, geo: URI, and an HTTPS deep link
* and a tilfluktsrom:// deep link (for app users). * that opens the app (if installed) or the PWA (in browser).
*/ */
private fun shareShelter() { private fun shareShelter() {
val selected = selectedShelter val selected = selectedShelter
@ -680,12 +682,14 @@ class MainActivity : AppCompatActivity(), SensorEventListener {
} }
val shelter = selected.shelter val shelter = selected.shelter
val deepLink = "https://${BuildConfig.DEEP_LINK_DOMAIN}/shelter/${shelter.lokalId}"
val body = getString( val body = getString(
R.string.share_body, R.string.share_body,
shelter.adresse, shelter.adresse,
shelter.plasser, shelter.plasser,
shelter.latitude, shelter.latitude,
shelter.longitude shelter.longitude,
deepLink
) )
val shareIntent = Intent(Intent.ACTION_SEND).apply { val shareIntent = Intent(Intent.ACTION_SEND).apply {

View file

@ -46,7 +46,7 @@ class ShelterRepository(private val context: Context) {
.readTimeout(60, TimeUnit.SECONDS) .readTimeout(60, TimeUnit.SECONDS)
.addInterceptor(Interceptor { chain -> .addInterceptor(Interceptor { chain ->
chain.proceed(chain.request().newBuilder() chain.proceed(chain.request().newBuilder()
.header("User-Agent", "Tilfluktsrom/1.7.0") .header("User-Agent", "Tilfluktsrom/1.8.0")
.build()) .build())
}) })
.build() .build()

View file

@ -60,7 +60,7 @@
<!-- Deling --> <!-- Deling -->
<string name="share_subject">Tilfluktsrom</string> <string name="share_subject">Tilfluktsrom</string>
<string name="share_body">Tilfluktsrom: %1$s\n%2$d plasser\n%3$.6f, %4$.6f\ngeo:%3$.6f,%4$.6f</string> <string name="share_body">Tilfluktsrom: %1$s\n%2$d plasser\n%3$.6f, %4$.6f\ngeo:%3$.6f,%4$.6f\n%5$s</string>
<string name="share_no_shelter">Ingen tilfluktsrom valgt</string> <string name="share_no_shelter">Ingen tilfluktsrom valgt</string>
<!-- Tilgjengelighet --> <!-- Tilgjengelighet -->

View file

@ -60,7 +60,7 @@
<!-- Deling --> <!-- Deling -->
<string name="share_subject">Tilfluktsrom</string> <string name="share_subject">Tilfluktsrom</string>
<string name="share_body">Tilfluktsrom: %1$s\n%2$d plassar\n%3$.6f, %4$.6f\ngeo:%3$.6f,%4$.6f</string> <string name="share_body">Tilfluktsrom: %1$s\n%2$d plassar\n%3$.6f, %4$.6f\ngeo:%3$.6f,%4$.6f\n%5$s</string>
<string name="share_no_shelter">Ingen tilfluktsrom valt</string> <string name="share_no_shelter">Ingen tilfluktsrom valt</string>
<!-- Tilgjenge --> <!-- Tilgjenge -->

View file

@ -60,7 +60,7 @@
<!-- Sharing --> <!-- Sharing -->
<string name="share_subject">Emergency shelter</string> <string name="share_subject">Emergency shelter</string>
<string name="share_body">Shelter: %1$s\n%2$d places\n%3$.6f, %4$.6f\ngeo:%3$.6f,%4$.6f</string> <string name="share_body">Shelter: %1$s\n%2$d places\n%3$.6f, %4$.6f\ngeo:%3$.6f,%4$.6f\n%5$s</string>
<string name="share_no_shelter">No shelter selected</string> <string name="share_no_shelter">No shelter selected</string>
<!-- Accessibility --> <!-- Accessibility -->

1
pwa/.gitignore vendored
View file

@ -1,2 +1,3 @@
node_modules/ node_modules/
dist/ dist/
public/data/shelters.json

View file

@ -6,14 +6,11 @@
<meta name="theme-color" content="#1A1A2E" /> <meta name="theme-color" content="#1A1A2E" />
<meta name="description" content="Find the nearest public shelter in Norway" /> <meta name="description" content="Find the nearest public shelter in Norway" />
<meta http-equiv="Content-Security-Policy" <meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline' https://unpkg.com; img-src 'self' data: https://*.tile.openstreetmap.org https://unpkg.com; connect-src 'self' https://*.tile.openstreetmap.org; font-src 'self'; worker-src 'self'" /> content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://*.tile.openstreetmap.org; connect-src 'self' https://*.tile.openstreetmap.org; font-src 'self'; worker-src 'self'" />
<title>Tilfluktsrom</title> <title>Tilfluktsrom</title>
<link rel="manifest" href="/manifest.webmanifest" /> <link rel="manifest" href="manifest.webmanifest" />
<link rel="icon" type="image/png" sizes="192x192" href="/icons/icon-192.png" /> <link rel="icon" type="image/png" sizes="192x192" href="icons/icon-192.png" />
<link rel="apple-touch-icon" href="/icons/icon-192.png" /> <link rel="apple-touch-icon" href="icons/icon-192.png" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin="anonymous" />
</head> </head>
<body> <body>
<div id="app"> <div id="app">
@ -66,6 +63,6 @@
</div> </div>
</div> </div>
<script type="module" src="/src/main.ts"></script> <script type="module" src="src/main.ts"></script>
</body> </body>
</html> </html>

View file

@ -0,0 +1,12 @@
[
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "no.naiv.tilfluktsrom",
"sha256_cert_fingerprints": [
"43:05:79:6F:EA:3E:F4:50:45:D3:8A:EF:EA:58:B6:65:49:D2:D2:C3:4B:4C:61:11:EE:74:48:B0:C7:70:E4:5B"
]
}
}
]

File diff suppressed because it is too large Load diff

View file

@ -2,20 +2,21 @@
"name": "Tilfluktsrom", "name": "Tilfluktsrom",
"short_name": "Tilfluktsrom", "short_name": "Tilfluktsrom",
"description": "Find the nearest public shelter in Norway", "description": "Find the nearest public shelter in Norway",
"start_url": "/", "start_url": ".",
"scope": ".",
"display": "standalone", "display": "standalone",
"orientation": "portrait", "orientation": "portrait",
"theme_color": "#1A1A2E", "theme_color": "#1A1A2E",
"background_color": "#1A1A2E", "background_color": "#1A1A2E",
"icons": [ "icons": [
{ {
"src": "/icons/icon-192.png", "src": "icons/icon-192.png",
"sizes": "192x192", "sizes": "192x192",
"type": "image/png", "type": "image/png",
"purpose": "any maskable" "purpose": "any maskable"
}, },
{ {
"src": "/icons/icon-512.png", "src": "icons/icon-512.png",
"sizes": "512x512", "sizes": "512x512",
"type": "image/png", "type": "image/png",
"purpose": "any maskable" "purpose": "any maskable"

View file

@ -9,7 +9,7 @@
import type { Shelter, ShelterWithDistance, LatLon } from './types'; import type { Shelter, ShelterWithDistance, LatLon } from './types';
import { t } from './i18n/i18n'; import { t } from './i18n/i18n';
import { formatDistance } from './util/distance-utils'; import { formatDistance, distanceMeters, bearingDegrees } from './util/distance-utils';
import { findNearest } from './location/shelter-finder'; import { findNearest } from './location/shelter-finder';
import * as repo from './data/shelter-repository'; import * as repo from './data/shelter-repository';
import * as locationProvider from './location/location-provider'; import * as locationProvider from './location/location-provider';
@ -20,7 +20,7 @@ import * as shelterList from './ui/shelter-list';
import * as statusBar from './ui/status-bar'; import * as statusBar from './ui/status-bar';
import * as loading from './ui/loading-overlay'; import * as loading from './ui/loading-overlay';
import * as mapCache from './cache/map-cache-manager'; import * as mapCache from './cache/map-cache-manager';
import * as aboutDialog from './ui/about-dialog'; import * as civilDefenseDialog from './ui/civil-defense-dialog';
const NEAREST_COUNT = 3; const NEAREST_COUNT = 3;
@ -43,14 +43,15 @@ export async function init(): Promise<void> {
setupShelterList(); setupShelterList();
setupButtons(); setupButtons();
await loadData(); await loadData();
handleDeepLink();
} }
/** Set localized aria-labels and wire the about button. */ /** Set localized aria-labels and wire the about button. */
function applyA11yLabels(): void { function applyA11yLabels(): void {
document.getElementById('about-btn')?.setAttribute('aria-label', t('action_about')); document.getElementById('about-btn')?.setAttribute('aria-label', t('action_civil_defense_info'));
document.getElementById('about-btn')?.addEventListener('click', () => { document.getElementById('about-btn')?.addEventListener('click', () => {
navigator.vibrate?.(10); navigator.vibrate?.(10);
aboutDialog.showAbout(); civilDefenseDialog.showCivilDefenseInfo();
}); });
document.getElementById('map-container')?.setAttribute('aria-label', t('a11y_map')); document.getElementById('map-container')?.setAttribute('aria-label', t('a11y_map'));
document.getElementById('compass-container')?.setAttribute('aria-label', t('a11y_compass')); document.getElementById('compass-container')?.setAttribute('aria-label', t('a11y_compass'));
@ -108,6 +109,7 @@ function setupButtons(): void {
} }
mapContainer.style.display = 'none'; mapContainer.style.display = 'none';
compassContainer.classList.add('active'); compassContainer.classList.add('active');
compassView.resize();
toggleFab.textContent = '\uD83D\uDDFA\uFE0F'; // map emoji toggleFab.textContent = '\uD83D\uDDFA\uFE0F'; // map emoji
compassProvider.startCompass(onHeadingUpdate); compassProvider.startCompass(onHeadingUpdate);
} else { } else {
@ -397,3 +399,67 @@ async function forceRefresh(): Promise<void> {
statusBar.setStatus(t('update_failed')); statusBar.setStatus(t('update_failed'));
} }
} }
/**
* Handle /shelter/{lokalId} deep links.
* Called after loadData() so allShelters is populated.
*/
function handleDeepLink(): void {
const match = window.location.pathname.match(/^\/shelter\/(.+)$/);
if (!match) return;
const lokalId = decodeURIComponent(match[1]);
// Clean the URL so refresh doesn't re-trigger
window.history.replaceState({}, '', '/');
const shelter = allShelters.find((s) => s.lokalId === lokalId);
if (!shelter) {
statusBar.setStatus(t('error_shelter_not_found'));
return;
}
selectShelterByData(shelter);
}
/**
* Select a specific shelter, even if it's not in the current nearest-3 list.
* Used for deep link targets.
*/
function selectShelterByData(shelter: Shelter): void {
// Check if it's already in nearestShelters
const existingIdx = nearestShelters.findIndex(
(s) => s.shelter.lokalId === shelter.lokalId,
);
if (existingIdx >= 0) {
userSelectedShelter = true;
selectedShelterIndex = existingIdx;
} else {
// Compute distance/bearing if we have a location, otherwise use placeholder
let dist = NaN;
let bearing = 0;
if (currentLocation) {
dist = distanceMeters(
currentLocation.latitude, currentLocation.longitude,
shelter.latitude, shelter.longitude,
);
bearing = bearingDegrees(
currentLocation.latitude, currentLocation.longitude,
shelter.latitude, shelter.longitude,
);
}
// Prepend to the list so it becomes the selected shelter
nearestShelters.unshift({
shelter,
distanceMeters: dist,
bearingDegrees: bearing,
});
userSelectedShelter = true;
selectedShelterIndex = 0;
shelterList.updateList(nearestShelters, selectedShelterIndex);
}
updateSelectedShelter(true);
}

2
pwa/src/config.ts Normal file
View file

@ -0,0 +1,2 @@
/** Deep link domain — single source of truth for the PWA. */
export const DEEP_LINK_DOMAIN = 'tilfluktsrom.naiv.no';

View file

@ -46,6 +46,7 @@ export const en: Record<string, string> = {
'No cached data available. Connect to the internet to download shelter data.', 'No cached data available. Connect to the internet to download shelter data.',
update_success: 'Shelter data updated', update_success: 'Shelter data updated',
update_failed: 'Update failed \u2014 using cached data', update_failed: 'Update failed \u2014 using cached data',
error_shelter_not_found: 'Shelter not found',
// Accessibility // Accessibility
direction_arrow_description: 'Direction to shelter, %s away', direction_arrow_description: 'Direction to shelter, %s away',
@ -54,6 +55,21 @@ export const en: Record<string, string> = {
a11y_shelter_info: 'Shelter info', a11y_shelter_info: 'Shelter info',
a11y_nearest_shelters: 'Nearest shelters', a11y_nearest_shelters: 'Nearest shelters',
// Civil defense
action_civil_defense_info: 'Civil defense information',
civil_defense_title: 'What to do if the alarm sounds',
civil_defense_step1_title: '1. Important message signal',
civil_defense_step1_body: 'Three series of short blasts with one minute of silence between each series. This means: seek information immediately. Turn on DAB radio, TV, or check official sources online.',
civil_defense_step2_title: '2. Air raid alarm',
civil_defense_step2_body: 'Short blasts lasting approximately one minute. This means immediate danger of attack — seek shelter now. Go to the nearest shelter, basement, or inner room immediately.',
civil_defense_step3_title: '3. Go indoors and find shelter',
civil_defense_step3_body: 'Get indoors. Close all windows, doors, and ventilation openings. Use this app to find the nearest public shelter. The compass and map work offline. If no shelter is nearby, go to a basement or an inner room away from windows.',
civil_defense_step4_title: '4. Listen to NRK on DAB radio',
civil_defense_step4_body: 'Tune in to NRK P1 on DAB radio for official updates and instructions from authorities. DAB radio works even when mobile networks and the internet are down.',
civil_defense_step5_title: '5. All clear',
civil_defense_step5_body: 'One continuous tone lasting approximately 30 seconds. The danger or attack is over. Continue to follow instructions from authorities.',
civil_defense_source: 'Source: DSB (Norwegian Directorate for Civil Protection)',
// About // About
about_title: 'About Tilfluktsrom', about_title: 'About Tilfluktsrom',
about_description: about_description:
@ -71,4 +87,6 @@ export const en: Record<string, string> = {
about_open_source: 'Open source — kode.naiv.no/olemd/tilfluktsrom', about_open_source: 'Open source — kode.naiv.no/olemd/tilfluktsrom',
action_about: 'About', action_about: 'About',
action_close: 'Close', action_close: 'Close',
action_clear_cache: 'Clear cached data',
cache_cleared: 'All cached data cleared',
}; };

View file

@ -41,6 +41,7 @@ export const nb: Record<string, string> = {
'Ingen lagrede data tilgjengelig. Koble til internett for å laste ned tilfluktsromdata.', 'Ingen lagrede data tilgjengelig. Koble til internett for å laste ned tilfluktsromdata.',
update_success: 'Tilfluktsromdata oppdatert', update_success: 'Tilfluktsromdata oppdatert',
update_failed: 'Oppdatering mislyktes — bruker lagrede data', update_failed: 'Oppdatering mislyktes — bruker lagrede data',
error_shelter_not_found: 'Fant ikke tilfluktsrommet',
// Tilgjengelighet // Tilgjengelighet
direction_arrow_description: 'Retning til tilfluktsrom, %s unna', direction_arrow_description: 'Retning til tilfluktsrom, %s unna',
@ -49,6 +50,21 @@ export const nb: Record<string, string> = {
a11y_shelter_info: 'Tilfluktsrominfo', a11y_shelter_info: 'Tilfluktsrominfo',
a11y_nearest_shelters: 'Nærmeste tilfluktsrom', a11y_nearest_shelters: 'Nærmeste tilfluktsrom',
// Sivilforsvar
action_civil_defense_info: 'Sivilforsvarsinformasjon',
civil_defense_title: 'Hva du skal gjøre hvis alarmen går',
civil_defense_step1_title: '1. Viktig melding-signalet',
civil_defense_step1_body: 'Tre serier med korte støt med ett minutts stillhet mellom hver serie. Dette betyr: søk informasjon umiddelbart. Slå på DAB-radio, TV, eller sjekk offisielle kilder på nett.',
civil_defense_step2_title: '2. Flyalarm',
civil_defense_step2_body: 'Korte støt som varer omtrent ett minutt. Dette betyr umiddelbar fare for angrep — søk dekning nå. Gå til nærmeste tilfluktsrom, kjeller eller innerrom umiddelbart.',
civil_defense_step3_title: '3. Gå innendørs og finn dekning',
civil_defense_step3_body: 'Kom deg innendørs. Lukk alle vinduer, dører og ventilasjonsåpninger. Bruk denne appen for å finne nærmeste offentlige tilfluktsrom. Kompasset og kartet fungerer uten internett. Hvis det ikke er noe tilfluktsrom i nærheten, gå til en kjeller eller et innerrom bort fra vinduer.',
civil_defense_step4_title: '4. Lytt til NRK på DAB-radio',
civil_defense_step4_body: 'Lytt til NRK P1 på DAB-radio for offisielle oppdateringer og instruksjoner fra myndighetene. DAB-radio fungerer selv når mobilnettet og internett er nede.',
civil_defense_step5_title: '5. Faren over',
civil_defense_step5_body: 'Én sammenhengende tone på omtrent 30 sekunder. Faren eller angrepet er over. Fortsett å følge instruksjoner fra myndighetene.',
civil_defense_source: 'Kilde: DSB (Direktoratet for samfunnssikkerhet og beredskap)',
// Om // Om
about_title: 'Om Tilfluktsrom', about_title: 'Om Tilfluktsrom',
about_description: about_description:
@ -66,4 +82,6 @@ export const nb: Record<string, string> = {
about_open_source: 'Åpen kildekode — kode.naiv.no/olemd/tilfluktsrom', about_open_source: 'Åpen kildekode — kode.naiv.no/olemd/tilfluktsrom',
action_about: 'Om', action_about: 'Om',
action_close: 'Lukk', action_close: 'Lukk',
action_clear_cache: 'Slett lagrede data',
cache_cleared: 'Alle lagrede data slettet',
}; };

View file

@ -41,6 +41,7 @@ export const nn: Record<string, string> = {
'Ingen lagra data tilgjengeleg. Kopla til internett for å laste ned tilfluktsromdata.', 'Ingen lagra data tilgjengeleg. Kopla til internett for å laste ned tilfluktsromdata.',
update_success: 'Tilfluktsromdata oppdatert', update_success: 'Tilfluktsromdata oppdatert',
update_failed: 'Oppdatering mislukkast — brukar lagra data', update_failed: 'Oppdatering mislukkast — brukar lagra data',
error_shelter_not_found: 'Fann ikkje tilfluktsrommet',
// Tilgjenge // Tilgjenge
direction_arrow_description: 'Retning til tilfluktsrom, %s unna', direction_arrow_description: 'Retning til tilfluktsrom, %s unna',
@ -49,6 +50,21 @@ export const nn: Record<string, string> = {
a11y_shelter_info: 'Tilfluktsrominfo', a11y_shelter_info: 'Tilfluktsrominfo',
a11y_nearest_shelters: 'Nærmaste tilfluktsrom', a11y_nearest_shelters: 'Nærmaste tilfluktsrom',
// Sivilforsvar
action_civil_defense_info: 'Sivilforsvarsinformasjon',
civil_defense_title: 'Kva du skal gjere om alarmen går',
civil_defense_step1_title: '1. Viktig melding-signalet',
civil_defense_step1_body: 'Tre seriar med korte støyt med eitt minutt stille mellom kvar serie. Dette tyder: søk informasjon med ein gong. Slå på DAB-radio, TV, eller sjekk offisielle kjelder på nett.',
civil_defense_step2_title: '2. Flyalarm',
civil_defense_step2_body: 'Korte støyt som varar omtrent eitt minutt. Dette tyder umiddelbar fare for åtak — søk dekning no. Gå til næraste tilfluktsrom, kjellar eller innerrom med ein gong.',
civil_defense_step3_title: '3. Gå innandørs og finn dekning',
civil_defense_step3_body: 'Kom deg innandørs. Lukk alle vindauge, dører og ventilasjonsopningar. Bruk denne appen for å finne næraste offentlege tilfluktsrom. Kompasset og kartet fungerer utan internett. Om det ikkje er noko tilfluktsrom i nærleiken, gå til ein kjellar eller eit innerrom bort frå vindauge.',
civil_defense_step4_title: '4. Lytt til NRK på DAB-radio',
civil_defense_step4_body: 'Lytt til NRK P1 på DAB-radio for offisielle oppdateringar og instruksjonar frå styresmaktene. DAB-radio fungerer sjølv når mobilnettet og internett er nede.',
civil_defense_step5_title: '5. Faren over',
civil_defense_step5_body: 'Éin samanhengande tone på omtrent 30 sekund. Faren eller åtaket er over. Hald fram med å følgje instruksjonar frå styresmaktene.',
civil_defense_source: 'Kjelde: DSB (Direktoratet for samfunnstryggleik og beredskap)',
// Om // Om
about_title: 'Om Tilfluktsrom', about_title: 'Om Tilfluktsrom',
about_description: about_description:
@ -66,4 +82,6 @@ export const nn: Record<string, string> = {
about_open_source: 'Open kjeldekode — kode.naiv.no/olemd/tilfluktsrom', about_open_source: 'Open kjeldekode — kode.naiv.no/olemd/tilfluktsrom',
action_about: 'Om', action_about: 'Om',
action_close: 'Lukk', action_close: 'Lukk',
action_clear_cache: 'Slett lagra data',
cache_cleared: 'Alle lagra data sletta',
}; };

View file

@ -458,6 +458,48 @@ html, body {
margin-bottom: 2px; margin-bottom: 2px;
} }
#civil-defense-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.85);
z-index: 2000;
display: flex;
align-items: center;
justify-content: center;
padding: 16px;
}
.about-link-btn {
display: block;
margin: 16px 0 0;
padding: 0;
background: none;
border: none;
color: #FF6B35;
font-size: 14px;
cursor: pointer;
min-height: 48px;
line-height: 48px;
}
.about-clear-btn {
display: block;
margin: 12px 0 0;
padding: 8px 16px;
background: transparent;
border: 1px solid #90A4AE;
border-radius: 6px;
color: #90A4AE;
font-size: 13px;
cursor: pointer;
}
.about-clear-btn:disabled {
border-color: #4a6a5a;
color: #4a6a5a;
cursor: default;
}
.about-close-btn { .about-close-btn {
display: block; display: block;
margin: 16px auto 0; margin: 16px auto 0;

View file

@ -1,5 +1,6 @@
/** /**
* About dialog: app info, privacy statement, data sources, copyright. * About dialog: app info, privacy statement, data sources, copyright.
* Includes a "Clear cached data" button that removes all local storage.
* Opens as a modal overlay, same pattern as loading-overlay. * Opens as a modal overlay, same pattern as loading-overlay.
*/ */
@ -35,6 +36,13 @@ export function showAbout(): void {
content.appendChild(subheading(t('about_stored_title'))); content.appendChild(subheading(t('about_stored_title')));
content.appendChild(para(t('about_stored_body'))); content.appendChild(para(t('about_stored_body')));
// Clear cache button
const clearBtn = document.createElement('button');
clearBtn.className = 'about-clear-btn';
clearBtn.textContent = t('action_clear_cache');
clearBtn.addEventListener('click', () => clearAllData(clearBtn));
content.appendChild(clearBtn);
const footer = document.createElement('div'); const footer = document.createElement('div');
footer.className = 'about-footer'; footer.className = 'about-footer';
footer.appendChild(small(t('about_copyright'))); footer.appendChild(small(t('about_copyright')));
@ -63,6 +71,28 @@ export function hideAbout(): void {
previousFocus = null; previousFocus = null;
} }
/** Clear all cached data: IndexedDB, localStorage, and service worker caches. */
async function clearAllData(btn: HTMLButtonElement): Promise<void> {
btn.disabled = true;
// Clear localStorage (map cache metadata)
localStorage.clear();
// Clear IndexedDB (shelter database)
const dbs = await indexedDB.databases?.() ?? [];
for (const db of dbs) {
if (db.name) indexedDB.deleteDatabase(db.name);
}
// Clear service worker caches (map tiles, precache)
const cacheNames = await caches.keys();
for (const name of cacheNames) {
await caches.delete(name);
}
btn.textContent = t('cache_cleared');
}
function heading(text: string): HTMLElement { function heading(text: string): HTMLElement {
const el = document.createElement('h2'); const el = document.createElement('h2');
el.textContent = text; el.textContent = text;

View file

@ -0,0 +1,96 @@
/**
* Civil defense info dialog: what to do when the alarm sounds.
* Same content as the Android CivilDefenseInfoDialog.
* Links to the about dialog at the bottom.
*/
import { t } from '../i18n/i18n';
import { showAbout } from './about-dialog';
let overlay: HTMLDivElement | null = null;
let previousFocus: HTMLElement | null = null;
/** Show the civil defense info dialog. */
export function showCivilDefenseInfo(): void {
if (overlay) return;
previousFocus = document.activeElement as HTMLElement | null;
overlay = document.createElement('div');
overlay.id = 'civil-defense-overlay';
overlay.setAttribute('role', 'dialog');
overlay.setAttribute('aria-modal', 'true');
overlay.setAttribute('aria-label', t('civil_defense_title'));
const content = document.createElement('div');
content.className = 'about-content';
content.appendChild(heading(t('civil_defense_title')));
for (let i = 1; i <= 5; i++) {
content.appendChild(subheading(t(`civil_defense_step${i}_title`)));
content.appendChild(para(t(`civil_defense_step${i}_body`)));
}
content.appendChild(small(t('civil_defense_source')));
// "About this app" link
const aboutLink = document.createElement('button');
aboutLink.className = 'about-link-btn';
aboutLink.textContent = t('action_about');
aboutLink.addEventListener('click', () => {
hideCivilDefenseInfo();
showAbout();
});
content.appendChild(aboutLink);
const closeBtn = document.createElement('button');
closeBtn.className = 'about-close-btn';
closeBtn.textContent = t('action_close');
closeBtn.addEventListener('click', hideCivilDefenseInfo);
content.appendChild(closeBtn);
overlay.appendChild(content);
document.body.appendChild(overlay);
closeBtn.focus();
}
/** Hide the dialog and restore focus. */
export function hideCivilDefenseInfo(): void {
if (overlay) {
overlay.remove();
overlay = null;
}
previousFocus?.focus();
previousFocus = null;
}
function heading(text: string): HTMLElement {
const el = document.createElement('h2');
el.textContent = text;
el.className = 'about-heading';
return el;
}
function subheading(text: string): HTMLElement {
const el = document.createElement('h3');
el.textContent = text;
el.className = 'about-subheading';
return el;
}
function para(text: string): HTMLElement {
const el = document.createElement('p');
el.textContent = text;
el.className = 'about-para';
return el;
}
function small(text: string): HTMLElement {
const el = document.createElement('p');
el.textContent = text;
el.className = 'about-small';
el.style.fontStyle = 'italic';
return el;
}

View file

@ -135,6 +135,11 @@ function drawNorthIndicator(
c.restore(); c.restore();
} }
/** Resize the canvas (call when the compass container becomes visible). */
export function resize(): void {
resizeCanvas();
}
/** Clean up compass resources. */ /** Clean up compass resources. */
export function destroyCompass(): void { export function destroyCompass(): void {
window.removeEventListener('resize', resizeCanvas); window.removeEventListener('resize', resizeCanvas);

View file

@ -6,6 +6,8 @@
* Focus is moved into the dialog when shown and restored when hidden. * Focus is moved into the dialog when shown and restored when hidden.
*/ */
import { t } from '../i18n/i18n';
/** Element that had focus before the overlay opened. */ /** Element that had focus before the overlay opened. */
let previousFocus: HTMLElement | null = null; let previousFocus: HTMLElement | null = null;
@ -45,6 +47,9 @@ export function showCachePrompt(
buttonRow.style.display = 'flex'; buttonRow.style.display = 'flex';
overlay.style.display = 'flex'; overlay.style.display = 'flex';
okBtn.textContent = t('action_cache_ok');
skipBtn.textContent = t('action_skip');
okBtn.onclick = () => { okBtn.onclick = () => {
hideLoading(); hideLoading();
onOk(); onOk();

View file

@ -6,16 +6,19 @@
*/ */
import L from 'leaflet'; import L from 'leaflet';
import markerIcon from 'leaflet/dist/images/marker-icon.png';
import markerIcon2x from 'leaflet/dist/images/marker-icon-2x.png';
import markerShadow from 'leaflet/dist/images/marker-shadow.png';
import type { Shelter, ShelterWithDistance, LatLon } from '../types'; import type { Shelter, ShelterWithDistance, LatLon } from '../types';
import { t } from '../i18n/i18n'; import { t } from '../i18n/i18n';
// Fix Leaflet default icon paths (broken by bundlers) // Fix Leaflet default icon paths (broken by bundlers) — use bundled assets
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (L.Icon.Default.prototype as any)._getIconUrl; delete (L.Icon.Default.prototype as any)._getIconUrl;
L.Icon.Default.mergeOptions({ L.Icon.Default.mergeOptions({
iconUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon.png', iconUrl: markerIcon,
iconRetinaUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon-2x.png', iconRetinaUrl: markerIcon2x,
shadowUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-shadow.png', shadowUrl: markerShadow,
}); });
const DEFAULT_ZOOM = 14; const DEFAULT_ZOOM = 14;

View file

@ -2,6 +2,7 @@ import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa'; import { VitePWA } from 'vite-plugin-pwa';
export default defineConfig({ export default defineConfig({
base: '/',
define: { define: {
// Injected as a global — changes every build, breaking any stale cache // Injected as a global — changes every build, breaking any stale cache
__BUILD_REVISION__: JSON.stringify( __BUILD_REVISION__: JSON.stringify(
@ -21,7 +22,7 @@ export default defineConfig({
cleanupOutdatedCaches: true, cleanupOutdatedCaches: true,
// SPA: serve index.html for all navigation requests // SPA: serve index.html for all navigation requests
navigateFallback: '/index.html', navigateFallback: 'index.html',
// Vite already hashes JS/CSS filenames — skip Workbox's // Vite already hashes JS/CSS filenames — skip Workbox's
// cache-bust query parameter for those // cache-bust query parameter for those