@@ -57,14 +57,12 @@ class DescopeFlowCoordinator(val webView: WebView) {
57
57
internal var listener: DescopeFlowView .Listener ? = null
58
58
internal var state: DescopeFlowView .State = Initial
59
59
60
- private lateinit var flow: DescopeFlow
60
+ private var flow: DescopeFlow ? = null
61
61
private val handler: Handler = Handler (Looper .getMainLooper())
62
- private val globalSdk: DescopeSdk ?
63
- get() = if (Descope .isInitialized) Descope .sdk else null
64
62
private val sdk: DescopeSdk ?
65
- get() = if (this ::flow .isInitialized) flow .sdk ? : globalSdk else globalSdk
63
+ get() = flow?.sdk ? : if (Descope .isInitialized) Descope .sdk else null
66
64
private val logger: DescopeLogger ?
67
- get() = sdk?.client? .config? .logger
65
+ get() = sdk?.client.config.logger
68
66
private var currentFlowUrl: Uri ? = null
69
67
private var alreadySetUp = false
70
68
@@ -154,13 +152,13 @@ class DescopeFlowCoordinator(val webView: WebView) {
154
152
155
153
is NativePayload .OAuthWeb -> {
156
154
logger?.log(Info , " Launching custom tab for web-based oauth" )
157
- launchCustomTab(webView.context, nativePayload.startUrl, flow.presentation?.createCustomTabsIntent(webView.context))
155
+ launchCustomTab(webView.context, nativePayload.startUrl, flow? .presentation?.createCustomTabsIntent(webView.context))
158
156
return @launch
159
157
}
160
158
161
159
is NativePayload .Sso -> {
162
160
logger?.log(Info , " Launching custom tab for sso" )
163
- launchCustomTab(webView.context, nativePayload.startUrl, flow.presentation?.createCustomTabsIntent(webView.context))
161
+ launchCustomTab(webView.context, nativePayload.startUrl, flow? .presentation?.createCustomTabsIntent(webView.context))
164
162
return @launch
165
163
}
166
164
@@ -232,7 +230,7 @@ class DescopeFlowCoordinator(val webView: WebView) {
232
230
DoNothing -> true
233
231
OpenBrowser -> {
234
232
try {
235
- launchCustomTab(webView.context, uri, flow.presentation?.createCustomTabsIntent(webView.context))
233
+ launchCustomTab(webView.context, uri, flow? .presentation?.createCustomTabsIntent(webView.context))
236
234
} catch (e: DescopeException ) {
237
235
logger?.log(Error , " Failed to open URL in browser" , e)
238
236
}
@@ -260,10 +258,10 @@ class DescopeFlowCoordinator(val webView: WebView) {
260
258
evaluateJavascript(
261
259
setupScript(
262
260
origin = origin,
263
- oauthNativeProvider = flow.oauthNativeProvider?.name ? : " " ,
264
- oauthRedirect = pickRedirectUrl(flow.oauthRedirect, flow.oauthRedirectCustomScheme, useCustomSchemeFallback),
265
- ssoRedirect = pickRedirectUrl(flow.ssoRedirect, flow.ssoRedirectCustomScheme, useCustomSchemeFallback),
266
- magicLinkRedirect = flow.magicLinkRedirect ? : " " ,
261
+ oauthNativeProvider = flow? .oauthNativeProvider?.name ? : " " ,
262
+ oauthRedirect = pickRedirectUrl(flow? .oauthRedirect, flow? .oauthRedirectCustomScheme, useCustomSchemeFallback),
263
+ ssoRedirect = pickRedirectUrl(flow? .ssoRedirect, flow? .ssoRedirectCustomScheme, useCustomSchemeFallback),
264
+ magicLinkRedirect = flow? .magicLinkRedirect ? : " " ,
267
265
isWebAuthnSupported = isWebAuthnSupported,
268
266
)
269
267
) {}
@@ -333,7 +331,10 @@ document.head.appendChild(element)
333
331
}
334
332
335
333
internal fun resumeFromDeepLink (deepLink : Uri ) {
336
- if (! this ::flow.isInitialized) throw DescopeException .flowFailed.with (desc = " `resumeFromDeepLink` cannot be called before `startFlow`" )
334
+ if (flow == null ) {
335
+ logger?.log(Error , " resumeFromDeepLink cannot be called before startFlow" )
336
+ return
337
+ }
337
338
activityHelper.closeCustomTab(webView.context)
338
339
val response = JSONObject ().apply { put(" url" , deepLink.toString()) }
339
340
val type = if (deepLink.queryParameterNames.contains(" t" )) " magicLink" else " oauthWeb"
@@ -345,7 +346,7 @@ document.head.appendChild(element)
345
346
private fun executeHooks (event : Event ) {
346
347
val hooks = mutableListOf<DescopeFlowHook >().apply {
347
348
addAll(DescopeFlowHook .defaults)
348
- if ( this @DescopeFlowCoordinator:: flow.isInitialized) addAll(flow .hooks)
349
+ flow?. let { addAll(it .hooks) }
349
350
}
350
351
hooks.filter { it.events.contains(event) }
351
352
.forEach { it.execute(event, this ) }
0 commit comments