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.
This commit is contained in:
1 parent
31408172df
commit
bdb3d7157d
8 files changed
+74
-18
No files matched your search
@@ -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
|
||||
|
||||
+14
@@ -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)
|
||||
+11
-5
@@ -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
|
||||
File renamed without changes.
+18
-13
@@ -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")
|
||||
}
|
||||
@@ -270,9 +281,3 @@ enum class PassphraseDialogMode {
|
||||
* 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))
|
||||
}
|
||||
File renamed without changes.
@@ -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)
|
||||
@@ -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" }
|
||||
|
||||
Reference in new issue
Block a user