feat(phase-1/m4.5b): desktop shell hosts the REAL shared screens

DesktopShell replaces the M1b placeholder two-pane window with the
app's own composables from commonMain: NoteListScreen (search, FAB,
cards), IncidoDrawer (filters + recent hashtags, in a
ModalNavigationDrawer) and NoteEditorScreen (ViewModel, attachments,
intake seam) — all over LocalAppGraph provides DesktopContainer (the
M4.3 AppGraph face). App.kt's navigation reduces to three pieces of
state (filter / editor / settings). IncidoTheme (shared theme, static
palettes on JVM via the null platformDynamicColorScheme actual) now
themes the window.

The M2/M3 menu skins (BackupActions/SecurityActions composables) are
removed — dead UI once the settings screen drives their exact flows
(BackupFlows / SecurityKeyFlows / toggleDesktopEncryption all live on).
RENDER logging simplified (the shell owns selection now).

Scripted legs: --settings-smoke and --editor-smoke compose the real
screens headlessly — the editor leg proves its ViewModel + intake seam
work on the JVM (JetBrains lifecycle's fallback store owner; the last
open M4 unknown). Both run to clean auto-exit; earlier 124s exits were
cold-build harness time, warm reruns exit 0.

Verified: assembleDebug :desktopApp:build SUCCESSFUL + :desktopApp:run
--self-test --settings-smoke (SELFTEST id=1, SETTINGS shown, ST_EXIT=0)
+ run --self-test --editor-smoke (EDITOR shown, EST_EXIT=0)
+ :core:data-jvm:smoke (M1a PASS); models clean.
This commit is contained in:
Incido Developer committed 2026-10-06 19:48:37 +13:00
1 parent d264238640
commit cce35587fc
4 files changed
+129 -297

No files matched your search

@@ -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 * M4.5: the import/export machinery, extracted from the menu so the real
* settings screen (BackupSection buttons) drives the EXACT flows M2 proved — * settings screen (BackupSection buttons) drives the EXACT flows M2 proved —
* same pickFile, same BackupBridge calls, same passphrase/confirm dialogs. * same pickFile, same BackupBridge calls, same passphrase/confirm dialogs.
* BackupActions is now just the menu skin over it; the state + dialogs * The M2 menu skin was removed with M4.5b: the settings screen's
* belong to whoever remembers the flows (one host at a time renders them). * BackupSection buttons drive these flows directly (one host, one set
* of dialogs).
*/ */
class BackupFlows internal constructor( class BackupFlows internal constructor(
val launchImport: () -> Unit, 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). */ /** Where the import flow stands (the file is already chosen). */
private sealed interface ImportStage { private sealed interface ImportStage {
/** Preview without a passphrase failed → either encrypted or corrupt. */ /** Preview without a passphrase failed → either encrypted or corrupt. */
@@ -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>(NoteFilter.Home) }
var editorOpen by remember { mutableStateOf(false) }
// null id = "new note" (exactly what onOpenEditor(null) means on Android).
var editorNoteId by remember { mutableStateOf<Long?>(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,
)
}
}
}
}
@@ -59,6 +59,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.incido.compose.data.backup.BackupBridge 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.EncryptedBackupCodec
import org.incido.compose.data.backup.EncryptedKeyCodec import org.incido.compose.data.backup.EncryptedKeyCodec
import org.incido.data.crypto.AesGcmFieldCipher import org.incido.data.crypto.AesGcmFieldCipher
@@ -105,6 +106,7 @@ fun main(args: Array<String>) {
// M4.5: scripted settings leg — opens the real settings screen mid-run // 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. // so the shared sections (M4.4d) render on the JVM before auto-exit.
val settingsSmoke = "--settings-smoke" in args val settingsSmoke = "--settings-smoke" in args
val editorSmoke = "--editor-smoke" in args
val cryptoSelfTest = "--crypto-self-test" in args val cryptoSelfTest = "--crypto-self-test" in args
val cryptoReopen = "--crypto-reopen" in args val cryptoReopen = "--crypto-reopen" in args
val cryptoPassphrase = args.argAfter("--crypto-passphrase") ?: "selftest-passphrase" val cryptoPassphrase = args.argAfter("--crypto-passphrase") ?: "selftest-passphrase"
@@ -149,6 +151,7 @@ fun main(args: Array<String>) {
exitAfterSeconds = exitAfterSeconds, exitAfterSeconds = exitAfterSeconds,
selfTest = selfTest, selfTest = selfTest,
settingsSmoke = settingsSmoke, settingsSmoke = settingsSmoke,
editorSmoke = editorSmoke,
backupImport = backupImport, backupImport = backupImport,
backupExport = backupExport, backupExport = backupExport,
backupExportEnc = backupExportEnc, backupExportEnc = backupExportEnc,
@@ -176,6 +179,7 @@ private fun NotesWindow(
exitAfterSeconds: Long?, exitAfterSeconds: Long?,
selfTest: Boolean, selfTest: Boolean,
settingsSmoke: Boolean, settingsSmoke: Boolean,
editorSmoke: Boolean,
backupImport: String?, backupImport: String?,
backupExport: String?, backupExport: String?,
backupExportEnc: String?, backupExportEnc: String?,
@@ -189,106 +193,34 @@ private fun NotesWindow(
) { ) {
val notes by remember(repository) { repository.observeAll() } val notes by remember(repository) { repository.observeAll() }
.collectAsState(initial = emptyList()) .collectAsState(initial = emptyList())
var selectedId by remember { mutableStateOf<Long?>(null) }
// M4.5: the real settings screen replaces the M1b placeholder list. // M4.5: the real settings screen replaces the M1b placeholder list.
var showSettings by remember { mutableStateOf(false) } 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 // M3: theme_mode is a real shared setting here — resolveDark picks the
// scheme. (Material3's MaterialTheme has no darkTheme parameter — the // scheme. M4.5b: the app's OWN IncidoTheme wraps the shell — the
// scheme IS the switch, same shape as the app's IncidoTheme.) // shared screens get the exact color scheme + typography the phone
// dynamic_color stays hidden (no Material You on the JVM), same rule // renders (platformDynamicColorScheme returns null on the JVM, so
// as biometrics / screenshot blocking. // dynamic color degrades to the static palettes, §6.5-honest).
val userSettings by app.settingsRepository.userSettingsFlow val userSettings by app.settingsRepository.userSettingsFlow
.collectAsState(initial = org.incido.compose.data.settings.UserSettings()) .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()) val darkTheme = userSettings.themeMode.resolveDark(isSystemInDarkTheme())
MaterialTheme( IncidoTheme(darkTheme = darkTheme, dynamicColor = false) {
colorScheme = if (darkTheme) darkColorScheme() else lightColorScheme(), // M4.5b: the shell hosts the REAL screens — NoteListScreen,
) { // IncidoDrawer, NoteEditorScreen and the M4.5a settings — over
if (showSettings) { // the AppGraph DesktopContainer already implements (M4.3 proof).
DesktopSettingsScreen(app = app, onBack = { showSettings = false }) DesktopShell(
} else { app = app,
Scaffold( showSettings = showSettings,
snackbarHost = { SnackbarHost(snackbar) }, onShowSettings = { showSettings = it },
topBar = { editorSmoke = editorSmoke,
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)
}
}
}
} }
LaunchedEffect(notes.size) { LaunchedEffect(notes.size) {
// Logged on every change: proves the ObjectBox subscription actually // Logged on every change: proves the ObjectBox subscription actually
// delivers to the composition (the first frame is always the empty // delivers to the composition (the first frame is always the empty
// initial value of collectAsState). // initial value of collectAsState).
println("RENDER notes=${notes.size} selected=${selected?.id}") println("RENDER notes=${notes.size}")
} }
if (selfTest) { if (selfTest) {
LaunchedEffect(Unit) { 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<String>.argAfter(flag: String): String? { private fun Array<String>.argAfter(flag: String): String? {
val index = indexOf(flag) val index = indexOf(flag)
return takeIf { index >= 0 && index + 1 < size }?.get(index + 1) return takeIf { index >= 0 && index + 1 < size }?.get(index + 1)
@@ -31,92 +31,18 @@ import org.incido.compose.data.settings.ThemeMode
import org.incido.data.crypto.AesGcmFieldCipher 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 * The M3 menu skin was removed with M4.5b — the settings screen drives
* exposes exactly what desktop can honestly offer, per the M3 rules: * these pieces now. What stays is exactly what desktop can honestly
* theme mode (works), encryption + recovery key (work, through the same * offer per the M3 rules: the encryption sweep (works), the recovery-key
* shared services Android drives), and NOTHING that can't exist here: * flows (work), and NOTHING that can't exist here: dynamic color,
* dynamic color, biometrics and screenshot blocking are hidden, not * biometrics and screenshot blocking are hidden, not faked (no Material
* faked (no Material You, no BiometricPrompt, no FLAG_SECURE on the JVM). * You, no BiometricPrompt, no FLAG_SECURE on the JVM). PIN gating is
* PIN gating is deliberately absent too — the desktop lock story is * deliberately absent too — the desktop lock story is deferred, so
* deferred, so [org.incido.compose.data.settings.UserSettings.isLockActive] * [org.incido.compose.data.settings.UserSettings.isLockActive] is never
* is never true on desktop and the notes open straight away. * 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 * M4.5: the enable/disable sweep, extracted from the menu so the real
* settings screen's toggle drives the identical sequence — Android * settings screen's toggle drives the identical sequence — Android