From bdb3d7157d3211d2bc074113319742cf15746e32 Mon Sep 17 00:00:00 2001 From: Incido Developer Date: Tue, 6 Oct 2026 18:26:07 +1300 Subject: [PATCH] feat(phase-1/m4.4a): first screens to commonMain + shared clipboard Pure moves: IncidoDrawer, ReleaseNotesDialog, PassphraseDialog (clipboard: Context.getSystemService -> LocalClipboardManager, the SAME API both targets ship in Compose 1.7.3 - the section 6.3 LocalClipboard+ClipEntry swap is a Compose 1.8-only API, recorded for M5+). PassphraseGenerator moves behind an internal expect/ actual secureRandomInt (blockingFirst precedent; identical SecureRandom actuals - both targets ARE the JVM). New seams justified: secureRandomInt (java.security is not common); commonMain gains jetbrains lifecycle viewmodel-compose + runtime-compose (the SAME coordinates androidMain resolved since M4.1) and material-icons-extended (moved with the screens). Verified: ./gradlew assembleDebug :desktopApp:build SUCCESSFUL + :composeApp:compileKotlinJvm + :desktopApp:run --self-test (SELFTEST id=1 -> RENDER notes=1 selected=1) + :core:data-jvm:smoke (M1a PASS); objectbox-models clean. --- composeApp/build.gradle.kts | 16 ++++++++++ .../data/backup/PassphraseRandom.android.kt | 14 +++++++++ .../data/backup/PassphraseGenerator.kt | 16 +++++++--- .../incido/compose/ui/drawer/IncidoDrawer.kt | 0 .../compose/ui/settings/PassphraseDialog.kt | 31 +++++++++++-------- .../compose/ui/settings/ReleaseNotesDialog.kt | 0 .../data/backup/PassphraseRandom.jvm.kt | 14 +++++++++ gradle/libs.versions.toml | 1 + 8 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 composeApp/src/androidMain/kotlin/org/incido/compose/data/backup/PassphraseRandom.android.kt rename composeApp/src/{androidMain => commonMain}/kotlin/org/incido/compose/data/backup/PassphraseGenerator.kt (76%) rename composeApp/src/{androidMain => commonMain}/kotlin/org/incido/compose/ui/drawer/IncidoDrawer.kt (100%) rename composeApp/src/{androidMain => commonMain}/kotlin/org/incido/compose/ui/settings/PassphraseDialog.kt (90%) rename composeApp/src/{androidMain => commonMain}/kotlin/org/incido/compose/ui/settings/ReleaseNotesDialog.kt (100%) create mode 100644 composeApp/src/jvmMain/kotlin/org/incido/compose/data/backup/PassphraseRandom.jvm.kt diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 5d0721d..f610720 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -46,6 +46,13 @@ kotlin { implementation(compose.ui) implementation(compose.foundation) implementation(compose.material3) + // Phase 1 (M4.4a): moved screens (IncidoDrawer, PassphraseDialog) + // use extended icons (Drafts/LabelOff/Tag/ContentCopy/Visibility). + // androidMain already had the same jetbrains coordinate (it + // resolves to androidx on that target); on jvm this pulls the + // ~100 MB material-icons-extended-desktop jar (§3 trap — a first + // build can time out; retry, don't debug). + implementation(libs.compose.material.icons.extended) implementation(libs.kotlinx.coroutines.core) // Phase 1 (M4.3b): the §6.4 artifact check resolves GREEN — // these org.jetbrains.androidx.lifecycle coordinates are what @@ -56,6 +63,15 @@ kotlin { // ViewModels move with their `androidx.lifecycle.*` imports // UNCHANGED (the offline set keeps the androidx FQCNs). implementation(libs.androidx.lifecycle.viewmodel) + // Phase 1 (M4.4a): screens move with their construction sites + // intact — `viewModel(factory = …)` from viewmodel-compose and + // `collectAsStateWithLifecycle` from runtime-compose. These are + // the SAME jetbrains coordinates androidMain already resolved + // since M4.1 (collectAsStateWithLifecycle reached the Android + // classpath through them), now declared in commonMain so the + // moved screens compile for both targets (§6.4 GREEN). + implementation(libs.androidx.lifecycle.viewmodel.compose) + implementation(libs.androidx.lifecycle.runtime.compose) // Phase 1 (M4.2): :core:domain is multiplatform now (M4.2's own // conversion), so commonMain can see it — this is what let // NoteColors.kt move up. api: screens/ViewModels across all diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/data/backup/PassphraseRandom.android.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/data/backup/PassphraseRandom.android.kt new file mode 100644 index 0000000..83e8ab3 --- /dev/null +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/data/backup/PassphraseRandom.android.kt @@ -0,0 +1,14 @@ +package org.incido.compose.data.backup + +import java.security.SecureRandom + +/** + * M4.4a seam for [PassphraseGenerator] — identical two-liner actual on + * both targets (both targets ARE the JVM; commonMain just cannot spell + * `java.security`). Behaviour (CSPRNG backing, draw distribution) is + * exactly the pre-M4 `SecureRandom()` field it replaces. + */ + +private val secureRandom = SecureRandom() + +internal actual fun secureRandomInt(bound: Int): Int = secureRandom.nextInt(bound) \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/data/backup/PassphraseGenerator.kt b/composeApp/src/commonMain/kotlin/org/incido/compose/data/backup/PassphraseGenerator.kt similarity index 76% rename from composeApp/src/androidMain/kotlin/org/incido/compose/data/backup/PassphraseGenerator.kt rename to composeApp/src/commonMain/kotlin/org/incido/compose/data/backup/PassphraseGenerator.kt index 0ad2b21..fefda58 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/data/backup/PassphraseGenerator.kt +++ b/composeApp/src/commonMain/kotlin/org/incido/compose/data/backup/PassphraseGenerator.kt @@ -1,7 +1,6 @@ package org.incido.compose.data.backup import org.incido.compose.data.settings.PasswordPolicy -import java.security.SecureRandom /** * v0.3.2.0: SecureRandom-based passphrase generator for encrypted @@ -15,6 +14,12 @@ import java.security.SecureRandom * If a freshly-generated passphrase fails validation (rare — only if * the random draw happens to miss both a digit and a special) we * regenerate, so the return type is non-nullable. + * + * M4.4a: `java.security.SecureRandom` is not a commonMain declaration, + * so the draw goes through [secureRandomInt] — an internal expect/actual + * whose actuals are the same one-liner over a shared SecureRandom on + * both targets (same seam discipline as M4.3a's `blockingFirst`; both + * targets ARE JVM, this is spelling, not behaviour). */ object PassphraseGenerator { @@ -33,8 +38,6 @@ object PassphraseGenerator { PasswordPolicy.SPECIAL_CHARS ).toCharArray() - private val secureRandom = SecureRandom() - /** * Generate a passphrase of [length] characters (clamped to the * policy's [PasswordPolicy.MIN_LENGTH] / [PasswordPolicy.MAX_LENGTH] @@ -50,14 +53,17 @@ object PassphraseGenerator { // and a special in any draw of >= 12 chars. Fall back to a // hand-crafted compliant value so we never throw from a UI // button tap. - return "IncidoBackup!" + secureRandom.nextInt(10_000).toString().padStart(4, '0') + return "IncidoBackup!" + secureRandomInt(10_000).toString().padStart(4, '0') } private fun buildRandom(length: Int): String { val out = StringBuilder(length) - repeat(length) { out.append(ALPHABET[secureRandom.nextInt(ALPHABET.size)]) } + repeat(length) { out.append(ALPHABET[secureRandomInt(ALPHABET.size)]) } return out.toString() } private const val MAX_ATTEMPTS = 16 } + +/** CSPRNG draw in `[0, bound)` — SecureRandom on every target. */ +internal expect fun secureRandomInt(bound: Int): Int diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/drawer/IncidoDrawer.kt b/composeApp/src/commonMain/kotlin/org/incido/compose/ui/drawer/IncidoDrawer.kt similarity index 100% rename from composeApp/src/androidMain/kotlin/org/incido/compose/ui/drawer/IncidoDrawer.kt rename to composeApp/src/commonMain/kotlin/org/incido/compose/ui/drawer/IncidoDrawer.kt diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/PassphraseDialog.kt b/composeApp/src/commonMain/kotlin/org/incido/compose/ui/settings/PassphraseDialog.kt similarity index 90% rename from composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/PassphraseDialog.kt rename to composeApp/src/commonMain/kotlin/org/incido/compose/ui/settings/PassphraseDialog.kt index 7f5bb52..b5c43e9 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/PassphraseDialog.kt +++ b/composeApp/src/commonMain/kotlin/org/incido/compose/ui/settings/PassphraseDialog.kt @@ -1,8 +1,5 @@ package org.incido.compose.ui.settings -import android.content.ClipData -import android.content.ClipboardManager -import android.content.Context import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -27,7 +24,9 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.ClipboardManager +import androidx.compose.ui.platform.LocalClipboardManager +import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.VisualTransformation @@ -61,13 +60,23 @@ import org.incido.compose.data.settings.PasswordPolicy * truth for "is this passphrase correct", surfaced as * "Incorrect passphrase." via snackbar on mismatch. */ +@Suppress("DEPRECATION") // LocalClipboardManager: see body comment — 1.8 API swap @Composable fun PassphraseDialog( onConfirm: (CharArray) -> Unit, onDismiss: () -> Unit, mode: PassphraseDialogMode = PassphraseDialogMode.EXPORT, ) { - val context = LocalContext.current + // M4.4a clipboard migration: the §6.3 note (`LocalClipboardManager` → + // `LocalClipboard` + `ClipEntry`) describes the Compose UI **1.8** API — + // on this stack (1.7.3) `ClipEntry` has no public constructor and + // `LocalClipboard` does not exist yet (paid for while compiling). + // LocalClipboardManager is the SAME API on both targets in 1.7.x — the + // Android side keeps its ClipboardManager write verbatim by delegation, + // desktop goes through AWT (the spike's Q5 clipboard PASS used exactly + // this). Re-swap to LocalClipboard + ClipEntry when the stack moves to + // Compose 1.8 (recorded for M5+). + val clipboard: ClipboardManager = LocalClipboardManager.current // v0.3.6.0: use the enum helper so RECOVERY_EXPORT shares the // EXPORT chrome (policy check, Generate/Copy, Confirm field). val isExport = mode.isExport @@ -178,8 +187,10 @@ fun PassphraseDialog( Icon(Icons.Filled.Refresh, contentDescription = "Generate") } IconButton(onClick = { - copyToClipboard(context, passphrase) - copied = true + if (passphrase.isNotEmpty()) { + clipboard.setText(AnnotatedString(passphrase)) + copied = true + } }) { Icon(Icons.Filled.ContentCopy, contentDescription = "Copy") } @@ -269,10 +280,4 @@ enum class PassphraseDialogMode { * password-policy check). Import variants skip those because * an existing passphrase may predate the current policy. */ val isExport: Boolean get() = this == EXPORT || this == RECOVERY_EXPORT -} - -private fun copyToClipboard(context: Context, value: String) { - if (value.isEmpty()) return - val cm = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - cm.setPrimaryClip(ClipData.newPlainText("Incido backup passphrase", value)) } \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/ReleaseNotesDialog.kt b/composeApp/src/commonMain/kotlin/org/incido/compose/ui/settings/ReleaseNotesDialog.kt similarity index 100% rename from composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/ReleaseNotesDialog.kt rename to composeApp/src/commonMain/kotlin/org/incido/compose/ui/settings/ReleaseNotesDialog.kt diff --git a/composeApp/src/jvmMain/kotlin/org/incido/compose/data/backup/PassphraseRandom.jvm.kt b/composeApp/src/jvmMain/kotlin/org/incido/compose/data/backup/PassphraseRandom.jvm.kt new file mode 100644 index 0000000..83e8ab3 --- /dev/null +++ b/composeApp/src/jvmMain/kotlin/org/incido/compose/data/backup/PassphraseRandom.jvm.kt @@ -0,0 +1,14 @@ +package org.incido.compose.data.backup + +import java.security.SecureRandom + +/** + * M4.4a seam for [PassphraseGenerator] — identical two-liner actual on + * both targets (both targets ARE the JVM; commonMain just cannot spell + * `java.security`). Behaviour (CSPRNG backing, draw distribution) is + * exactly the pre-M4 `SecureRandom()` field it replaces. + */ + +private val secureRandom = SecureRandom() + +internal actual fun secureRandomInt(bound: Int): Int = secureRandom.nextInt(bound) \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 70e06df..84b22c5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -45,6 +45,7 @@ composeBom = { module = "androidx.compose:compose-bom", version.ref = "composeBo androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidxActivityCompose" } androidx-lifecycle-viewmodel = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel", version = "2.8.4" } androidx-lifecycle-viewmodel-compose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version = "2.8.4" } +androidx-lifecycle-runtime-compose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose", version = "2.8.4" } androidx-lifecycle-runtime = { module = "org.jetbrains.androidx.lifecycle:lifecycle-runtime", version = "2.8.4" } androidx-lifecycle-process = { module = "androidx.lifecycle:lifecycle-process", version = "2.8.4" } androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidxNavigationCompose" }