mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-09-22 03:35:06 -04:00
androidx.datastore.preferences publishes no wasmJs variant at any version, so core:prefs can no longer depend on DataStore<Preferences> from commonMain. Introduces PrefsStore/PrefsSnapshot/PrefsKey (core/prefs/store/PrefsStore.kt), a minimal interface mirroring DataStore<Preferences>'s own shape closely enough that porting each *PrefsImpl off DataStore is a mechanical key-factory rename, not a rewrite. Two implementations: nonWebMain's DataStorePrefsStore adapts a real DataStore<Preferences> (android/jvm/iOS unchanged underneath), and wasmJsMain's LocalStoragePrefsStore is backed by the browser's localStorage directly -- synchronous and built-in, so unlike core:database's OPFS story this needs no Worker or npm dependency. Unlike core:database's DatabaseManager split, none of the 17 *PrefsImpl classes needed to move out of commonMain: the platform difference is fully absorbed inside PrefsStore's two implementations, so every impl's diff is exactly the mechanical shape promised (defaults, migration logic, dynamic per-node keys all unchanged). PrefsDataStores.kt's 12 marker interfaces/wrappers get the same mechanical swap. Enabling core:prefs's wasmJs target exposed a second, one-module-upstream gap: core:repository had no wasmJs target at all (its `expect class Location` had android/jvm/iOS actuals but no wasmJs one). Fixed with a wasmJsMain placeholder mirroring the existing jvmMain placeholder exactly -- desktop has no real location hardware either, so this introduces no new product decision, just parity with the platform that already has none. core:service's MeshLogCleanupWorkerTest fake DataStore<Preferences> is updated to fake PrefsStore/PrefsSnapshot instead, following the interface change through its one external consumer. CorePrefsWasmJsModule (new Koin module, localStorage-backed) is not yet registered anywhere -- no webApp module exists yet to wire it into, same as core:database's SingleDatabaseProvider precedent. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
:core:prefs
Overview
The :core:prefs module provides a type-safe preferences layer backed by DataStore (multiplatform). On Android, legacy SharedPreferences are automatically migrated to DataStore on first access via SharedPreferencesMigration.
Key Components
1. DataStore Providers (CorePrefsAndroidModule)
Provides named DataStore<Preferences> singletons for each preference domain (analytics, app, map, mesh, radio, UI, etc.). Each DataStore uses an injected CoroutineDispatchers.io scope and includes a SharedPreferencesMigration for seamless migration from the legacy preference files.
2. Specialized Prefs
RadioPrefs: Manages radio-specific settings (e.g., the last connected device address).UiPrefs: Manages UI preferences (e.g., theme selection, unit systems).MapPrefs: Manages mapping preferences (e.g., preferred map provider).
Dependency Graph
graph TB
:core:prefs[prefs]:::kmp-library
:core:prefs -.-> :core:repository
:core:prefs -.-> :core:common
:core:prefs -.-> :core:di
classDef android-application fill:#CAFFBF,stroke:#000,stroke-width:2px,color:#000;
classDef android-application-compose fill:#CAFFBF,stroke:#000,stroke-width:2px,color:#000;
classDef compose-desktop-application fill:#CAFFBF,stroke:#000,stroke-width:2px,color:#000;
classDef android-feature fill:#FFD6A5,stroke:#000,stroke-width:2px,color:#000;
classDef android-library fill:#9BF6FF,stroke:#000,stroke-width:2px,color:#000;
classDef android-library-compose fill:#9BF6FF,stroke:#000,stroke-width:2px,color:#000;
classDef android-test fill:#A0C4FF,stroke:#000,stroke-width:2px,color:#000;
classDef jvm-library fill:#BDB2FF,stroke:#000,stroke-width:2px,color:#000;
classDef kmp-feature fill:#FFD6A5,stroke:#000,stroke-width:2px,color:#000;
classDef kmp-library-compose fill:#FFC1CC,stroke:#000,stroke-width:2px,color:#000;
classDef kmp-library fill:#FFC1CC,stroke:#000,stroke-width:2px,color:#000;
classDef unknown fill:#FFADAD,stroke:#000,stroke-width:2px,color:#000;