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
+130 -298

No files matched your search

@@ -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<String>) {
// 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<String>) {
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<Long?>(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<String>.argAfter(flag: String): String? {
val index = indexOf(flag)
return takeIf { index >= 0 && index + 1 < size }?.get(index + 1)