Skip to content

Commit

Permalink
fix: MiniAppDirectJump save config data
Browse files Browse the repository at this point in the history
Closes #1281
  • Loading branch information
HdShare committed Dec 22, 2024
1 parent 1bb032a commit d04bb07
Showing 1 changed file with 41 additions and 29 deletions.
70 changes: 41 additions & 29 deletions app/src/main/java/top/xunflash/hook/MiniAppDirectJump.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import me.ketal.data.ConfigData
import xyz.nextalone.util.throwOrTrue
import java.io.Serializable
import java.lang.reflect.Array
import java.net.HttpURLConnection
import java.net.URL
Expand All @@ -79,7 +81,7 @@ object MiniAppDirectJump : CommonConfigFunctionHook(targets = arrayOf(CArkAppIte
var packageNames: List<String>,
var regex: String,
var parseShortUrls: Boolean
)
) : Serializable

override val name: String = "小程序/分享卡片跳转APP"
override val valueState: MutableStateFlow<String?> by lazy {
Expand All @@ -92,28 +94,35 @@ object MiniAppDirectJump : CommonConfigFunctionHook(targets = arrayOf(CArkAppIte
showConfigDialog(activity)
}

private var appConfigs = mutableListOf(
AppConfig(
listOf("tv.danmaku.bili", "com.bilibili.app.in", "tv.danmaku.bilibilihd", "com.bilibili.app.blue"),
"""https?:\\?/\\?/((b23\.tv)|([\w.]*bilibili\.com))[^"]*""",
true
),
AppConfig(
listOf("com.xingin.xhs"),
"""(?<="jumpUrl":")https?:\\?/\\?/[^"]*""",
false
),
AppConfig(
listOf("com.coolapk.market"),
"""(?<="jumpUrl":")https?:\\?/\\?/[^"]*""",
false
),
AppConfig(
listOf("com.zhihu.android"),
"""(?<="jumpUrl":")https?:\\?/\\?/[^"]*""",
false
)
)
private val appConfigsData = ConfigData<MutableList<AppConfig>>("MiniAppDirectJump_appConfigs")
private var appConfigs: MutableList<AppConfig>
get() = appConfigsData.getOrDefault(
mutableListOf(
AppConfig(
listOf("tv.danmaku.bili", "com.bilibili.app.in", "tv.danmaku.bilibilihd", "com.bilibili.app.blue"),
"""https?:\\?/\\?/((b23\.tv)|([\w.]*bilibili\.com))[^"]*""",
true
),
AppConfig(
listOf("com.xingin.xhs"),
"""(?<="jumpUrl":")https?:\\?/\\?/[^"]*""",
false
),
AppConfig(
listOf("com.coolapk.market"),
"""(?<="jumpUrl":")https?:\\?/\\?/[^"]*""",
false
),
AppConfig(
listOf("com.zhihu.android"),
"""(?<="jumpUrl":")https?:\\?/\\?/[^"]*""",
false
)
)
)
set(value) {
appConfigsData.value = value
}

@SuppressLint("SetTextI18n")
private fun showConfigDialog(ctx: Context) {
Expand Down Expand Up @@ -161,10 +170,12 @@ object MiniAppDirectJump : CommonConfigFunctionHook(targets = arrayOf(CArkAppIte
hint = "应用包名(英文逗号分隔,优先检查的放在前面)"
textSize = 14f
}
addView(packageNameEdit, LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
))
addView(
packageNameEdit, LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
)

val regexEdit = EditText(ctx).apply {
setText(config?.regex ?: "")
Expand Down Expand Up @@ -229,16 +240,17 @@ object MiniAppDirectJump : CommonConfigFunctionHook(targets = arrayOf(CArkAppIte
valueState.value = if (newEnabled) "已开启" else "禁用"
}

appConfigs.clear()
val newAppConfigs = mutableListOf<AppConfig>()
for (i in 0 until appConfigsContainer.childCount) {
val view = appConfigsContainer.getChildAt(i)
val config = (view.tag as? Any)?.let {
it.javaClass.getDeclaredMethod("getConfig").invoke(it) as? AppConfig
} ?: continue
if (config.packageNames.isNotEmpty() && config.regex.isNotBlank()) {
appConfigs.add(config)
newAppConfigs.add(config)
}
}
appConfigs = newAppConfigs

Toasts.success(ctx, "已保存配置")
}
Expand Down

0 comments on commit d04bb07

Please sign in to comment.