Skip to content

Commit 44ed40c

Browse files
committed
💪 [kmp/helper] 提升稳定性,尝试修复dwebview不在主线程启动的问题
1 parent e2bb163 commit 44ed40c

File tree

2 files changed

+10
-5
lines changed
  • next/kmp

2 files changed

+10
-5
lines changed

next/kmp/dwebview/src/iosMain/kotlin/org/dweb_browser/dwebview/engine/DWebDelegate/hookDeeplink.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,22 @@ private fun DWebViewEngine.hookDeeplink(request: NSURLRequest): Boolean {
5757
val scheme = url?.scheme ?: "http"
5858
if (url != null && !isWebUrlScheme(scheme)) {
5959
if (scheme == "dweb") {
60-
lifecycleScope.launch {
61-
remoteMM.nativeFetch(url.absoluteString!!)
60+
return when (val urlStr = url.absoluteString) {
61+
null -> false
62+
else -> {
63+
lifecycleScope.launch {
64+
remoteMM.nativeFetch(urlStr)
65+
}
66+
true
67+
}
6268
}
63-
return true
6469
}
6570

6671
// 无法使用 uiApp.canOpenURL,因为没有在 info.plist 注册特殊scheme,会导致无法打开scheme链接
6772
// 无法使用 uiApp.openURL,因为当前kotlin对接的iOS openURL已经失效,需要自己对接 open 方法
6873
// val uiApp = remoteMM.getUIApplication()
6974
// 必须排除 dweb+https 这类,否则会导致dweb app无法启动
70-
if(url.scheme?.startsWith("dweb+") == false) {
75+
if (scheme.startsWith("dweb+") == false) {
7176
dwebHelper.openURL(url) { res ->
7277
debugDWebView("hookDeeplink openURL -> ", res)
7378
}

next/kmp/helper/src/commonMain/kotlin/org/dweb_browser/helper/coroutineHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public val globalIoScope: CoroutineScope
3838

3939
public expect suspend inline fun <T> withMainContext(crossinline block: suspend () -> T): T
4040
public suspend inline fun <T> withMainContextCommon(crossinline block: suspend () -> T): T {
41-
return withContext(Dispatchers.Main.immediate + mainAsyncExceptionHandler) { block() }
41+
return withContext(mainAsyncExceptionHandler) { block() }
4242
}
4343

4444
public suspend inline fun <T> withIoContext(crossinline block: suspend () -> T): T {

0 commit comments

Comments
 (0)