diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9c75396..7f93a22 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -32,12 +32,19 @@
+ android:label="@string/app_name"
+ android:launchMode="singleTask"
+ android:alwaysRetainTaskState="true">
-
+
+
+
+
+
+
diff --git a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt
index 3072c52..3677f70 100644
--- a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt
+++ b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt
@@ -34,7 +34,6 @@ import org.komputing.khex.extensions.toHexString
import org.komputing.khex.extensions.toNoPrefixHexString
import org.komputing.khex.model.HexString
import org.walletconnect.Session
-import org.walletconnect.Session.Config.Companion.fromWCUri
import org.walletconnect.impls.FileWCSessionStore
import org.walletconnect.impls.MoshiPayloadAdapter
import org.walletconnect.impls.OkHttpTransport
@@ -212,12 +211,12 @@ class WalletConnect(var sessionStatusListener : Session.Callback, var bip32Path:
uiAction = this::nop
}
- fun connect(uri: String) {
+ fun connect(uri: Session.FullyQualifiedConfig) {
scope.launch(Dispatchers.IO) {
session?.kill()
session = WCSession(
- fromWCUri(uri).toFullyQualifiedConfig(),
+ uri,
MoshiPayloadAdapter(moshi),
sessionStore,
OkHttpTransport.Builder(okHttpClient, moshi),
diff --git a/app/src/main/java/im/status/keycard/connect/ui/MainActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/MainActivity.kt
index 1e84ecd..09d84d5 100644
--- a/app/src/main/java/im/status/keycard/connect/ui/MainActivity.kt
+++ b/app/src/main/java/im/status/keycard/connect/ui/MainActivity.kt
@@ -16,6 +16,7 @@ import im.status.keycard.connect.Registry
import im.status.keycard.connect.card.*
import im.status.keycard.connect.data.*
import org.walletconnect.Session
+import org.walletconnect.Session.Config.Companion.fromWCUri
import kotlin.reflect.KClass
class MainActivity : AppCompatActivity(), ScriptListener, Session.Callback {
@@ -32,6 +33,8 @@ class MainActivity : AppCompatActivity(), ScriptListener, Session.Callback {
setContentView(viewSwitcher)
Registry.init(this, this, this)
Registry.scriptExecutor.defaultScript = cardCheckupScript()
+
+ handleIntent(intent)
}
override fun onResume() {
@@ -44,6 +47,21 @@ class MainActivity : AppCompatActivity(), ScriptListener, Session.Callback {
Registry.nfcAdapter.disableReaderMode(this)
}
+ override fun onNewIntent(intent: Intent?) {
+ super.onNewIntent(intent)
+ handleIntent(intent)
+ }
+
+ private fun handleIntent(intent: Intent?) {
+ if (intent?.action == Intent.ACTION_VIEW) {
+ handleWCURI(intent.data?.toString())
+ }
+ }
+
+ override fun onBackPressed() {
+ moveTaskToBack(false)
+ }
+
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
@@ -137,10 +155,15 @@ class MainActivity : AppCompatActivity(), ScriptListener, Session.Callback {
private fun qrCodeScanned(resultCode: Int, data: Intent?) {
if (resultCode != Activity.RESULT_OK || data == null) return
- val uri: String? = data.getStringExtra(Intents.Scan.RESULT)
+ handleWCURI(data.getStringExtra(Intents.Scan.RESULT))
- if (uri != null && uri.startsWith("wc:")) {
- Registry.walletConnect.connect(uri)
+ }
+
+ private fun handleWCURI(uri: String?) {
+ if (uri != null) {
+ try {
+ Registry.walletConnect.connect(fromWCUri(uri).toFullyQualifiedConfig())
+ } catch (e: Exception) {}
}
}