also looking at this
fix(android): hand the launch link to the page that subscribes for it
#232
17 files
+776
-136
| @@ -44,7 +44,19 @@ class MainActivity : AppCompatActivity() { | ||
| 44 | 44 | |
| 45 | 45 | webView = findViewById(R.id.webview) |
| 46 | 46 | craftBridge = CraftBridge(this, webView, CraftHealthConnect(this, webView)) |
| 47 | handleIncomingDeepLink(intent, dispatch = false) | |
| 47 | // The link that launched the app (#215). Queued until the page's bridge | |
| 48 | // is injected, then dispatched once with `initial: true`, so a page that | |
| 49 | // subscribes rather than calling getInitialURL still hears it. A | |
| 50 | // relaunch from Recents carries the old intent, and was not opened by it. | |
| 51 | // A recreated activity restores what the bridge saved: its intent may | |
| 52 | // be a later warm link that onNewIntent set. | |
| 53 | if (savedInstanceState == null) { | |
| 54 | val launchLink = intent.data?.toString() | |
| 55 | val launchedFromHistory = intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY != 0 | |
| 56 | if (launchLink != null && !launchedFromHistory) craftBridge.receiveDeepLink(launchLink) | |
| 57 | } else { | |
| 58 | craftBridge.restoreDeepLinks(savedInstanceState) | |
| 59 | } | |
| 48 | 60 | if (savedInstanceState == null) handleIncomingShortcut(intent) |
| 49 | 61 | |
| 50 | 62 | setupWebView() |
| @@ -150,12 +162,6 @@ class MainActivity : AppCompatActivity() { | ||
| 150 | 162 | } |
| 151 | 163 | } |
| 152 | 164 | |
| 153 | private fun handleIncomingDeepLink(source: Intent?, dispatch: Boolean) { | |
| 154 | val url = source?.data?.toString() ?: return | |
| 155 | craftBridge.setInitialURL(url) | |
| 156 | if (dispatch) craftBridge.dispatchDeepLink(url) | |
| 157 | } | |
| 158 | ||
| 159 | 165 | private fun handleIncomingShortcut(source: Intent?) { |
| 160 | 166 | source?.getStringExtra(SHORTCUT_TYPE_EXTRA)?.let(craftBridge::dispatchShortcut) |
| 161 | 167 | } |
| @@ -198,10 +204,15 @@ class MainActivity : AppCompatActivity() { | ||
| 198 | 204 | return (uri.scheme == "https" || localDevelopment) && origin in trustedOrigins |
| 199 | 205 | } |
| 200 | 206 | |
| 207 | override fun onSaveInstanceState(outState: Bundle) { | |
| 208 | super.onSaveInstanceState(outState) | |
| 209 | craftBridge.saveDeepLinks(outState) | |
| 210 | } | |
| 211 | ||
| 201 | 212 | override fun onNewIntent(intent: Intent) { |
| 202 | 213 | super.onNewIntent(intent) |
| 203 | 214 | setIntent(intent) |
| 204 | handleIncomingDeepLink(intent, dispatch = true) | |
| 215 | intent.data?.toString()?.let(craftBridge::receiveDeepLink) | |
| 205 | 216 | handleIncomingShortcut(intent) |
| 206 | 217 | } |
| 207 | 218 | |