Skip to content

Commit

Permalink
Fix "Cannot connect to crypto provider"
Browse files Browse the repository at this point in the history
Initialize `openPgpCallback` before `onSwitchAccount()` is called from the class initializer.
  • Loading branch information
schorschii authored May 22, 2023
1 parent 726027f commit 7edbe54
Showing 1 changed file with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ class RecipientPresenter(
private val allRecipients: List<Recipient>
get() = with(recipientMvpView) { toRecipients + ccRecipients + bccRecipients }

private val openPgpCallback = object : OpenPgpApiManagerCallback {
override fun onOpenPgpProviderStatusChanged() {
if (openPgpApiManager.openPgpProviderState == OpenPgpProviderState.UI_REQUIRED) {
recipientMvpView.showErrorOpenPgpUserInteractionRequired()
}
asyncUpdateCryptoStatus()
}

override fun onOpenPgpProviderError(error: OpenPgpProviderError) {
when (error) {
OpenPgpProviderError.ConnectionLost -> openPgpApiManager.refreshConnection()
OpenPgpProviderError.VersionIncompatible -> recipientMvpView.showErrorOpenPgpIncompatible()
OpenPgpProviderError.ConnectionFailed -> recipientMvpView.showErrorOpenPgpConnection()
else -> recipientMvpView.showErrorOpenPgpConnection()
}
}
}

init {
recipientMvpView.setPresenter(this)
recipientMvpView.setLoaderManager(loaderManager)
Expand Down Expand Up @@ -723,25 +741,6 @@ class RecipientPresenter(
}
}

private val openPgpCallback = object : OpenPgpApiManagerCallback {
override fun onOpenPgpProviderStatusChanged() {
if (openPgpApiManager.openPgpProviderState == OpenPgpProviderState.UI_REQUIRED) {
recipientMvpView.showErrorOpenPgpUserInteractionRequired()
}

asyncUpdateCryptoStatus()
}

override fun onOpenPgpProviderError(error: OpenPgpProviderError) {
when (error) {
OpenPgpProviderError.ConnectionLost -> openPgpApiManager.refreshConnection()
OpenPgpProviderError.VersionIncompatible -> recipientMvpView.showErrorOpenPgpIncompatible()
OpenPgpProviderError.ConnectionFailed -> recipientMvpView.showErrorOpenPgpConnection()
else -> recipientMvpView.showErrorOpenPgpConnection()
}
}
}

private fun Array<String>.toAddressArray(): Array<Address> {
return flatMap { addressString ->
Address.parseUnencoded(addressString).toList()
Expand Down

0 comments on commit 7edbe54

Please sign in to comment.