feat(phase-1/m4.5a): desktop settings screen on the shared sections

DesktopSettingsScreen composes the M4.4d common sections (Appearance
/ Backup / About + building blocks) plus desktop-only Encryption rows.
Android-incapable surfaces are hidden per 6.5: dynamic-color row
(onDynamicColor null), Carnet importer (onImportCarnet null),
SecuritySection entirely (no BiometricPrompt/FLAG_SECURE on the JVM).

Flow dedupe so settings drives the EXACT M2/M3 behaviour, not a copy:
- BackupActions split: BackupFlows/rememberBackupFlows owns the pick+
  bridge + dialog machinery; the menu is now a thin skin (launchImport/
  launchExportPlain/launchExportEncrypted + Dialogs()).
- SecurityActions split: SecurityKeyFlows owns the recovery-key export/
  import dialogs (hasKey gate, overwrite warning, import leg);
  toggleDesktopEncryption() keeps the enable/disable ordering.
- M4.4d sections became PUBLIC (desktopApp is a separate module).

Main.kt: gear button routes list-window <-> settings in-place (no nav
stack yet — desktop nav polish is M5). New scripted leg
--settings-smoke renders the screen headlessly before auto-exit.

Verified: assembleDebug :desktopApp:build SUCCESSFUL + :desktopApp:
run --self-test --settings-smoke (SELFTEST id=1, RENDER notes=1
selected=1, SETTINGS shown, ST_EXIT=0) + :core:data-jvm:smoke
(M1a PASS); models clean.
This commit is contained in:
Incido Developer committed 2026-10-06 19:27:02 +13:00
1 parent 0dc5935d1d
commit d264238640
5 files changed
+461 -216

No files matched your search

@@ -59,14 +59,26 @@ const val DESKTOP_APP_VERSION = "0.4.2.0"
* PassphraseDialog.kt is deliberately NOT ported (M4 will move the real
* one into common code).
*/
/**
* 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).
*/
class BackupFlows internal constructor(
val launchImport: () -> Unit,
val launchExportPlain: () -> Unit,
val launchExportEncrypted: () -> Unit,
val Dialogs: @Composable () -> Unit,
)
@Composable
fun BackupActions(
fun rememberBackupFlows(
repository: NoteRepository,
snackbar: SnackbarHostState,
modifier: Modifier = Modifier,
) {
): BackupFlows {
val scope = rememberCoroutineScope()
var menuOpen by remember { mutableStateOf(false) }
var importStage by remember { mutableStateOf<ImportStage?>(null) }
var exportStage by remember { mutableStateOf<ExportStage?>(null) }
// M2 task 3: dedupe is ON by default; the confirm dialog exposes it.
@@ -74,24 +86,15 @@ fun BackupActions(
fun say(message: String) { scope.launch { snackbar.showSnackbar(message) } }
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
return remember(repository) {
BackupFlows(
launchImport = {
scope.launch {
val file = pickFile(load = true, title = "Import backup") ?: return@launch
startImport(file, ::say) { stage -> importStage = stage }
}
},
)
DropdownMenuItem(
text = { Text("Export (plain)") },
onClick = {
menuOpen = false
launchExportPlain = {
scope.launch {
val file = pickFile(load = false, title = "Export backup", suggested = suggestedExportName()) ?: return@launch
runCatching {
@@ -102,96 +105,128 @@ fun BackupActions(
.onFailure { say("Export failed: ${it.message}") }
}
},
launchExportEncrypted = {
exportStage = ExportStage.AwaitingPassphrase
},
Dialogs = {
// ---- import dialogs (verbatim M2 behaviour) --------------
when (val stage = importStage) {
is ImportStage.NeedPassphrase -> PassphraseDialog(
blurb = "This backup is encrypted (INCDBK1). Enter its passphrase to preview it.",
onDismiss = { importStage = null },
onConfirm = { pass ->
scope.launch {
val preview = withContext(Dispatchers.IO) {
runCatching {
BackupBridge.preview(FileInputStream(stage.file), pass.toCharArray())
}.getOrNull()
}
if (preview == null) {
say("Wrong passphrase") // dialog stays open for a retry
} else {
importStage = ImportStage.Confirm(stage.file, preview, pass)
}
}
},
)
is ImportStage.Confirm -> ConfirmImportDialog(
preview = stage.preview,
skipExisting = skipDuplicates,
onSkipChange = { skipDuplicates = it },
onDismiss = { importStage = null },
onConfirm = {
importStage = null
scope.launch {
runCatching {
withContext(Dispatchers.IO) {
BackupBridge.import(
repository,
FileInputStream(stage.file),
stage.passphrase?.toCharArray(),
skipExisting = skipDuplicates,
)
}
}.onSuccess {
say(
"Imported ${it.imported} notes" +
if (it.skipped > 0) " · skipped ${it.skipped} already imported" else "",
)
}
.onFailure { say("Import failed: ${it.message}") }
}
},
)
null -> Unit
}
// ---- export dialogs (verbatim M2 behaviour) --------------
when (exportStage) {
ExportStage.AwaitingPassphrase -> PassphraseDialog(
blurb = "Choose the passphrase for the encrypted backup (same INCDBK1 envelope as the phone).",
onDismiss = { exportStage = null },
onConfirm = { pass ->
exportStage = null
scope.launch {
val file = pickFile(load = false, title = "Export backup", suggested = suggestedExportName()) ?: return@launch
runCatching {
withContext(Dispatchers.IO) {
BackupBridge.exportEncrypted(
repository,
FileOutputStream(file),
pass.toCharArray(),
DESKTOP_APP_VERSION,
)
}
}.onSuccess { say("Exported $it encrypted notes to ${file.name}") }
.onFailure { say("Export failed: ${it.message}") }
}
},
)
null -> Unit
}
},
)
}
}
@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
exportStage = ExportStage.AwaitingPassphrase
flows.launchExportEncrypted()
},
)
}
// ---- import dialogs --------------------------------------------------
when (val stage = importStage) {
is ImportStage.NeedPassphrase -> PassphraseDialog(
blurb = "This backup is encrypted (INCDBK1). Enter its passphrase to preview it.",
onDismiss = { importStage = null },
onConfirm = { pass ->
scope.launch {
val preview = withContext(Dispatchers.IO) {
runCatching {
BackupBridge.preview(FileInputStream(stage.file), pass.toCharArray())
}.getOrNull()
}
if (preview == null) {
say("Wrong passphrase") // dialog stays open for a retry
} else {
importStage = ImportStage.Confirm(stage.file, preview, pass)
}
}
},
)
is ImportStage.Confirm -> ConfirmImportDialog(
preview = stage.preview,
skipExisting = skipDuplicates,
onSkipChange = { skipDuplicates = it },
onDismiss = { importStage = null },
onConfirm = {
importStage = null
scope.launch {
runCatching {
withContext(Dispatchers.IO) {
BackupBridge.import(
repository,
FileInputStream(stage.file),
stage.passphrase?.toCharArray(),
skipExisting = skipDuplicates,
)
}
}.onSuccess {
say(
"Imported ${it.imported} notes" +
if (it.skipped > 0) " · skipped ${it.skipped} already imported" else "",
)
}
.onFailure { say("Import failed: ${it.message}") }
}
},
)
null -> Unit
}
// ---- export dialogs --------------------------------------------------
when (exportStage) {
ExportStage.AwaitingPassphrase -> PassphraseDialog(
blurb = "Choose the passphrase for the encrypted backup (same INCDBK1 envelope as the phone).",
onDismiss = { exportStage = null },
onConfirm = { pass ->
exportStage = null
scope.launch {
val file = pickFile(load = false, title = "Export backup", suggested = suggestedExportName()) ?: return@launch
runCatching {
withContext(Dispatchers.IO) {
BackupBridge.exportEncrypted(
repository,
FileOutputStream(file),
pass.toCharArray(),
DESKTOP_APP_VERSION,
)
}
}.onSuccess { say("Exported $it encrypted notes to ${file.name}") }
.onFailure { say("Export failed: ${it.message}") }
}
},
)
null -> Unit
}
flows.Dialogs()
}
/** Where the import flow stands (the file is already chosen). */