@@ -3,7 +3,6 @@ package org.dweb_browser.browser.jsProcess
33import io.ktor.http.HttpStatusCode
44import io.ktor.http.fullPath
55import kotlinx.coroutines.async
6- import kotlinx.serialization.encodeToString
76import kotlinx.serialization.json.Json
87import org.dweb_browser.browser.BrowserI18nResource
98import org.dweb_browser.browser.jmm.JsMicroModule
@@ -25,6 +24,7 @@ import org.dweb_browser.helper.ImageResource
2524import org.dweb_browser.helper.SafeHashMap
2625import org.dweb_browser.helper.collectIn
2726import org.dweb_browser.helper.encodeURI
27+ import org.dweb_browser.helper.getDebugTags
2828import org.dweb_browser.helper.randomUUID
2929import org.dweb_browser.helper.resolvePath
3030import org.dweb_browser.helper.toJsonElement
@@ -167,8 +167,7 @@ class JsProcessNMM : NativeMicroModule("js.browser.dweb", "Js Process") {
167167 apis.createIpcEndpoint(processId, manifestJson, ids.first).globalId.also {
168168 debugMM(" create-ipc-endpoint-success" , " globalId=$it manifest=$manifestJson " )
169169 }
170- },
171- " /create-ipc" bind PureMethod .GET by defineEmptyResponse {
170+ }, " /create-ipc" bind PureMethod .GET by defineEmptyResponse {
172171 val processToken = request.query(" token" )
173172 val processId = tokenPidMap[processToken] ? : throw ResponseException (
174173 code = HttpStatusCode .NotFound ,
@@ -179,12 +178,9 @@ class JsProcessNMM : NativeMicroModule("js.browser.dweb", "Js Process") {
179178 val manifestJson = request.query(" manifest" )
180179 debugMM(" /create-ipc" ) { " remoteGlobalId=$remoteGlobalId ,manifestJson=$manifestJson " }
181180 apis.createJsIpc(
182- processId,
183- GlobalWebMessageEndpoint .get(remoteGlobalId).port,
184- manifestJson
181+ processId, GlobalWebMessageEndpoint .get(remoteGlobalId).port, manifestJson
185182 ) {}
186- }
187- )
183+ })
188184 }
189185
190186 override suspend fun _shutdown () {
@@ -238,14 +234,25 @@ class JsProcessNMM : NativeMicroModule("js.browser.dweb", "Js Process") {
238234 },
239235 )
240236 }
241-
237+ fun getJsDebugTags (): List <String > {
238+ val allTags = getDebugTags()
239+ // 如果有js特调,那么久返回特调的,否则和native共享同一套配置
240+ val jsOnly = allTags.filter { it.startsWith(" :js:" ) }
241+ return when {
242+ jsOnly.isEmpty() -> allTags
243+ else -> jsOnly.map { tag -> tag.slice(" :js:" .length.. < tag.length) }
244+ }
245+ }
242246 // / TODO env 允许远端传过来扩展
243247 val env = mutableMapOf<String , String >(
244248 // ...your envs
245249 // 这不是是它代码的请求路径,代码请求路径从 import.meta.url 中读取,这里是用来为开发者提供一个 baseURL 而已
246250 " host" to httpDwebServer.startResult.urlInfo.host,
247- // native环境是否启用调试
248- " debug" to debugJsProcess.isEnable.toString(),
251+ // 按需开启输出
252+ " debug" to when {
253+ debugJsProcess.isEnable -> Json .encodeToString(getJsDebugTags())
254+ else -> " []"
255+ },
249256 // jmm的版本信息
250257 " jsMicroModule" to " ${JsMicroModule .VERSION } .${JsMicroModule .PATCH } " ,
251258 // web brands
0 commit comments