feat(phase-1/m3.1): :core:settings — SettingsRepository shared, store injected
Milestone M3 task 1 (DESKTOP_PHASE_PLAN §5): move UserSettings +
SettingsRepository into a plain kotlin("jvm") module so the desktop
build reads/writes the SAME preferences keys and .preferences_pb format
the phone uses. Package name org.incido.compose.data.settings kept, so
the Android diff is file moves + one constructor change.
Seam: SettingsRepository now takes an injected DataStore<Preferences>.
Android supplies the preferencesDataStore(name = "incido_settings")
Context-extension store (new AndroidSettingsStore.kt, moved verbatim);
desktop builds it with PreferenceDataStoreFactory.create(
corruptionHandler = ReplaceFileCorruptionHandler, produceFile) — the
Phase-0 API delta (no Context extension on the multiplatform core
artifact). snapshot() keeps runBlocking for startup-only use.
DesktopContainer grows settingsRepository first, mirroring AppContainer
construction order ahead of M3's cipher install. dynamic_color /
use_biometric / block_screenshots keys ride along but have no desktop
UI — hidden, not faked (M3 exit rule).
Verified: ./gradlew assembleDebug (green; :app needed :core:settings on
its classpath — MainActivity reads userSettingsFlow, same pattern as
:core:domain) + ./gradlew :desktopApp:run --args="--data-dir
/tmp/incido-desktop-smoke --self-test --exit-after 6" (RENDER/SELFTEST
sequence intact) + ./gradlew :core:data-jvm:smoke (green).
This commit is contained in:
1 parent
561d16eb0c
commit
8db835640e
10 files changed
+131
-30
No files matched your search
@@ -1,6 +1,12 @@
|
||||
package org.incido.desktop
|
||||
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
|
||||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.emptyPreferences
|
||||
import java.io.File
|
||||
import org.incido.compose.data.settings.SettingsRepository
|
||||
import org.incido.data.ImageOrientationNormalizer
|
||||
import org.incido.data.ObjectBoxStore
|
||||
import org.incido.data.crypto.CipherHolder
|
||||
@@ -11,10 +17,10 @@ import org.incido.domain.repository.NoteRepository
|
||||
* Hand-rolled DI container for the desktop build — the JVM counterpart of
|
||||
* the Android app's `AppContainer` (Development Plan §6, Phase 1, M1b).
|
||||
*
|
||||
* Deliberately mirrors Android's construction order: open the store, then
|
||||
* build the repository over a shared [CipherHolder] so installing or removing
|
||||
* at-rest encryption later is a one-line change here instead of a rebuild of
|
||||
* the graph.
|
||||
* Deliberately mirrors Android's construction order: settings first (M3),
|
||||
* then open the store, then build the repository over a shared
|
||||
* [CipherHolder] so installing or removing at-rest encryption later is a
|
||||
* one-line change here instead of a rebuild of the graph.
|
||||
*
|
||||
* Two Android behaviours are intentionally absent, both planned work:
|
||||
* - at-rest encryption (milestone M3 — needs a JVM KeyProvider; the
|
||||
@@ -24,6 +30,18 @@ import org.incido.domain.repository.NoteRepository
|
||||
*/
|
||||
class DesktopContainer(dataDir: File) {
|
||||
|
||||
/**
|
||||
* Phase 1 (M3 task 1): the same settings the phone stores, in the same
|
||||
* `.preferences_pb` format, living inside this library's data dir.
|
||||
* SPIKE FINDING applied: the multiplatform DataStore has no
|
||||
* `preferencesDataStore(name = …)` extension — the store is created
|
||||
* from a file with PreferenceDataStoreFactory + a corruption handler
|
||||
* that replaces an unreadable file with empty preferences (same
|
||||
* semantics as Android's default).
|
||||
*/
|
||||
val settingsRepository: SettingsRepository =
|
||||
SettingsRepository(preferencesStore(dataDir, "incido_settings"))
|
||||
|
||||
val cipherHolder = CipherHolder()
|
||||
|
||||
val boxStore = ObjectBoxStore.init(dataDir)
|
||||
@@ -37,6 +55,19 @@ class DesktopContainer(dataDir: File) {
|
||||
fun shutdown() = ObjectBoxStore.reset()
|
||||
}
|
||||
|
||||
/**
|
||||
* One DataStore Preferences file inside [dataDir]. Each call site owns a
|
||||
* DISTINCT file (settings, window state, …) — the JVM factory is not a
|
||||
* name-keyed singleton like Android's `preferencesDataStore` delegate, so
|
||||
* uniqueness of the produced file is the caller's job (two DataStore
|
||||
* instances on one file would fight over the lock).
|
||||
*/
|
||||
fun preferencesStore(dataDir: File, name: String): DataStore<Preferences> =
|
||||
PreferenceDataStoreFactory.create(
|
||||
corruptionHandler = ReplaceFileCorruptionHandler { emptyPreferences() },
|
||||
produceFile = { File(dataDir, "$name.preferences_pb") },
|
||||
)
|
||||
|
||||
/**
|
||||
* Where the desktop library lives: `$XDG_DATA_HOME/incido`, falling back to
|
||||
* `~/.local/share/incido` (Development Plan §6 — a *separate* library per
|
||||
|
||||
Reference in new issue
Block a user