feat(phase-1/m4.3c): ViewModels off APPLICATION_KEY; DesktopContainer implements AppGraph
Completes the M4.3 container seam:
* NoteListViewModel + NoteEditorViewModel (UiStates and SharedImage
included) move to commonMain. NoteEditorViewModel had zero android.*
imports; its four withContext(Dispatchers.IO) sites become
withContext(ioDispatcher) — a new internal expect/actual whose ACTUALS
are literally Dispatchers.IO on both targets, so Android behaviour is
byte-identical (invariant §2.1), merely spelled through the seam.
* New commonMain EncryptionBadge/LibraryVerification: the read-only
mirror of :core:data's EncryptionVerification. Required because
:core:data is an androidLibrary invisible to commonMain and must stay
so (invariant §2.3 — objectbox-android vs objectbox-java classpaths).
AppGraph gains encryptionBadge; both containers map the real verifier
result 1:1 at their own seam.
* SettingsViewModel stays in androidMain (SecurityManager, Keystore key
provider, BackupManager Uri IO, CarnetImporter are genuine Android-only
services — the graph was NOT widened to fake them, §9) but its factory
now takes the concrete AppContainer via a new LocalAndroidContainer,
provided alongside LocalAppGraph in IncidoApp. No APPLICATION_KEY /
IncidoApplication reference survives in ANY ViewModel: all six call
sites (drawer, list, editor, settings, pin setup, pin change) build
factories from the graph/container locals at composition time.
* M4.3 exit proof: DesktopContainer : AppGraph — the same face
(noteRepository/settingsRepository/encryptionBadge) the commonMain
ViewModels consume, compiler-checked by :desktopApp building against
:composeApp's jvm target. repository → noteRepository rename.
The stand-in two-pane UI still runs (M4.5 consumes the real screens).
Verification (all green, one suite):
./gradlew assembleDebug :composeApp:compileKotlinJvm :desktopApp:build
→ BUILD SUCCESSFUL
./gradlew :desktopApp:run … --self-test --exit-after 6 → SELFTEST id=1, clean exit
./gradlew :core:data-jvm:smoke → RESULT: M1a PASS
crypto legs (separate processes): leg-A ALL-OK → LEG-B PASS/ALL-OK
git diff '*/objectbox-models/*' → empty
This commit is contained in:
1 parent
cd363c7aa5
commit
59bd6e106b
21 files changed
+176
-37
No files matched your search
@@ -40,7 +40,7 @@ suspend fun runCryptoSelfTest(app: DesktopContainer, passphrase: String): Boolea
|
||||
// 1. A probe note whose exact content we can look for again later.
|
||||
val marker = "M3-PROBE-${System.currentTimeMillis()} secret-at-rest"
|
||||
val now = System.currentTimeMillis()
|
||||
val probe = app.repository.saveNoteWithHashtags(
|
||||
val probe = app.noteRepository.saveNoteWithHashtags(
|
||||
Note(id = 0L, content = marker, createdAt = now, updatedAt = now),
|
||||
hashtagsToAdd = emptySet(),
|
||||
hashtagsToRemove = emptySet(),
|
||||
@@ -65,7 +65,7 @@ suspend fun runCryptoSelfTest(app: DesktopContainer, passphrase: String): Boolea
|
||||
)
|
||||
|
||||
// 4. Repository reads decrypt transparently.
|
||||
val readBack = app.repository.observeAll().first()
|
||||
val readBack = app.noteRepository.observeAll().first()
|
||||
check(
|
||||
"repository decrypts transparently",
|
||||
readBack.any { it.content == marker },
|
||||
|
||||
@@ -11,6 +11,10 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import org.incido.compose.data.settings.SettingsRepository
|
||||
import org.incido.compose.di.AppGraph
|
||||
import org.incido.compose.di.EncryptionBadge
|
||||
import org.incido.compose.di.LibraryVerification
|
||||
import kotlinx.coroutines.flow.map
|
||||
import org.incido.data.ImageOrientationNormalizer
|
||||
import org.incido.data.ObjectBoxStore
|
||||
import org.incido.data.crypto.AesGcmFieldCipher
|
||||
@@ -45,12 +49,12 @@ import org.incido.domain.repository.NoteRepository
|
||||
* EXIF rotation remains the one absent Android behaviour (M4 — needs a
|
||||
* JVM image decoder).
|
||||
*/
|
||||
class DesktopContainer(val dataDir: File) {
|
||||
class DesktopContainer(val dataDir: File) : AppGraph {
|
||||
|
||||
/** Process-wide scope for the verifier, mirroring AppContainer.appScope. */
|
||||
val appScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
|
||||
val settingsRepository: SettingsRepository =
|
||||
override val settingsRepository: SettingsRepository =
|
||||
SettingsRepository(preferencesStore(dataDir, "incido_settings"))
|
||||
|
||||
val keyProvider = DesktopKeyProvider(dataDir)
|
||||
@@ -74,7 +78,7 @@ class DesktopContainer(val dataDir: File) {
|
||||
}
|
||||
}
|
||||
|
||||
val repository: NoteRepository = NoteRepositoryImpl(
|
||||
override val noteRepository: NoteRepository = NoteRepositoryImpl(
|
||||
boxStore = boxStore,
|
||||
cipherHolder = cipherHolder,
|
||||
orientationNormalizer = ImageOrientationNormalizer.NoOp,
|
||||
@@ -86,6 +90,16 @@ class DesktopContainer(val dataDir: File) {
|
||||
/** Runs on every launch — feeds the "Encrypted" badge state. */
|
||||
val encryptionVerifier = EncryptionVerifier(noteCryptoService, appScope)
|
||||
|
||||
/**
|
||||
* M4.3c [AppGraph] face — same 3-field mapping AppContainer does;
|
||||
* the desktop sweep is the real M3 verifier over the desktop store.
|
||||
*/
|
||||
override val encryptionBadge: EncryptionBadge = object : EncryptionBadge {
|
||||
override val verification = encryptionVerifier.verification.map { result ->
|
||||
result?.let { LibraryVerification(it.verifiedNoteIds, it.failedNoteIds, it.checkedAt) }
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
encryptionVerifier.checkNow()
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ fun main(args: Array<String>) {
|
||||
) {
|
||||
NotesWindow(
|
||||
app = app,
|
||||
repository = app.repository,
|
||||
repository = app.noteRepository,
|
||||
windowStore = windowStore,
|
||||
windowState = windowState,
|
||||
exitAfterSeconds = exitAfterSeconds,
|
||||
|
||||
Reference in new issue
Block a user