mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
feat: 支持 checkUpdateUrl 字段
This commit is contained in:
parent
c0011a9e7e
commit
ffbb2d4950
6
app/src/main/kotlin/li/songe/gkd/data/SubsVersion.kt
Normal file
6
app/src/main/kotlin/li/songe/gkd/data/SubsVersion.kt
Normal file
|
@ -0,0 +1,6 @@
|
|||
package li.songe.gkd.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class SubsVersion(val id: Long, val version: Int)
|
|
@ -4,7 +4,16 @@ import blue.endless.jankson.Jankson
|
|||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.*
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.JsonNull
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.boolean
|
||||
import kotlinx.serialization.json.int
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.long
|
||||
import li.songe.gkd.util.json
|
||||
import li.songe.selector.Selector
|
||||
|
||||
|
@ -17,6 +26,7 @@ data class SubscriptionRaw(
|
|||
val author: String? = null,
|
||||
val updateUrl: String? = null,
|
||||
val supportUri: String? = null,
|
||||
val checkUpdateUrl: String? = null,
|
||||
val apps: List<AppRaw> = emptyList(),
|
||||
) {
|
||||
|
||||
|
@ -63,7 +73,7 @@ data class SubscriptionRaw(
|
|||
override val resetMatch: String?,
|
||||
override val activityIds: List<String>?,
|
||||
override val excludeActivityIds: List<String>?,
|
||||
val rules: List<RuleRaw> = emptyList(),
|
||||
val rules: List<RuleRaw>,
|
||||
val snapshotUrls: List<String>?,
|
||||
val exampleUrls: List<String>?,
|
||||
) : CommonProps {
|
||||
|
@ -291,6 +301,7 @@ data class SubscriptionRaw(
|
|||
author = getString(rootJson, "author"),
|
||||
updateUrl = getString(rootJson, "updateUrl"),
|
||||
supportUri = getString(rootJson, "supportUri"),
|
||||
checkUpdateUrl = getString(rootJson, "checkUpdateUrl"),
|
||||
apps = rootJson["apps"]?.jsonArray?.mapIndexed { index, jsonElement ->
|
||||
jsonToAppRaw(
|
||||
jsonElement.jsonObject, index
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.view.accessibility.AccessibilityEvent
|
|||
import com.blankj.utilcode.util.LogUtils
|
||||
import com.blankj.utilcode.util.ServiceUtils
|
||||
import com.blankj.utilcode.util.ToastUtils
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -33,6 +34,7 @@ import li.songe.gkd.data.ActionResult
|
|||
import li.songe.gkd.data.GkdAction
|
||||
import li.songe.gkd.data.NodeInfo
|
||||
import li.songe.gkd.data.RpcError
|
||||
import li.songe.gkd.data.SubsVersion
|
||||
import li.songe.gkd.data.SubscriptionRaw
|
||||
import li.songe.gkd.data.getActionFc
|
||||
import li.songe.gkd.db.DbSet
|
||||
|
@ -55,6 +57,8 @@ class GkdAbService : CompositionAbService({
|
|||
|
||||
val context = this as GkdAbService
|
||||
|
||||
context.resources
|
||||
|
||||
val scope = useScope()
|
||||
|
||||
service = context
|
||||
|
@ -235,13 +239,25 @@ class GkdAbService : CompositionAbService({
|
|||
subsItemsFlow.value.forEach { subsItem ->
|
||||
if (subsItem.updateUrl == null) return@forEach
|
||||
try {
|
||||
val oldSubsRaw = subsIdToRawFlow.value[subsItem.id]
|
||||
if (oldSubsRaw?.checkUpdateUrl != null) {
|
||||
try {
|
||||
val subsVersion =
|
||||
client.get(oldSubsRaw.checkUpdateUrl).body<SubsVersion>()
|
||||
LogUtils.d("快速检测更新成功", subsVersion)
|
||||
if (subsVersion.id == oldSubsRaw.id && subsVersion.version <= oldSubsRaw.version) {
|
||||
return@forEach
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
LogUtils.d("快速检测更新失败", subsItem, e)
|
||||
}
|
||||
}
|
||||
val newSubsRaw = SubscriptionRaw.parse(
|
||||
client.get(subsItem.updateUrl).bodyAsText()
|
||||
)
|
||||
if (newSubsRaw.id != subsItem.id) {
|
||||
return@forEach
|
||||
}
|
||||
val oldSubsRaw = subsIdToRawFlow.value[subsItem.id]
|
||||
if (oldSubsRaw != null && newSubsRaw.version <= oldSubsRaw.version) {
|
||||
return@forEach
|
||||
}
|
||||
|
@ -258,7 +274,7 @@ class GkdAbService : CompositionAbService({
|
|||
LogUtils.d("更新磁盘订阅文件:${newSubsRaw.name}")
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
LogUtils.d("更新失败", e)
|
||||
LogUtils.d("检测更新失败", e)
|
||||
}
|
||||
}
|
||||
lastUpdateSubsTime = System.currentTimeMillis()
|
||||
|
|
|
@ -3,8 +3,10 @@ package li.songe.gkd.ui
|
|||
import android.webkit.URLUtil
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.blankj.utilcode.util.LogUtils
|
||||
import com.blankj.utilcode.util.ToastUtils
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -13,6 +15,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import li.songe.gkd.data.SubsItem
|
||||
import li.songe.gkd.data.SubsVersion
|
||||
import li.songe.gkd.data.SubscriptionRaw
|
||||
import li.songe.gkd.db.DbSet
|
||||
import li.songe.gkd.util.client
|
||||
|
@ -97,6 +100,18 @@ class SubsManageVm @Inject constructor() : ViewModel() {
|
|||
if (oldItem.updateUrl == null) return@mapNotNull null
|
||||
val oldSubsRaw = subsIdToRawFlow.value[oldItem.id]
|
||||
try {
|
||||
if (oldSubsRaw?.checkUpdateUrl != null) {
|
||||
try {
|
||||
val subsVersion =
|
||||
client.get(oldSubsRaw.checkUpdateUrl).body<SubsVersion>()
|
||||
LogUtils.d("快速检测更新成功", subsVersion)
|
||||
if (subsVersion.id == oldSubsRaw.id && subsVersion.version <= oldSubsRaw.version) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
LogUtils.d("快速检测更新失败", oldItem, e)
|
||||
}
|
||||
}
|
||||
val newSubsRaw = SubscriptionRaw.parse(
|
||||
client.get(oldItem.updateUrl).bodyAsText()
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user