From b2db0212382266ac6def8c9e7348aae2a997162d Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 8 Apr 2026 16:36:44 +0000 Subject: [PATCH] Fix forward-reference compile error in CloudBackupScreen CreateDocument queue Replace the self-referential createDocLauncher.launch() call inside the launcher's own callback with a LaunchedEffect(pendingIndex) pattern. The callback now only advances pendingIndex; the LaunchedEffect reacts to state changes and triggers the next file-save picker launch. Also update richtextUi JitPack hash to f92ef49c9d which has all required submodules available. https://claude.ai/code/session_01MCtBrEDEWfCfzppiGRaKEU --- .../ui/actions/CloudBackupScreen.kt | 30 ++++++++++++------- gradle/libs.versions.toml | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/actions/CloudBackupScreen.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/actions/CloudBackupScreen.kt index ec94bef1..9a473c1e 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/actions/CloudBackupScreen.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/actions/CloudBackupScreen.kt @@ -83,9 +83,10 @@ fun CloudBackupScreen(modifier: Modifier) { // Google Drive sheet state var showGdriveSheet by remember { mutableStateOf(false) } - // Queue for sequential CreateDocument launches (one per account) + // Queue for sequential CreateDocument launches (one per account). + // pendingIndex == -1 means idle; >= 0 means a launch is in progress. var pendingExports by remember { mutableStateOf(emptyList>()) } - var pendingIndex by remember { mutableIntStateOf(0) } + var pendingIndex by remember { mutableIntStateOf(-1) } LaunchedEffect(Unit) { launch(Dispatchers.IO) { @@ -105,7 +106,7 @@ fun CloudBackupScreen(modifier: Modifier) { ) { uri -> val exports = pendingExports val idx = pendingIndex - if (uri != null && idx < exports.size) { + if (uri != null && idx >= 0 && idx < exports.size) { val (_, ncryptsec) = exports[idx] Amber.instance.applicationIOScope.launch(Dispatchers.IO) { context.contentResolver.openOutputStream(uri)?.use { stream -> @@ -115,20 +116,30 @@ fun CloudBackupScreen(modifier: Modifier) { } val next = idx + 1 if (next < exports.size) { + // Advance the index; LaunchedEffect below will trigger the next picker launch pendingIndex = next - createDocLauncher.launch("${exports[next].first}.ncryptsec") } else { - // All done + // All done — reset and notify + val count = exports.size pendingExports = emptyList() - pendingIndex = 0 + pendingIndex = -1 Toast.makeText( context, - context.getString(R.string.cloud_backup_success, "${exports.size} accounts"), + context.getString(R.string.cloud_backup_success, "$count accounts"), Toast.LENGTH_LONG, ).show() } } + // When pendingIndex advances to a valid index, open the next file-save picker. + // This avoids the forward-reference that would arise from calling createDocLauncher + // inside its own initializer lambda. + LaunchedEffect(pendingIndex) { + if (pendingIndex >= 0 && pendingIndex < pendingExports.size) { + createDocLauncher.launch("${pendingExports[pendingIndex].first}.ncryptsec") + } + } + // Restore: pick any .ncryptsec file and import it val filePickerLauncher = rememberLauncherForActivityResult(ActivityResultContracts.GetContent()) { uri -> uri?.let { fileUri -> @@ -575,10 +586,9 @@ fun CloudBackupScreen(modifier: Modifier) { statusText = "" if (pairs.isNotEmpty()) { pendingExports = pairs + // Setting pendingIndex to 0 triggers LaunchedEffect, + // which opens the first file-save picker. pendingIndex = 0 - // Launch the file-save picker for the first account; - // the launcher callback chains the rest automatically. - createDocLauncher.launch("${pairs[0].first}.ncryptsec") } } }.onFailure { e -> diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 11e3c2a4..c36a9140 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ material3 = "1.4.0" nav_version = "2.9.7" quartz = "1.06.3" compose_ui = "1.10.6" -richtextUi = "a02a03a3e9" +richtextUi = "f92ef49c9d" roomKtx = "2.8.4" securityCryptoKtx = "1.1.0" zxingAndroidEmbedded = "4.3.0"