android: Start wallet no longer looks like a no-op while Cuprate launches
Tapping Start held the SQLCipher mutex for the whole in-process Node::launch and blocked the UniFFI tokio worker, so wallet_status stayed off with no error. Drop the store lock until creds are needed, spawn_blocking the sync start, and show that Start is in flight. The APK still runs Cuprate testnet only; this does not add mainnet or prune.
This commit is contained in:
parent
2df10124ef
commit
0acf89a0b4
7 changed files with 103 additions and 34 deletions
|
|
@ -40,6 +40,7 @@ import uniffi.onionwire_sdk.WalletChildStatus
|
|||
import uniffi.onionwire_sdk.Wire
|
||||
import uniffi.onionwire_sdk.decodeInvite
|
||||
import java.io.File
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
sealed interface Phase {
|
||||
/** No identity unlocked. Nothing Tor-related is running. */
|
||||
|
|
@ -618,6 +619,14 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
|||
private val _walletChildError = MutableStateFlow<String?>(null)
|
||||
val walletChildError: StateFlow<String?> = _walletChildError.asStateFlow()
|
||||
|
||||
/**
|
||||
* Start is in flight. Core status stays `off` until Cuprate/`monerod` answers,
|
||||
* so the screen must not wait on that snapshot to show that the tap landed.
|
||||
*/
|
||||
private val startInFlight = AtomicBoolean(false)
|
||||
private val _walletChildStarting = MutableStateFlow(false)
|
||||
val walletChildStarting: StateFlow<Boolean> = _walletChildStarting.asStateFlow()
|
||||
|
||||
/** The stored chain source + binary settings, for prefilling the editor. */
|
||||
private val _chainSource = MutableStateFlow<ChainConfig?>(null)
|
||||
val chainSource: StateFlow<ChainConfig?> = _chainSource.asStateFlow()
|
||||
|
|
@ -795,25 +804,28 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
|||
fun chainFreeBytes(): Long? = ChainStorage.freeBytes(home)
|
||||
|
||||
/**
|
||||
* Spawns the child (and its daemon/SOCKS siblings) and returns what the core
|
||||
* reached.
|
||||
*
|
||||
* The returned state is `connecting` at best on the first call — the wallet
|
||||
* RPC does not answer the instant the process exists — and that is reported
|
||||
* as-is. The spawn is synchronous inside the node and a `.onion` source
|
||||
* waits up to 20s for its SOCKS listener, so this never runs on the main
|
||||
* thread.
|
||||
* Kick off start on [viewModelScope] so leaving the composition does not
|
||||
* cancel Cuprate launch. Returns immediately; watch [walletChildStarting]
|
||||
* and [walletChildError]. Core status stays `off` until the node answers.
|
||||
*/
|
||||
suspend fun startWalletChild(): Result<WalletChildStatus> {
|
||||
fun startWalletChild() {
|
||||
if (!startInFlight.compareAndSet(false, true)) return
|
||||
_walletChildStarting.value = true
|
||||
_walletChildError.value = null
|
||||
val started = withContext(Dispatchers.IO) {
|
||||
runCatching { requireWire().startWalletChild() }
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val started = withContext(Dispatchers.IO) {
|
||||
runCatching { requireWire().startWalletChild() }
|
||||
}
|
||||
started.fold(
|
||||
onSuccess = { _walletChild.value = it },
|
||||
onFailure = { _walletChildError.value = it.message ?: it.toString() },
|
||||
)
|
||||
} finally {
|
||||
startInFlight.set(false)
|
||||
_walletChildStarting.value = false
|
||||
}
|
||||
}
|
||||
started.fold(
|
||||
onSuccess = { _walletChild.value = it },
|
||||
onFailure = { _walletChildError.value = it.message ?: it.toString() },
|
||||
)
|
||||
return started
|
||||
}
|
||||
|
||||
/** Stops the child and its siblings. Idempotent in the core. */
|
||||
|
|
|
|||
|
|
@ -303,6 +303,9 @@ const val ONION_NEEDS_ARTI_NOTICE: String =
|
|||
/** Shown while the first `wallet_status()` read is still in flight. */
|
||||
const val READING_CHILD_NOTICE: String = "Reading the wallet child status…"
|
||||
|
||||
const val STARTING_CHILD_NOTICE: String =
|
||||
"Start is running. Status stays off until the on-device node answers — that can take a minute, and is not a dead button."
|
||||
|
||||
/**
|
||||
* The caveat the on-device node is offered with, **before** Start.
|
||||
*
|
||||
|
|
@ -388,8 +391,10 @@ fun startBlockedReason(
|
|||
bins: WalletChildBinaryPaths,
|
||||
input: WalletChildInput?,
|
||||
onionDaemon: Boolean = false,
|
||||
starting: Boolean = false,
|
||||
): String? = when {
|
||||
bins.walletRpc == null -> NO_WALLET_RPC_MESSAGE
|
||||
starting -> STARTING_CHILD_NOTICE
|
||||
input == null -> READING_CHILD_NOTICE
|
||||
input.running -> "The wallet child is already running."
|
||||
!input.configured -> "No chain source yet: a wallet child needs a daemon to dial."
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ fun WalletScreen(
|
|||
val friends by vm.friends.collectAsStateWithLifecycle()
|
||||
val child by vm.walletChild.collectAsStateWithLifecycle()
|
||||
val childError by vm.walletChildError.collectAsStateWithLifecycle()
|
||||
val starting by vm.walletChildStarting.collectAsStateWithLifecycle()
|
||||
val chain by vm.chainSource.collectAsStateWithLifecycle()
|
||||
val scope = rememberCoroutineScope()
|
||||
// Resolved once per composition: the native library directory is fixed for
|
||||
|
|
@ -259,7 +260,8 @@ fun WalletScreen(
|
|||
.onFailure { daemonError = it.message ?: it.toString() }
|
||||
}
|
||||
},
|
||||
onStart = { scope.launch { vm.startWalletChild() } },
|
||||
starting = starting,
|
||||
onStart = { vm.startWalletChild() },
|
||||
onStop = { scope.launch { vm.stopWalletChild() } },
|
||||
)
|
||||
|
||||
|
|
@ -616,6 +618,7 @@ private fun WalletChildCard(
|
|||
onSaveDaemon: () -> Unit,
|
||||
onReceiveOnly: () -> Unit,
|
||||
onInProcessNode: () -> Unit,
|
||||
starting: Boolean = false,
|
||||
onStart: () -> Unit,
|
||||
onStop: () -> Unit,
|
||||
) {
|
||||
|
|
@ -626,7 +629,7 @@ private fun WalletChildCard(
|
|||
// read comes back: the warning and the storage line must not wait for the
|
||||
// poller, or the user would press Start having seen neither.
|
||||
val inProcess = input?.chainInProcess == true || chain?.kind == ChainChoice.IN_PROCESS_CUPRATE
|
||||
val startWhy = startBlockedReason(bins, input, onionDaemon)
|
||||
val startWhy = startBlockedReason(bins, input, onionDaemon, starting)
|
||||
?: if (inProcess) chainStorageBlockedReason(nodeFreeBytes) else null
|
||||
val stopWhy = stopBlockedReason(input)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue