diff --git a/desktopApp/src/main/kotlin/org/incido/desktop/BackupActions.kt b/desktopApp/src/main/kotlin/org/incido/desktop/BackupActions.kt index df6806a..657e8ac 100644 --- a/desktopApp/src/main/kotlin/org/incido/desktop/BackupActions.kt +++ b/desktopApp/src/main/kotlin/org/incido/desktop/BackupActions.kt @@ -63,8 +63,9 @@ const val DESKTOP_APP_VERSION = "0.4.2.0" * M4.5: the import/export machinery, extracted from the menu so the real * settings screen (BackupSection buttons) drives the EXACT flows M2 proved — * same pickFile, same BackupBridge calls, same passphrase/confirm dialogs. - * BackupActions is now just the menu skin over it; the state + dialogs - * belong to whoever remembers the flows (one host at a time renders them). + * The M2 menu skin was removed with M4.5b: the settings screen's + * BackupSection buttons drive these flows directly (one host, one set + * of dialogs). */ class BackupFlows internal constructor( val launchImport: () -> Unit, @@ -191,44 +192,6 @@ fun rememberBackupFlows( } } -@Composable -fun BackupActions( - repository: NoteRepository, - snackbar: SnackbarHostState, - modifier: Modifier = Modifier, -) { - val flows = rememberBackupFlows(repository, snackbar) - var menuOpen by remember { mutableStateOf(false) } - - IconButton(onClick = { menuOpen = true }, modifier = modifier) { - Icon(Icons.Default.MoreVert, contentDescription = "Backup menu") - } - DropdownMenu(expanded = menuOpen, onDismissRequest = { menuOpen = false }) { - DropdownMenuItem( - text = { Text("Import from file…") }, - onClick = { - menuOpen = false - flows.launchImport() - }, - ) - DropdownMenuItem( - text = { Text("Export (plain)") }, - onClick = { - menuOpen = false - flows.launchExportPlain() - }, - ) - DropdownMenuItem( - text = { Text("Export (encrypted)…") }, - onClick = { - menuOpen = false - flows.launchExportEncrypted() - }, - ) - } - flows.Dialogs() -} - /** Where the import flow stands (the file is already chosen). */ private sealed interface ImportStage { /** Preview without a passphrase failed → either encrypted or corrupt. */ diff --git a/desktopApp/src/main/kotlin/org/incido/desktop/DesktopShell.kt b/desktopApp/src/main/kotlin/org/incido/desktop/DesktopShell.kt new file mode 100644 index 0000000..ad69e7b --- /dev/null +++ b/desktopApp/src/main/kotlin/org/incido/desktop/DesktopShell.kt @@ -0,0 +1,98 @@ +package org.incido.desktop + +import androidx.compose.material3.DrawerValue +import androidx.compose.material3.ModalNavigationDrawer +import androidx.compose.material3.rememberDrawerState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import org.incido.compose.di.LocalAppGraph +import org.incido.compose.ui.drawer.IncidoDrawer +import org.incido.compose.ui.editor.NoteEditorScreen +import org.incido.compose.ui.notelist.NoteListScreen +import org.incido.domain.model.NoteFilter + +/** + * Phase 1 (M4.5b): the desktop shell hosting the app's REAL screens. + * + * This is the feasibility proof made literal: NoteListScreen, IncidoDrawer + * and NoteEditorScreen — the same composables the phone renders, from + * commonMain — running against the desktop ObjectBox store. App.kt's nav + * controller is replaced by three pieces of state (filter / editor / + * settings); everything below the chrome is shared, byte-identical code. + * + * Platform differences handled, not faked (§6.5): + * - beginExternalActivity is null on desktop (no auto-lock to suppress), + * - the editor's intake seam hides camera/voice on the JVM, + * - PlatformBackHandler is a no-op here — Esc routing is M5 polish, + * the editor closes via its own top-bar arrow like the phone's up button. + */ +@Composable +fun DesktopShell( + app: DesktopContainer, + showSettings: Boolean, + onShowSettings: (Boolean) -> Unit, + /** M4.5b scripted leg: opens the editor headlessly after first frame. */ + editorSmoke: Boolean = false, +) { + val scope = rememberCoroutineScope() + val drawerState = rememberDrawerState(DrawerValue.Closed) + var filterMode by remember { mutableStateOf(NoteFilter.Home) } + var editorOpen by remember { mutableStateOf(false) } + // null id = "new note" (exactly what onOpenEditor(null) means on Android). + var editorNoteId by remember { mutableStateOf(null) } + + if (editorSmoke) { + LaunchedEffect(Unit) { + delay(2500) + // Opens the REAL editor (ViewModel + intake seam included); + // a crash here fails the run — that IS the assertion. + editorOpen = true + println("EDITOR shown (real NoteEditorScreen + intake seam)") + } + } + + CompositionLocalProvider(LocalAppGraph provides app) { + when { + showSettings -> DesktopSettingsScreen(app = app, onBack = { onShowSettings(false) }) + editorOpen -> NoteEditorScreen( + noteId = editorNoteId, + onClose = { editorOpen = false }, + repository = app.noteRepository, + ) + else -> ModalNavigationDrawer( + drawerState = drawerState, + drawerContent = { + IncidoDrawer( + currentFilter = filterMode, + onSelectFilter = { picked -> + filterMode = picked + scope.launch { drawerState.close() } + }, + onOpenSettings = { + scope.launch { drawerState.close() } + onShowSettings(true) + }, + ) + }, + ) { + NoteListScreen( + filterMode = filterMode, + onOpenDrawer = { scope.launch { drawerState.open() } }, + onOpenEditor = { id -> + editorNoteId = id + editorOpen = true + }, + repository = app.noteRepository, + ) + } + } + } +} \ No newline at end of file diff --git a/desktopApp/src/main/kotlin/org/incido/desktop/Main.kt b/desktopApp/src/main/kotlin/org/incido/desktop/Main.kt index ef98e89..bd1f3bf 100644 --- a/desktopApp/src/main/kotlin/org/incido/desktop/Main.kt +++ b/desktopApp/src/main/kotlin/org/incido/desktop/Main.kt @@ -59,6 +59,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import org.incido.compose.data.backup.BackupBridge +import org.incido.compose.ui.theme.IncidoTheme import org.incido.compose.data.backup.EncryptedBackupCodec import org.incido.compose.data.backup.EncryptedKeyCodec import org.incido.data.crypto.AesGcmFieldCipher @@ -105,6 +106,7 @@ fun main(args: Array) { // M4.5: scripted settings leg — opens the real settings screen mid-run // so the shared sections (M4.4d) render on the JVM before auto-exit. val settingsSmoke = "--settings-smoke" in args + val editorSmoke = "--editor-smoke" in args val cryptoSelfTest = "--crypto-self-test" in args val cryptoReopen = "--crypto-reopen" in args val cryptoPassphrase = args.argAfter("--crypto-passphrase") ?: "selftest-passphrase" @@ -149,6 +151,7 @@ fun main(args: Array) { exitAfterSeconds = exitAfterSeconds, selfTest = selfTest, settingsSmoke = settingsSmoke, + editorSmoke = editorSmoke, backupImport = backupImport, backupExport = backupExport, backupExportEnc = backupExportEnc, @@ -176,6 +179,7 @@ private fun NotesWindow( exitAfterSeconds: Long?, selfTest: Boolean, settingsSmoke: Boolean, + editorSmoke: Boolean, backupImport: String?, backupExport: String?, backupExportEnc: String?, @@ -189,106 +193,34 @@ private fun NotesWindow( ) { val notes by remember(repository) { repository.observeAll() } .collectAsState(initial = emptyList()) - var selectedId by remember { mutableStateOf(null) } // M4.5: the real settings screen replaces the M1b placeholder list. var showSettings by remember { mutableStateOf(false) } - val scope = rememberCoroutineScope() - val snackbar = remember { SnackbarHostState() } // M3: theme_mode is a real shared setting here — resolveDark picks the - // scheme. (Material3's MaterialTheme has no darkTheme parameter — the - // scheme IS the switch, same shape as the app's IncidoTheme.) - // dynamic_color stays hidden (no Material You on the JVM), same rule - // as biometrics / screenshot blocking. + // scheme. M4.5b: the app's OWN IncidoTheme wraps the shell — the + // shared screens get the exact color scheme + typography the phone + // renders (platformDynamicColorScheme returns null on the JVM, so + // dynamic color degrades to the static palettes, §6.5-honest). val userSettings by app.settingsRepository.userSettingsFlow .collectAsState(initial = org.incido.compose.data.settings.UserSettings()) - - // Keep a valid selection as the library changes. - val selected = notes.firstOrNull { it.id == selectedId } ?: notes.firstOrNull() - val darkTheme = userSettings.themeMode.resolveDark(isSystemInDarkTheme()) - MaterialTheme( - colorScheme = if (darkTheme) darkColorScheme() else lightColorScheme(), - ) { - if (showSettings) { - DesktopSettingsScreen(app = app, onBack = { showSettings = false }) - } else { - Scaffold( - snackbarHost = { SnackbarHost(snackbar) }, - topBar = { - CenterAlignedTopAppBar( - title = { Text("Incido") }, - actions = { - // M3: theme + encryption live here (Palette menu). - SecurityActions(app = app, snackbar = snackbar) - // M2: the phone bridge lives here (Import…/Export). - BackupActions(repository = repository, snackbar = snackbar) - IconButton( - onClick = { - scope.launch { - val now = System.currentTimeMillis() - val saved = repository.saveNoteWithHashtags( - note = Note( - id = 0L, - content = "", - createdAt = now, - updatedAt = now, - ), - hashtagsToAdd = emptySet(), - hashtagsToRemove = emptySet(), - ) - selectedId = saved.id - } - }, - ) { Icon(Icons.Filled.Add, contentDescription = "New note") } - IconButton(onClick = { showSettings = true }) { - Icon(Icons.Filled.Settings, contentDescription = "Settings") - } - }, - ) - }, - ) { padding -> - Row(Modifier.fillMaxSize().padding(padding)) { - Surface( - modifier = Modifier.width(340.dp).fillMaxHeight(), - tonalElevation = 2.dp, - ) { - LazyColumn(modifier = Modifier.fillMaxSize()) { - items(notes, key = { it.id }) { note -> - NoteRow( - note = note, - selected = note.id == selected?.id, - onClick = { selectedId = note.id }, - onToggleFavorite = { - scope.launch { - repository.setFavorite(note.id, !note.isFavorite) - } - }, - ) - HorizontalDivider() - } - if (notes.isEmpty()) { - item { - Text( - "No notes yet — press + to write one.", - modifier = Modifier.padding(24.dp), - style = MaterialTheme.typography.bodyMedium, - ) - } - } - } - } - Editor(repository = repository, note = selected) - } - } - } + IncidoTheme(darkTheme = darkTheme, dynamicColor = false) { + // M4.5b: the shell hosts the REAL screens — NoteListScreen, + // IncidoDrawer, NoteEditorScreen and the M4.5a settings — over + // the AppGraph DesktopContainer already implements (M4.3 proof). + DesktopShell( + app = app, + showSettings = showSettings, + onShowSettings = { showSettings = it }, + editorSmoke = editorSmoke, + ) } LaunchedEffect(notes.size) { // Logged on every change: proves the ObjectBox subscription actually // delivers to the composition (the first frame is always the empty // initial value of collectAsState). - println("RENDER notes=${notes.size} selected=${selected?.id}") + println("RENDER notes=${notes.size}") } if (selfTest) { LaunchedEffect(Unit) { @@ -456,93 +388,6 @@ private fun NotesWindow( } } } -@Composable -private fun NoteRow( - note: Note, - selected: Boolean, - onClick: () -> Unit, - onToggleFavorite: () -> Unit, -) { - val (title, body) = Note.titleAndBody(note.content) - Row( - modifier = Modifier - .fillMaxWidth() - .clickable(onClick = onClick) - .padding(horizontal = 12.dp, vertical = 10.dp), - verticalAlignment = Alignment.CenterVertically, - ) { - Column(Modifier.weight(1f)) { - Text( - title, - style = MaterialTheme.typography.titleSmall, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - color = if (selected) { - MaterialTheme.colorScheme.primary - } else { - MaterialTheme.colorScheme.onSurface - }, - ) - if (body.isNotBlank()) { - Text( - body, - style = MaterialTheme.typography.bodySmall, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - ) - } - } - IconButton(onClick = onToggleFavorite) { - if (note.isFavorite) { - Icon(Icons.Filled.Star, contentDescription = "Unfavourite") - } else { - Icon(Icons.Outlined.StarBorder, contentDescription = "Favourite") - } - } - } -} - -/** Debounced write-through editor — the same "save as you type" feel as Android. */ -@Composable -private fun Editor(repository: NoteRepository, note: Note?) { - if (note == null) { - Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { - Text("Nothing to show yet", color = MaterialTheme.colorScheme.outline) - } - return - } - - var text by remember(note.id) { mutableStateOf(note.content) } - val scope = rememberCoroutineScope() - - // The saved note flows back through observeAll(); once the snapshot - // matches what is on screen there is nothing to write. - LaunchedEffect(text, note.content, note.id) { - if (text == note.content) return@LaunchedEffect - delay(400) - scope.launch { - repository.saveNoteWithHashtags( - note = note.copy(content = text), - hashtagsToAdd = emptySet(), - hashtagsToRemove = emptySet(), - ) - } - } - - Column( - modifier = Modifier.fillMaxSize().padding(16.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), - ) { - Text("Editing #${note.id}", style = MaterialTheme.typography.labelMedium) - OutlinedTextField( - value = text, - onValueChange = { text = it }, - modifier = Modifier.fillMaxSize(), - placeholder = { Text("Write something…") }, - ) - } -} - private fun Array.argAfter(flag: String): String? { val index = indexOf(flag) return takeIf { index >= 0 && index + 1 < size }?.get(index + 1) diff --git a/desktopApp/src/main/kotlin/org/incido/desktop/SecurityActions.kt b/desktopApp/src/main/kotlin/org/incido/desktop/SecurityActions.kt index 13faaee..e76035a 100644 --- a/desktopApp/src/main/kotlin/org/incido/desktop/SecurityActions.kt +++ b/desktopApp/src/main/kotlin/org/incido/desktop/SecurityActions.kt @@ -31,92 +31,18 @@ import org.incido.compose.data.settings.ThemeMode import org.incido.data.crypto.AesGcmFieldCipher /** - * Phase 1 (M3 task 3): the desktop security menu. + * Phase 1 (M3 task 3 → M4.5a): the desktop security services. * - * Deliberately SMALL — the real settings screen arrives with M4. It - * exposes exactly what desktop can honestly offer, per the M3 rules: - * theme mode (works), encryption + recovery key (work, through the same - * shared services Android drives), and NOTHING that can't exist here: - * dynamic color, biometrics and screenshot blocking are hidden, not - * faked (no Material You, no BiometricPrompt, no FLAG_SECURE on the JVM). - * PIN gating is deliberately absent too — the desktop lock story is - * deferred, so [org.incido.compose.data.settings.UserSettings.isLockActive] - * is never true on desktop and the notes open straight away. + * The M3 menu skin was removed with M4.5b — the settings screen drives + * these pieces now. What stays is exactly what desktop can honestly + * offer per the M3 rules: the encryption sweep (works), the recovery-key + * flows (work), and NOTHING that can't exist here: dynamic color, + * biometrics and screenshot blocking are hidden, not faked (no Material + * You, no BiometricPrompt, no FLAG_SECURE on the JVM). PIN gating is + * deliberately absent too — the desktop lock story is deferred, so + * [org.incido.compose.data.settings.UserSettings.isLockActive] is never + * true on desktop and the notes open straight away. */ -@Composable -fun SecurityActions( - app: DesktopContainer, - snackbar: SnackbarHostState, - modifier: Modifier = Modifier, -) { - val scope = rememberCoroutineScope() - var menuOpen by remember { mutableStateOf(false) } - val keys = rememberSecurityKeyFlows(app, snackbar) - - val settings by app.settingsRepository.userSettingsFlow - .collectAsState(initial = org.incido.compose.data.settings.UserSettings()) - val verification by app.encryptionVerifier.verification.collectAsState(null) - - fun say(message: String) { scope.launch { snackbar.showSnackbar(message) } } - - IconButton(onClick = { menuOpen = true }, modifier = modifier) { - Icon(Icons.Default.Palette, contentDescription = "Security & theme menu") - } - DropdownMenu(expanded = menuOpen, onDismissRequest = { menuOpen = false }) { - val active = settings.isEncryptionActive - val badge = verification?.let { - "encrypted ${it.verifiedNoteIds.size} · failed ${it.failedNoteIds.size}" - } ?: "checking…" - DropdownMenuItem( - text = { - Column(verticalArrangement = Arrangement.spacedBy(2.dp)) { - Text("Encryption: ${if (active) "on" else "off"}") - Text(badge, style = MaterialTheme.typography.bodySmall) - } - }, - onClick = {}, - enabled = false, - ) - Divider() - DropdownMenuItem( - text = { Text("Theme: ${settings.themeMode.name.lowercase()} (tap to cycle)") }, - onClick = { - scope.launch { - val next = when (settings.themeMode) { - ThemeMode.SYSTEM -> ThemeMode.DARK - ThemeMode.DARK -> ThemeMode.LIGHT - ThemeMode.LIGHT -> ThemeMode.SYSTEM - } - app.settingsRepository.setThemeMode(next) - } - }, - ) - Divider() - DropdownMenuItem( - text = { Text(if (active) "Decrypt all notes…" else "Encrypt all notes") }, - onClick = { - menuOpen = false - scope.launch { toggleDesktopEncryption(app, want = !active, ::say) } - }, - ) - DropdownMenuItem( - text = { Text("Export recovery key…") }, - onClick = { - menuOpen = false - keys.launchExport() - }, - ) - DropdownMenuItem( - text = { Text("Import recovery key…") }, - onClick = { - menuOpen = false - keys.launchImport() - }, - ) - } - keys.Dialogs() -} - /** * M4.5: the enable/disable sweep, extracted from the menu so the real * settings screen's toggle drives the identical sequence — Android