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:
1 parent
0dc5935d1d
commit
d264238640
5 files changed
+461
-216
No files matched your search
@@ -36,7 +36,7 @@ import org.incido.compose.data.settings.ThemeMode
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun AppearanceSection(
|
fun AppearanceSection(
|
||||||
themeMode: ThemeMode,
|
themeMode: ThemeMode,
|
||||||
dynamicColor: Boolean,
|
dynamicColor: Boolean,
|
||||||
onThemeMode: (ThemeMode) -> Unit,
|
onThemeMode: (ThemeMode) -> Unit,
|
||||||
@@ -88,7 +88,7 @@ internal fun AppearanceSection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun BackupSection(
|
fun BackupSection(
|
||||||
onExport: () -> Unit,
|
onExport: () -> Unit,
|
||||||
onImport: () -> Unit,
|
onImport: () -> Unit,
|
||||||
/** Null hides the Carnet row — its importer lives in androidMain. */
|
/** Null hides the Carnet row — its importer lives in androidMain. */
|
||||||
@@ -124,7 +124,7 @@ internal fun BackupSection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun AboutSection(
|
fun AboutSection(
|
||||||
version: String,
|
version: String,
|
||||||
onVersionClick: () -> Unit,
|
onVersionClick: () -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -156,12 +156,13 @@ internal fun AboutSection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Building blocks — M4.4d: internal so SettingsScreen (androidMain) and
|
// Building blocks — M4.4d: shared vocabulary for SettingsScreen
|
||||||
// the desktop settings surface (commonMain) share one vocabulary.
|
// (androidMain) and DesktopSettingsScreen. M4.5 note: public, not
|
||||||
|
// internal — desktopApp is a separate Gradle module.
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun SettingsSection(title: String, content: @Composable () -> Unit) {
|
fun SettingsSection(title: String, content: @Composable () -> Unit) {
|
||||||
Column {
|
Column {
|
||||||
Text(
|
Text(
|
||||||
text = title,
|
text = title,
|
||||||
@@ -179,7 +180,7 @@ internal fun SettingsSection(title: String, content: @Composable () -> Unit) {
|
|||||||
/** v0.3.3.0: optionally renders a disabled (greyed) switch — used for
|
/** v0.3.3.0: optionally renders a disabled (greyed) switch — used for
|
||||||
* the mutually-exclusive PIN / Biometric toggles. */
|
* the mutually-exclusive PIN / Biometric toggles. */
|
||||||
@Composable
|
@Composable
|
||||||
internal fun SettingsToggle(
|
fun SettingsToggle(
|
||||||
title: String,
|
title: String,
|
||||||
subtitle: String,
|
subtitle: String,
|
||||||
checked: Boolean,
|
checked: Boolean,
|
||||||
@@ -215,7 +216,7 @@ internal fun SettingsToggle(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun SettingsRow(
|
fun SettingsRow(
|
||||||
title: String,
|
title: String,
|
||||||
subtitle: String,
|
subtitle: String,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
|
|||||||
@@ -59,14 +59,26 @@ const val DESKTOP_APP_VERSION = "0.4.2.0"
|
|||||||
* PassphraseDialog.kt is deliberately NOT ported (M4 will move the real
|
* PassphraseDialog.kt is deliberately NOT ported (M4 will move the real
|
||||||
* one into common code).
|
* 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
|
@Composable
|
||||||
fun BackupActions(
|
fun rememberBackupFlows(
|
||||||
repository: NoteRepository,
|
repository: NoteRepository,
|
||||||
snackbar: SnackbarHostState,
|
snackbar: SnackbarHostState,
|
||||||
modifier: Modifier = Modifier,
|
): BackupFlows {
|
||||||
) {
|
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
var menuOpen by remember { mutableStateOf(false) }
|
|
||||||
var importStage by remember { mutableStateOf<ImportStage?>(null) }
|
var importStage by remember { mutableStateOf<ImportStage?>(null) }
|
||||||
var exportStage by remember { mutableStateOf<ExportStage?>(null) }
|
var exportStage by remember { mutableStateOf<ExportStage?>(null) }
|
||||||
// M2 task 3: dedupe is ON by default; the confirm dialog exposes it.
|
// 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) } }
|
fun say(message: String) { scope.launch { snackbar.showSnackbar(message) } }
|
||||||
|
|
||||||
IconButton(onClick = { menuOpen = true }, modifier = modifier) {
|
return remember(repository) {
|
||||||
Icon(Icons.Default.MoreVert, contentDescription = "Backup menu")
|
BackupFlows(
|
||||||
}
|
launchImport = {
|
||||||
DropdownMenu(expanded = menuOpen, onDismissRequest = { menuOpen = false }) {
|
|
||||||
DropdownMenuItem(
|
|
||||||
text = { Text("Import from file…") },
|
|
||||||
onClick = {
|
|
||||||
menuOpen = false
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val file = pickFile(load = true, title = "Import backup") ?: return@launch
|
val file = pickFile(load = true, title = "Import backup") ?: return@launch
|
||||||
startImport(file, ::say) { stage -> importStage = stage }
|
startImport(file, ::say) { stage -> importStage = stage }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
launchExportPlain = {
|
||||||
DropdownMenuItem(
|
|
||||||
text = { Text("Export (plain)") },
|
|
||||||
onClick = {
|
|
||||||
menuOpen = false
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val file = pickFile(load = false, title = "Export backup", suggested = suggestedExportName()) ?: return@launch
|
val file = pickFile(load = false, title = "Export backup", suggested = suggestedExportName()) ?: return@launch
|
||||||
runCatching {
|
runCatching {
|
||||||
@@ -102,96 +105,128 @@ fun BackupActions(
|
|||||||
.onFailure { say("Export failed: ${it.message}") }
|
.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(
|
DropdownMenuItem(
|
||||||
text = { Text("Export (encrypted)…") },
|
text = { Text("Export (encrypted)…") },
|
||||||
onClick = {
|
onClick = {
|
||||||
menuOpen = false
|
menuOpen = false
|
||||||
exportStage = ExportStage.AwaitingPassphrase
|
flows.launchExportEncrypted()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
flows.Dialogs()
|
||||||
// ---- 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Where the import flow stands (the file is already chosen). */
|
/** Where the import flow stands (the file is already chosen). */
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
package org.incido.desktop
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.SnackbarHost
|
||||||
|
import androidx.compose.material3.SnackbarHostState
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
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 androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.incido.compose.ui.settings.AboutSection
|
||||||
|
import org.incido.compose.ui.settings.AppearanceSection
|
||||||
|
import org.incido.compose.ui.settings.ReleaseNotesDialog
|
||||||
|
import org.incido.compose.ui.settings.BackupSection
|
||||||
|
import org.incido.compose.ui.settings.SettingsRow
|
||||||
|
import org.incido.compose.ui.settings.SettingsSection
|
||||||
|
import org.incido.compose.ui.settings.SettingsToggle
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phase 1 (M4.5): the desktop settings screen.
|
||||||
|
*
|
||||||
|
* Composes the SAME section composables the phone's SettingsScreen uses —
|
||||||
|
* Appearance / Backup / About moved to commonMain in M4.4d — plus two
|
||||||
|
* desktop rows. The Android-only surfaces are hidden per §6.5:
|
||||||
|
* SecuritySection (PIN / biometric / screenshot blocking — no
|
||||||
|
* BiometricPrompt, no FLAG_SECURE, desktop lock deferred), the
|
||||||
|
* dynamic-color row (AppearanceSection drops it when onDynamicColor is
|
||||||
|
* null) and the 3rd-party importer (onImportCarnet null).
|
||||||
|
*
|
||||||
|
* The encryption row mirrors SecurityActions' menu logic — the two share
|
||||||
|
* DesktopContainer's services and the Android SettingsViewModel's enable/
|
||||||
|
* disable ordering (key → cipher → sweep → flags; disable sweeps first).
|
||||||
|
*/
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun DesktopSettingsScreen(app: DesktopContainer, onBack: () -> Unit) {
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
val snackbar = remember { SnackbarHostState() }
|
||||||
|
fun say(message: String) { scope.launch { snackbar.showSnackbar(message) } }
|
||||||
|
|
||||||
|
val settings by app.settingsRepository.userSettingsFlow
|
||||||
|
.collectAsState(initial = org.incido.compose.data.settings.UserSettings())
|
||||||
|
val backup = rememberBackupFlows(app.noteRepository, snackbar)
|
||||||
|
val keys = rememberSecurityKeyFlows(app, snackbar)
|
||||||
|
var showNotes by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
Scaffold(
|
||||||
|
snackbarHost = { SnackbarHost(snackbar) },
|
||||||
|
topBar = {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text("Settings") },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = onBack) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) { padding ->
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(padding)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
) {
|
||||||
|
AppearanceSection(
|
||||||
|
themeMode = settings.themeMode,
|
||||||
|
dynamicColor = settings.dynamicColor,
|
||||||
|
onThemeMode = { mode -> scope.launch { app.settingsRepository.setThemeMode(mode) } },
|
||||||
|
onDynamicColor = null, // no Material You on the JVM (§6.5)
|
||||||
|
)
|
||||||
|
// Desktop-only: the two rows SecurityActions' menu carried.
|
||||||
|
SettingsSection(title = "Encryption") {
|
||||||
|
Column(Modifier.padding(horizontal = 16.dp, vertical = 4.dp)) {
|
||||||
|
SettingsToggle(
|
||||||
|
title = if (settings.isEncryptionActive) "Encrypt all notes" else "Decrypt all notes",
|
||||||
|
subtitle = "At-rest AES-GCM on this device — the same sweep the phone runs.",
|
||||||
|
checked = settings.isEncryptionActive,
|
||||||
|
onCheckedChange = { want ->
|
||||||
|
if (want != settings.isEncryptionActive) {
|
||||||
|
scope.launch { toggleDesktopEncryption(app, want, ::say) }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
SettingsRow(
|
||||||
|
title = "Export recovery key…",
|
||||||
|
subtitle = "Save the INCKEY1 envelope (passphrase-protected).",
|
||||||
|
onClick = { keys.launchExport() },
|
||||||
|
)
|
||||||
|
SettingsRow(
|
||||||
|
title = "Import recovery key…",
|
||||||
|
subtitle = "Restore the key from an INCKEY1 file (phone export works).",
|
||||||
|
onClick = { keys.launchImport() },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BackupSection(
|
||||||
|
onExport = { backup.launchExportPlain() },
|
||||||
|
onImport = { backup.launchImport() },
|
||||||
|
onImportCarnet = null, // the Carnet importer lives in androidMain
|
||||||
|
)
|
||||||
|
AboutSection(
|
||||||
|
version = DESKTOP_APP_VERSION,
|
||||||
|
onVersionClick = { showNotes = true },
|
||||||
|
)
|
||||||
|
Spacer(Modifier.padding(bottom = 24.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Both dialog hosts render here; only one set of flows is live
|
||||||
|
// per trigger, so they never stack unexpectedly.
|
||||||
|
backup.Dialogs()
|
||||||
|
keys.Dialogs()
|
||||||
|
if (showNotes) {
|
||||||
|
ReleaseNotesDialog(onDismiss = { showNotes = false })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
|
import androidx.compose.material.icons.filled.Settings
|
||||||
import androidx.compose.material.icons.filled.Star
|
import androidx.compose.material.icons.filled.Star
|
||||||
import androidx.compose.material.icons.outlined.StarBorder
|
import androidx.compose.material.icons.outlined.StarBorder
|
||||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
@@ -101,6 +102,9 @@ fun main(args: Array<String>) {
|
|||||||
val backupPassphrase = args.argAfter("--backup-passphrase")
|
val backupPassphrase = args.argAfter("--backup-passphrase")
|
||||||
// M3 task 4: scripted at-rest encryption legs — leg A enables + proves,
|
// M3 task 4: scripted at-rest encryption legs — leg A enables + proves,
|
||||||
// leg B (a SEPARATE process) proves the relaunch auto-install + sweep.
|
// leg B (a SEPARATE process) proves the relaunch auto-install + sweep.
|
||||||
|
// 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 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"
|
||||||
@@ -144,6 +148,7 @@ fun main(args: Array<String>) {
|
|||||||
windowState = windowState,
|
windowState = windowState,
|
||||||
exitAfterSeconds = exitAfterSeconds,
|
exitAfterSeconds = exitAfterSeconds,
|
||||||
selfTest = selfTest,
|
selfTest = selfTest,
|
||||||
|
settingsSmoke = settingsSmoke,
|
||||||
backupImport = backupImport,
|
backupImport = backupImport,
|
||||||
backupExport = backupExport,
|
backupExport = backupExport,
|
||||||
backupExportEnc = backupExportEnc,
|
backupExportEnc = backupExportEnc,
|
||||||
@@ -170,6 +175,7 @@ private fun NotesWindow(
|
|||||||
windowState: androidx.compose.ui.window.WindowState,
|
windowState: androidx.compose.ui.window.WindowState,
|
||||||
exitAfterSeconds: Long?,
|
exitAfterSeconds: Long?,
|
||||||
selfTest: Boolean,
|
selfTest: Boolean,
|
||||||
|
settingsSmoke: Boolean,
|
||||||
backupImport: String?,
|
backupImport: String?,
|
||||||
backupExport: String?,
|
backupExport: String?,
|
||||||
backupExportEnc: String?,
|
backupExportEnc: String?,
|
||||||
@@ -184,6 +190,8 @@ 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) }
|
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 scope = rememberCoroutineScope()
|
||||||
val snackbar = remember { SnackbarHostState() }
|
val snackbar = remember { SnackbarHostState() }
|
||||||
|
|
||||||
@@ -202,6 +210,9 @@ private fun NotesWindow(
|
|||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colorScheme = if (darkTheme) darkColorScheme() else lightColorScheme(),
|
colorScheme = if (darkTheme) darkColorScheme() else lightColorScheme(),
|
||||||
) {
|
) {
|
||||||
|
if (showSettings) {
|
||||||
|
DesktopSettingsScreen(app = app, onBack = { showSettings = false })
|
||||||
|
} else {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
snackbarHost = { SnackbarHost(snackbar) },
|
snackbarHost = { SnackbarHost(snackbar) },
|
||||||
topBar = {
|
topBar = {
|
||||||
@@ -230,6 +241,9 @@ private fun NotesWindow(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
) { Icon(Icons.Filled.Add, contentDescription = "New note") }
|
) { Icon(Icons.Filled.Add, contentDescription = "New note") }
|
||||||
|
IconButton(onClick = { showSettings = true }) {
|
||||||
|
Icon(Icons.Filled.Settings, contentDescription = "Settings")
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -267,6 +281,7 @@ private fun NotesWindow(
|
|||||||
Editor(repository = repository, note = selected)
|
Editor(repository = repository, note = selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(notes.size) {
|
LaunchedEffect(notes.size) {
|
||||||
@@ -295,6 +310,15 @@ private fun NotesWindow(
|
|||||||
println("SELFTEST wrote note id=${saved.id}")
|
println("SELFTEST wrote note id=${saved.id}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (settingsSmoke) {
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
delay(1500)
|
||||||
|
// Compose the real screen (crash = failure); it stays up as the
|
||||||
|
// window's content until --exit-after closes the app.
|
||||||
|
showSettings = true
|
||||||
|
println("SETTINGS shown (shared Appearance/Backup/About + desktop rows)")
|
||||||
|
}
|
||||||
|
}
|
||||||
if (backupImport != null || backupExportEnc != null) {
|
if (backupImport != null || backupExportEnc != null) {
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
delay(800) // mirror the self-test pacing; wait past first frame
|
delay(800) // mirror the self-test pacing; wait past first frame
|
||||||
|
|||||||
@@ -51,9 +51,7 @@ fun SecurityActions(
|
|||||||
) {
|
) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
var menuOpen by remember { mutableStateOf(false) }
|
var menuOpen by remember { mutableStateOf(false) }
|
||||||
var pendingKeyExport by remember { mutableStateOf(false) }
|
val keys = rememberSecurityKeyFlows(app, snackbar)
|
||||||
var pendingKeyImport by remember { mutableStateOf<File?>(null) }
|
|
||||||
var confirmOverwrite by remember { mutableStateOf<Pair<File, String>?>(null) }
|
|
||||||
|
|
||||||
val settings by app.settingsRepository.userSettingsFlow
|
val settings by app.settingsRepository.userSettingsFlow
|
||||||
.collectAsState(initial = org.incido.compose.data.settings.UserSettings())
|
.collectAsState(initial = org.incido.compose.data.settings.UserSettings())
|
||||||
@@ -98,46 +96,94 @@ fun SecurityActions(
|
|||||||
text = { Text(if (active) "Decrypt all notes…" else "Encrypt all notes") },
|
text = { Text(if (active) "Decrypt all notes…" else "Encrypt all notes") },
|
||||||
onClick = {
|
onClick = {
|
||||||
menuOpen = false
|
menuOpen = false
|
||||||
scope.launch {
|
scope.launch { toggleDesktopEncryption(app, want = !active, ::say) }
|
||||||
val message = withContext(Dispatchers.IO) {
|
|
||||||
if (!app.settingsRepository.snapshot().isEncryptionActive) {
|
|
||||||
// Android SettingsViewModel's enable order:
|
|
||||||
// key → cipher into holder → sweep → flags.
|
|
||||||
app.keyProvider.getOrCreateKey()
|
|
||||||
app.cipherHolder.cipher = AesGcmFieldCipher(app.keyProvider)
|
|
||||||
app.noteCryptoService.encryptAllInPlace()
|
|
||||||
app.settingsRepository.setSecurityEnabled(true)
|
|
||||||
app.settingsRepository.setEncryptionEnabled(true)
|
|
||||||
"Notes are now encrypted on this device."
|
|
||||||
} else {
|
|
||||||
// Disable order: sweep FIRST, then cipher, then flags.
|
|
||||||
app.noteCryptoService.decryptAllInPlace()
|
|
||||||
app.cipherHolder.cipher = null
|
|
||||||
app.settingsRepository.setEncryptionEnabled(false)
|
|
||||||
app.settingsRepository.setSecurityEnabled(false)
|
|
||||||
"Notes are now stored unencrypted."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
app.encryptionVerifier.checkNow()
|
|
||||||
say(message)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text("Export recovery key…") },
|
text = { Text("Export recovery key…") },
|
||||||
onClick = {
|
onClick = {
|
||||||
menuOpen = false
|
menuOpen = false
|
||||||
if (!app.keyProvider.hasKey()) {
|
keys.launchExport()
|
||||||
say("Encryption isn't active — nothing to back up.")
|
|
||||||
} else {
|
|
||||||
pendingKeyExport = true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text("Import recovery key…") },
|
text = { Text("Import recovery key…") },
|
||||||
onClick = {
|
onClick = {
|
||||||
menuOpen = false
|
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
|
||||||
|
* SettingsViewModel's ordering either way (enable: key → cipher →
|
||||||
|
* sweep → flags; disable: sweep → cipher → flags).
|
||||||
|
*/
|
||||||
|
internal suspend fun toggleDesktopEncryption(
|
||||||
|
app: DesktopContainer,
|
||||||
|
want: Boolean,
|
||||||
|
say: (String) -> Unit,
|
||||||
|
) {
|
||||||
|
val message = withContext(Dispatchers.IO) {
|
||||||
|
if (!want) {
|
||||||
|
// Disable order: sweep FIRST, then cipher, then flags.
|
||||||
|
app.noteCryptoService.decryptAllInPlace()
|
||||||
|
app.cipherHolder.cipher = null
|
||||||
|
app.settingsRepository.setEncryptionEnabled(false)
|
||||||
|
app.settingsRepository.setSecurityEnabled(false)
|
||||||
|
"Notes are now stored unencrypted."
|
||||||
|
} else {
|
||||||
|
// Enable order: key → cipher into holder → sweep → flags.
|
||||||
|
app.keyProvider.getOrCreateKey()
|
||||||
|
app.cipherHolder.cipher = AesGcmFieldCipher(app.keyProvider)
|
||||||
|
app.noteCryptoService.encryptAllInPlace()
|
||||||
|
app.settingsRepository.setSecurityEnabled(true)
|
||||||
|
app.settingsRepository.setEncryptionEnabled(true)
|
||||||
|
"Notes are now encrypted on this device."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app.encryptionVerifier.checkNow()
|
||||||
|
say(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SEC_PART_B
|
||||||
|
/**
|
||||||
|
* M4.5: recovery-key export/import, extracted from the menu so the
|
||||||
|
* settings screen's rows drive the exact same flows (same passphrases,
|
||||||
|
* same hasKey gate, same overwrite warning gate, same import leg).
|
||||||
|
*/
|
||||||
|
internal class SecurityKeyFlows constructor(
|
||||||
|
val launchExport: () -> Unit,
|
||||||
|
val launchImport: () -> Unit,
|
||||||
|
val Dialogs: @Composable () -> Unit,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
internal fun rememberSecurityKeyFlows(
|
||||||
|
app: DesktopContainer,
|
||||||
|
snackbar: SnackbarHostState,
|
||||||
|
): SecurityKeyFlows {
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
var pendingKeyExport by remember { mutableStateOf(false) }
|
||||||
|
var pendingKeyImport by remember { mutableStateOf<File?>(null) }
|
||||||
|
var confirmOverwrite by remember { mutableStateOf<Pair<File, String>?>(null) }
|
||||||
|
|
||||||
|
fun say(message: String) { scope.launch { snackbar.showSnackbar(message) } }
|
||||||
|
|
||||||
|
return remember(app) {
|
||||||
|
SecurityKeyFlows(
|
||||||
|
launchExport = {
|
||||||
|
if (!app.keyProvider.hasKey()) {
|
||||||
|
say("Encryption isn't active — nothing to back up.")
|
||||||
|
} else {
|
||||||
|
pendingKeyExport = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
launchImport = {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val file = pickFile(
|
val file = pickFile(
|
||||||
load = true,
|
load = true,
|
||||||
@@ -147,90 +193,91 @@ fun SecurityActions(
|
|||||||
pendingKeyImport = file
|
pendingKeyImport = file
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
Dialogs = {
|
||||||
}
|
// ---- passphrase dialogs (shared with the backup menu) ----
|
||||||
|
|
||||||
// ---- passphrase dialogs (shared with the backup menu) ----
|
if (pendingKeyExport) {
|
||||||
|
PassphraseDialog(
|
||||||
if (pendingKeyExport) {
|
blurb = "This passphrase protects the recovery file. Notes can only " +
|
||||||
PassphraseDialog(
|
"be opened on another device with this file AND the passphrase.",
|
||||||
blurb = "This passphrase protects the recovery file. Notes can only " +
|
onDismiss = { pendingKeyExport = false },
|
||||||
"be opened on another device with this file AND the passphrase.",
|
onConfirm = { passphrase ->
|
||||||
onDismiss = { pendingKeyExport = false },
|
pendingKeyExport = false
|
||||||
onConfirm = { passphrase ->
|
scope.launch {
|
||||||
pendingKeyExport = false
|
val outcome = runCatching {
|
||||||
scope.launch {
|
withContext(Dispatchers.IO) {
|
||||||
val outcome = runCatching {
|
val target = pickFile(
|
||||||
withContext(Dispatchers.IO) {
|
load = false,
|
||||||
val target = pickFile(
|
title = "Export recovery key",
|
||||||
load = false,
|
suggested = "incido-recovery-key.incidokey",
|
||||||
title = "Export recovery key",
|
extensions = listOf("incidokey"),
|
||||||
suggested = "incido-recovery-key.incidokey",
|
) ?: return@withContext null
|
||||||
extensions = listOf("incidokey"),
|
target.writeBytes(app.keyProvider.exportRecoveryKey(passphrase.toCharArray()))
|
||||||
) ?: return@withContext null
|
target
|
||||||
target.writeBytes(app.keyProvider.exportRecoveryKey(passphrase.toCharArray()))
|
}
|
||||||
target
|
}
|
||||||
}
|
// The codec zeroes the CharArray derived from the
|
||||||
}
|
// passphrase inside exportRecoveryKey (fill('0')).
|
||||||
// The codec zeroes the CharArray derived from the
|
say(
|
||||||
// passphrase inside exportRecoveryKey (fill('0')).
|
outcome.fold(
|
||||||
say(
|
onSuccess = { if (it == null) "Export cancelled." else "Recovery key exported to ${it.name}." },
|
||||||
outcome.fold(
|
onFailure = { "Export failed: ${it.message}" },
|
||||||
onSuccess = { if (it == null) "Export cancelled." else "Recovery key exported to ${it.name}." },
|
),
|
||||||
onFailure = { "Export failed: ${it.message}" },
|
)
|
||||||
),
|
}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pendingKeyImport?.let { file ->
|
pendingKeyImport?.let { file ->
|
||||||
PassphraseDialog(
|
PassphraseDialog(
|
||||||
blurb = "Unlock the recovery key file. Importing it replaces this " +
|
blurb = "Unlock the recovery key file. Importing it replaces this " +
|
||||||
"library's encryption key.",
|
"library's encryption key.",
|
||||||
onDismiss = { pendingKeyImport = null },
|
onDismiss = { pendingKeyImport = null },
|
||||||
onConfirm = { passphrase ->
|
onConfirm = { passphrase ->
|
||||||
pendingKeyImport = null
|
pendingKeyImport = null
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val bytes = withContext(Dispatchers.IO) { file.readBytes() }
|
val bytes = withContext(Dispatchers.IO) { file.readBytes() }
|
||||||
if (!org.incido.compose.data.backup.EncryptedKeyCodec.isEncryptedKey(bytes)) {
|
if (!org.incido.compose.data.backup.EncryptedKeyCodec.isEncryptedKey(bytes)) {
|
||||||
say("Not an Incido recovery key file.")
|
say("Not an Incido recovery key file.")
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
if (app.noteCryptoService.hasEncryptedRows()) {
|
if (app.noteCryptoService.hasEncryptedRows()) {
|
||||||
// Android warns before overwriting a live key — same gate.
|
// Android warns before overwriting a live key — same gate.
|
||||||
confirmOverwrite = file to passphrase
|
confirmOverwrite = file to passphrase
|
||||||
} else {
|
} else {
|
||||||
importKey(app, bytes, passphrase, ::say)
|
importKey(app, bytes, passphrase, ::say)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
confirmOverwrite?.let { (file, passphrase) ->
|
confirmOverwrite?.let { (file, passphrase) ->
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = { confirmOverwrite = null },
|
onDismissRequest = { confirmOverwrite = null },
|
||||||
title = { Text("Replace encryption key?") },
|
title = { Text("Replace encryption key?") },
|
||||||
text = {
|
text = {
|
||||||
Text(
|
Text(
|
||||||
"This library already has encrypted notes. Installing a " +
|
"This library already has encrypted notes. Installing a " +
|
||||||
"different key makes those notes unreadable unless they " +
|
"different key makes those notes unreadable unless they " +
|
||||||
"were encrypted with the SAME key (e.g. restoring this " +
|
"were encrypted with the SAME key (e.g. restoring this " +
|
||||||
"device's own recovery file).",
|
"device's own recovery file).",
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
confirmOverwrite = null
|
confirmOverwrite = null
|
||||||
scope.launch { importKey(app, file.readBytes(), passphrase, ::say) }
|
scope.launch { importKey(app, file.readBytes(), passphrase, ::say) }
|
||||||
},
|
},
|
||||||
) { Text("Replace") }
|
) { Text("Replace") }
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = { confirmOverwrite = null }) { Text("Cancel") }
|
TextButton(onClick = { confirmOverwrite = null }) { Text("Cancel") }
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user