diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/App.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/App.kt index d10bf29..b468968 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/App.kt +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/App.kt @@ -31,6 +31,7 @@ import androidx.navigation.navArgument import kotlinx.coroutines.launch import org.incido.compose.data.security.SecurityManager import org.incido.compose.data.settings.SettingsRepository +import org.incido.compose.di.LocalAndroidContainer import org.incido.compose.di.LocalAppGraph import org.incido.compose.share.SharedIntentBuffer import org.incido.compose.ui.drawer.IncidoDrawer @@ -112,7 +113,10 @@ fun IncidoApp( // M4.3: the platform graph reaches the screens through the composition — // the same face DesktopContainer implements (commonMain di/AppGraph.kt). - CompositionLocalProvider(LocalAppGraph provides app.container) { + CompositionLocalProvider( + LocalAppGraph provides app.container, + LocalAndroidContainer provides app.container, + ) { IncidoTheme( darkTheme = settings.themeMode.resolveDark(isSystemInDarkTheme()), dynamicColor = settings.dynamicColor, diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/IncidoApplication.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/IncidoApplication.kt index 0059d34..da93444 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/IncidoApplication.kt +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/IncidoApplication.kt @@ -8,8 +8,10 @@ import org.incido.compose.di.AppContainer * Application class. Constructs the singleton [AppContainer] holding the * ObjectBox store and the note repository. * - * ViewModels reach the container via `(application as IncidoApplication).container` - * (see `NoteListViewModel.Factory` and `NoteEditorViewModel.factory`). + * M4.3: the screens reach the container through `LocalAppGraph` (provided + * by `IncidoApp`); the graph-based ViewModel factories (`factory(graph)`) + * no longer touch the Application through CreationExtras. The Application + * still owns construction order. * * v0.3.2.0 — initialises the [SecurityManager] lock state during * `onCreate` so the first composition of the root Compose tree diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/di/AndroidContainer.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/di/AndroidContainer.kt new file mode 100644 index 0000000..402a848 --- /dev/null +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/di/AndroidContainer.kt @@ -0,0 +1,21 @@ +package org.incido.compose.di + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.compositionLocalOf + +/** + * M4.3c — Android-only bridge beside [LocalAppGraph]. + * + * `SettingsViewModel` still needs the concrete [AppContainer] (Security + * Manager, Keystore key provider, BackupManager, CarnetImporter — the + * Android services M4.3 deliberately did NOT widen the graph with). The + * screen reads this local until M4.4/4.5 ports or hides that surface; + * `IncidoApp` provides the SAME container instance through both locals. + */ +val LocalAndroidContainer = compositionLocalOf { null } + +/** Read [LocalAndroidContainer] or throw with context — call at composition. */ +@Composable +fun requireAndroidContainer(): AppContainer = checkNotNull(LocalAndroidContainer.current) { + "No AppContainer provided — IncidoApp provides it at the root." +} \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/di/AppContainer.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/di/AppContainer.kt index 38873f4..d17a157 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/di/AppContainer.kt +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/di/AppContainer.kt @@ -20,6 +20,9 @@ import org.incido.compose.data.security.SecurityManager import org.incido.compose.data.settings.SettingsRepository import org.incido.compose.data.settings.settingsDataStore import org.incido.compose.di.AppGraph +import org.incido.compose.di.EncryptionBadge +import org.incido.compose.di.LibraryVerification +import kotlinx.coroutines.flow.map /** * Hand-rolled DI container. Replaces Hilt/Dagger for v0.1 — keeps the @@ -110,6 +113,18 @@ class AppContainer(context: Context) : AppGraph { /** Runs on every app open — feeds the verified-encryption badge. */ val encryptionVerifier = EncryptionVerifier(noteCryptoService, appScope) + /** + * M4.3c: [AppGraph]'s shared face over the concrete verifier — the + * 3-field copy is why `LibraryVerification` mirrors the data class + * (see EncryptionBadge.kt: :core:data is an androidLibrary, invisible + * to commonMain, and must stay that way per invariant §2.3). + */ + override val encryptionBadge: EncryptionBadge = object : EncryptionBadge { + override val verification = encryptionVerifier.verification.map { result -> + result?.let { LibraryVerification(it.verifiedNoteIds, it.failedNoteIds, it.checkedAt) } + } + } + /** Kick the startup verification off immediately. */ init { encryptionVerifier.checkNow() diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/di/PlatformIo.android.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/di/PlatformIo.android.kt new file mode 100644 index 0000000..91ba841 --- /dev/null +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/di/PlatformIo.android.kt @@ -0,0 +1,6 @@ +package org.incido.compose.di + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +internal actual val ioDispatcher: CoroutineDispatcher = Dispatchers.IO \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/editor/NoteEditorScreen.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/editor/NoteEditorScreen.kt index b722bee..a9acfd0 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/editor/NoteEditorScreen.kt +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/editor/NoteEditorScreen.kt @@ -117,6 +117,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.incido.compose.data.security.SecurityManager +import org.incido.compose.di.requireAppGraph import org.incido.compose.ui.theme.AllNoteColors import org.incido.compose.ui.theme.swatchBorderColor import org.incido.compose.ui.theme.toComposeColor @@ -150,6 +151,7 @@ fun NoteEditorScreen( securityManager: SecurityManager? = null, viewModel: NoteEditorViewModel = viewModel( factory = NoteEditorViewModel.factory( + graph = requireAppGraph(), noteId = noteId, initialSharedText = initialSharedText, initialSharedImages = initialSharedImages, diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/notelist/NoteListScreen.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/notelist/NoteListScreen.kt index 4f8c70c..f29daf8 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/notelist/NoteListScreen.kt +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/notelist/NoteListScreen.kt @@ -75,6 +75,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel +import org.incido.compose.di.requireAppGraph import org.incido.compose.ui.theme.toComposeColor import org.incido.compose.util.rememberRelativeTimestamp import org.incido.domain.model.Note @@ -127,7 +128,7 @@ fun NoteListScreen( onOpenEditor: (Long?) -> Unit, /** v0.3.1.0 — used to fetch image bytes for card thumbnails. */ repository: NoteRepository? = null, - viewModel: NoteListViewModel = viewModel(factory = NoteListViewModel.Factory), + viewModel: NoteListViewModel = viewModel(factory = NoteListViewModel.factory(requireAppGraph())), ) { val state by viewModel.uiState.collectAsStateWithLifecycle() var localQuery by remember { mutableStateOf("") } diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt index 2833c1f..72bfb90 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt @@ -52,6 +52,7 @@ import kotlinx.coroutines.launch import org.incido.compose.data.backup.BackupPreview import org.incido.compose.data.backup.EncryptedBackupCodec import org.incido.compose.data.security.SecurityManager +import org.incido.compose.di.requireAndroidContainer import org.incido.compose.data.settings.AutoLockTimeout import org.incido.compose.data.settings.ThemeMode @@ -93,7 +94,7 @@ fun SettingsScreen( * suppression (the pre-0.3.4.0 behaviour). */ securityManager: SecurityManager? = null, - viewModel: SettingsViewModel = viewModel(factory = SettingsViewModel.Factory), + viewModel: SettingsViewModel = viewModel(factory = SettingsViewModel.factory(requireAndroidContainer())), ) { val settings by viewModel.userSettings.collectAsStateWithLifecycle() val migrationState by viewModel.migrationState.collectAsStateWithLifecycle() diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsViewModel.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsViewModel.kt index aa366c2..7af4cc0 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsViewModel.kt +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsViewModel.kt @@ -2,7 +2,6 @@ package org.incido.compose.ui.settings import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory @@ -12,7 +11,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch -import org.incido.compose.IncidoApplication +import org.incido.compose.di.AppContainer import org.incido.compose.data.backup.BackupManager import org.incido.compose.data.backup.CarnetImporter import org.incido.compose.data.security.ObjectBoxKeyProvider @@ -362,10 +361,17 @@ class SettingsViewModel( * — if you bump one, bump both. */ const val APP_VERSION = "0.4.2.0" - val Factory: ViewModelProvider.Factory = viewModelFactory { + /** + * M4.3c: graph-based factory — but this ViewModel genuinely needs + * the ANDROID services (SecurityManager, Keystore key provider, + * BackupManager's Uri IO, CarnetImporter), so it takes the + * concrete AppContainer, not just the AppGraph face. It stays in + * androidMain until those services gain desktop answers (or the + * UI hides them — plan §6.5). + */ + fun factory(container: AppContainer): ViewModelProvider.Factory = viewModelFactory { initializer { - val app = this[APPLICATION_KEY] as IncidoApplication - val c = app.container + val c = container SettingsViewModel( settings = c.settingsRepository, security = c.securityManager, diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/auth/PinChangeScreen.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/auth/PinChangeScreen.kt index 7a4ab72..3d95aa1 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/auth/PinChangeScreen.kt +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/auth/PinChangeScreen.kt @@ -40,6 +40,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import kotlinx.coroutines.launch +import org.incido.compose.di.requireAndroidContainer import org.incido.compose.ui.settings.SettingsViewModel /** @@ -57,7 +58,7 @@ import org.incido.compose.ui.settings.SettingsViewModel * stored hash + salt. The screen pops on success and surfaces a * "PIN updated." snackbar via the existing viewModel.snackbar flow. * - * Reuses the existing [SettingsViewModel.Factory] — the new screen + * Reuses the existing [SettingsViewModel.factory] — the new screen * doesn't need its own ViewModel because every operation goes through * the existing security manager. */ @@ -66,7 +67,7 @@ import org.incido.compose.ui.settings.SettingsViewModel fun PinChangeScreen( onDone: () -> Unit, onCancel: () -> Unit, - viewModel: SettingsViewModel = viewModel(factory = SettingsViewModel.Factory), + viewModel: SettingsViewModel = viewModel(factory = SettingsViewModel.factory(requireAndroidContainer())), ) { val scope = rememberCoroutineScope() var step by remember { mutableStateOf(Step.VerifyOld) } diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/auth/PinSetupScreen.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/auth/PinSetupScreen.kt index 76944cf..6eb121c 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/auth/PinSetupScreen.kt +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/auth/PinSetupScreen.kt @@ -36,6 +36,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import kotlinx.coroutines.launch +import org.incido.compose.di.requireAndroidContainer import org.incido.compose.ui.settings.SettingsViewModel /** @@ -60,7 +61,7 @@ import org.incido.compose.ui.settings.SettingsViewModel fun PinSetupScreen( onDone: () -> Unit, onCancel: () -> Unit, - viewModel: SettingsViewModel = viewModel(factory = SettingsViewModel.Factory), + viewModel: SettingsViewModel = viewModel(factory = SettingsViewModel.factory(requireAndroidContainer())), ) { val scope = rememberCoroutineScope() diff --git a/composeApp/src/commonMain/kotlin/org/incido/compose/di/AppGraph.kt b/composeApp/src/commonMain/kotlin/org/incido/compose/di/AppGraph.kt index 29d8c50..fb40e26 100644 --- a/composeApp/src/commonMain/kotlin/org/incido/compose/di/AppGraph.kt +++ b/composeApp/src/commonMain/kotlin/org/incido/compose/di/AppGraph.kt @@ -27,6 +27,13 @@ import org.incido.domain.repository.NoteRepository interface AppGraph { val noteRepository: NoteRepository val settingsRepository: SettingsRepository + /** + * M4.3c: the encryption-badge feed (verified/unverified note ids from + * the trial-decrypt sweep). Both platforms genuinely run + * `EncryptionVerifier` on their own store, so this is a shared face, + * not an Android concept — see EncryptionBadge.kt for the mapping. + */ + val encryptionBadge: EncryptionBadge } /** diff --git a/composeApp/src/commonMain/kotlin/org/incido/compose/di/EncryptionBadge.kt b/composeApp/src/commonMain/kotlin/org/incido/compose/di/EncryptionBadge.kt new file mode 100644 index 0000000..354be5c --- /dev/null +++ b/composeApp/src/commonMain/kotlin/org/incido/compose/di/EncryptionBadge.kt @@ -0,0 +1,34 @@ +package org.incido.compose.di + +import kotlinx.coroutines.flow.Flow + +/** + * Phase 1 (M4.3c) — the commonMain mirror of `EncryptionVerification` + * (`org.incido.data.crypto`, :core:data shared sources). + * + * Why a mirror instead of the real type: :core:data is an androidLibrary — + * its classes are invisible to a KMP commonMain, and it can never become + * multiplatform without colliding with invariant §2.3 + * (objectbox-android and objectbox-java may never share a classpath). + * A ViewModel only ever READS the verification result, so the graph + * exposes this read-only view; both containers map the real class into it + * with a 3-field copy at the seam. + */ +data class LibraryVerification( + val verifiedNoteIds: Set, + val failedNoteIds: Set, + /** [System.currentTimeMillis] when the check ran (set by the platform). */ + val checkedAt: Long, +) { + val allOk: Boolean get() = failedNoteIds.isEmpty() +} + +/** + * The encryption-badge feed the note list binds to: `null` until the + * first verification sweep completes; empty sets when the library is + * unencrypted. `EncryptionVerifier`'s common face (see [LibraryVerification] + * for why the concrete class can't cross the seam). + */ +interface EncryptionBadge { + val verification: Flow +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/org/incido/compose/di/PlatformIo.kt b/composeApp/src/commonMain/kotlin/org/incido/compose/di/PlatformIo.kt new file mode 100644 index 0000000..3130cf7 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/org/incido/compose/di/PlatformIo.kt @@ -0,0 +1,12 @@ +package org.incido.compose.di + +import kotlinx.coroutines.CoroutineDispatcher + +/** + * Phase 1 (M4.3c): `Dispatchers.IO` has no commonMain declaration + * (coroutines 1.9 keeps it JVM-only). NoteEditorViewModel swaps its four + * `withContext(Dispatchers.IO)` sites for this seam — both actuals are + * literally `Dispatchers.IO`, so the Android behaviour is unchanged + * (invariant §2.1), it is merely spelled through an expect/actual. + */ +internal expect val ioDispatcher: CoroutineDispatcher \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/editor/NoteEditorViewModel.kt b/composeApp/src/commonMain/kotlin/org/incido/compose/ui/editor/NoteEditorViewModel.kt similarity index 98% rename from composeApp/src/androidMain/kotlin/org/incido/compose/ui/editor/NoteEditorViewModel.kt rename to composeApp/src/commonMain/kotlin/org/incido/compose/ui/editor/NoteEditorViewModel.kt index ea55829..174c495 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/editor/NoteEditorViewModel.kt +++ b/composeApp/src/commonMain/kotlin/org/incido/compose/ui/editor/NoteEditorViewModel.kt @@ -2,11 +2,9 @@ package org.incido.compose.ui.editor import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.MutableStateFlow @@ -21,7 +19,8 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.incido.compose.IncidoApplication +import org.incido.compose.di.AppGraph +import org.incido.compose.di.ioDispatcher import org.incido.compose.share.LinkedShareComposer import org.incido.domain.model.ChecklistItem import org.incido.domain.model.Hashtag @@ -614,7 +613,7 @@ class NoteEditorViewModel( val existingId = _state.value.existing?.id if (existingId != null && existingId > 0L) { // Persist straight to the DB; observeAttachments will surface it. - withContext(Dispatchers.IO) { + withContext(ioDispatcher) { repository.addAttachment( noteId = existingId, bytes = bytes, @@ -656,7 +655,7 @@ class NoteEditorViewModel( /** Delete a persisted attachment by id (used by the ✕ on the thumbnail strip). */ fun deletePersistedAttachment(id: Long) { viewModelScope.launch { - withContext(Dispatchers.IO) { repository.removeAttachment(id) } + withContext(ioDispatcher) { repository.removeAttachment(id) } } } @@ -685,7 +684,7 @@ class NoteEditorViewModel( val stalePersisted = _state.value.attachments .filter { it.mimeType.startsWith("audio/") } if (stalePersisted.isNotEmpty()) { - withContext(Dispatchers.IO) { + withContext(ioDispatcher) { stalePersisted.forEach { repository.removeAttachment(it.id) } } } @@ -799,7 +798,7 @@ class NoteEditorViewModel( current.pendingAttachments.forEach { pending -> val bytes = current.pendingAttachmentBytes[pending.tempId] if (bytes != null) { - withContext(Dispatchers.IO) { + withContext(ioDispatcher) { repository.addAttachment( noteId = saved.id, bytes = bytes, @@ -847,6 +846,7 @@ class NoteEditorViewModel( const val DRAFT_AUTOSAVE_DEBOUNCE_MS = 400L fun factory( + graph: AppGraph, noteId: Long?, initialSharedText: String? = null, initialSharedImages: List = emptyList(), @@ -858,9 +858,8 @@ class NoteEditorViewModel( initialSharedSubject: String? = null, ): ViewModelProvider.Factory = viewModelFactory { initializer { - val app = this[APPLICATION_KEY] as IncidoApplication NoteEditorViewModel( - repository = app.container.noteRepository, + repository = graph.noteRepository, noteId = noteId, initialSharedText = initialSharedText, initialSharedImages = initialSharedImages, diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/notelist/NoteListViewModel.kt b/composeApp/src/commonMain/kotlin/org/incido/compose/ui/notelist/NoteListViewModel.kt similarity index 92% rename from composeApp/src/androidMain/kotlin/org/incido/compose/ui/notelist/NoteListViewModel.kt rename to composeApp/src/commonMain/kotlin/org/incido/compose/ui/notelist/NoteListViewModel.kt index 181e6db..fb10a0e 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/notelist/NoteListViewModel.kt +++ b/composeApp/src/commonMain/kotlin/org/incido/compose/ui/notelist/NoteListViewModel.kt @@ -2,7 +2,6 @@ package org.incido.compose.ui.notelist import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory @@ -16,7 +15,8 @@ import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch -import org.incido.compose.IncidoApplication +import org.incido.compose.di.AppGraph +import org.incido.compose.di.EncryptionBadge import org.incido.domain.model.HashtagUsage import org.incido.domain.model.Note import org.incido.domain.model.NoteFilter @@ -52,8 +52,11 @@ data class NoteListUiState( @OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) class NoteListViewModel( private val repository: NoteRepository, - /** v0.3.5.0 — source of the verified-encryption badge set. */ - private val encryptionVerifier: org.incido.data.crypto.EncryptionVerifier? = null, + /** v0.3.5.0 — source of the verified-encryption badge set. + * M4.3c: the concrete `EncryptionVerifier` (androidLibrary sources) + * becomes the commonMain [EncryptionBadge] face — same StateFlow + * contents, mapped 1:1 by each container. */ + private val encryptionBadge: EncryptionBadge? = null, ) : ViewModel() { private val filterMode = MutableStateFlow(NoteFilter.Home) @@ -112,7 +115,7 @@ class NoteListViewModel( */ val uiState: StateFlow = combine( baseUiState, - encryptionVerifier?.verification + encryptionBadge?.verification ?: kotlinx.coroutines.flow.flowOf(null), ) { state, verification -> state.copy( @@ -175,12 +178,11 @@ class NoteListViewModel( } companion object { - val Factory: ViewModelProvider.Factory = viewModelFactory { + fun factory(graph: AppGraph): ViewModelProvider.Factory = viewModelFactory { initializer { - val app = this[APPLICATION_KEY] as IncidoApplication NoteListViewModel( - repository = app.container.noteRepository, - encryptionVerifier = app.container.encryptionVerifier, + repository = graph.noteRepository, + encryptionBadge = graph.encryptionBadge, ) } } diff --git a/composeApp/src/jvmMain/kotlin/org/incido/compose/di/PlatformIo.jvm.kt b/composeApp/src/jvmMain/kotlin/org/incido/compose/di/PlatformIo.jvm.kt new file mode 100644 index 0000000..91ba841 --- /dev/null +++ b/composeApp/src/jvmMain/kotlin/org/incido/compose/di/PlatformIo.jvm.kt @@ -0,0 +1,6 @@ +package org.incido.compose.di + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +internal actual val ioDispatcher: CoroutineDispatcher = Dispatchers.IO \ No newline at end of file diff --git a/desktopApp/build.gradle.kts b/desktopApp/build.gradle.kts index d9f17dd..59806b5 100644 --- a/desktopApp/build.gradle.kts +++ b/desktopApp/build.gradle.kts @@ -39,6 +39,11 @@ dependencies { // `.preferences_pb` store from a file path (no Context extension). implementation(project(":core:settings")) implementation(libs.androidx.datastore.preferences.core) + // Phase 1 (M4.3c): composeApp's jvm target — the AppGraph face and + // the commonMain ViewModels. DesktopContainer implementing AppGraph + // is the M4.3 exit proof, checked by the compiler. The stand-in UI + // keeps running until M4.5 consumes the real screens. + implementation(project(":composeApp")) } // Packaging works (proven in Phase 0), but per-OS installers and icons are diff --git a/desktopApp/src/main/kotlin/org/incido/desktop/CryptoSelfTest.kt b/desktopApp/src/main/kotlin/org/incido/desktop/CryptoSelfTest.kt index f0868d8..e8915b5 100644 --- a/desktopApp/src/main/kotlin/org/incido/desktop/CryptoSelfTest.kt +++ b/desktopApp/src/main/kotlin/org/incido/desktop/CryptoSelfTest.kt @@ -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 }, diff --git a/desktopApp/src/main/kotlin/org/incido/desktop/DesktopContainer.kt b/desktopApp/src/main/kotlin/org/incido/desktop/DesktopContainer.kt index 15fe33e..77fef5d 100644 --- a/desktopApp/src/main/kotlin/org/incido/desktop/DesktopContainer.kt +++ b/desktopApp/src/main/kotlin/org/incido/desktop/DesktopContainer.kt @@ -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() } diff --git a/desktopApp/src/main/kotlin/org/incido/desktop/Main.kt b/desktopApp/src/main/kotlin/org/incido/desktop/Main.kt index f9e704b..455d2ab 100644 --- a/desktopApp/src/main/kotlin/org/incido/desktop/Main.kt +++ b/desktopApp/src/main/kotlin/org/incido/desktop/Main.kt @@ -139,7 +139,7 @@ fun main(args: Array) { ) { NotesWindow( app = app, - repository = app.repository, + repository = app.noteRepository, windowStore = windowStore, windowState = windowState, exitAfterSeconds = exitAfterSeconds,