Skip to content

Commit

Permalink
适配新版检测逻辑
Browse files Browse the repository at this point in the history
Signed-off-by: teble <me@teble.me>
  • Loading branch information
teble committed Jul 12, 2023
1 parent 74f3ab5 commit b568003
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 81 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/app-meta-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ jobs:
if [[ -n $(git status -s) ]]; then
git commit -m "Update app-meta.json"
git push "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" pages:pages
fi
fi
- name: Purge jsdelivr CDN
run: |
for file in $(ls); do
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@pages/${file}"
done
7 changes: 4 additions & 3 deletions app-meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"versionName": "3.0.17-NT",
"versionCode": 23042100,
"updateTime": "2023-04-21 21:00:00"
"versionName": "3.0.18",
"versionCode": 23071217,
"updateTime": "2023-07-12 17:37:25",
"updateLog": "在3.0.17基础上仅适配 NT 版本 QQ(正式版v8.9.63+)"
}
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ val appVerCode: Int by lazy {
val buildNum: String get() = SimpleDateFormat("MMddHH", Locale.ENGLISH).format(Date())
val appVerName: String = "3.0.17-NT"
val updateLog = """
在3.0.17基础上仅适配 NT 版本 QQ(正式版v8.9.63+)
""".trimIndent()

android {
Expand Down Expand Up @@ -264,7 +265,7 @@ androidComponents.onVariants { variant ->
"versionName": "$appVerName",
"versionCode": $appVerCode,
"updateTime": "$formatTime",
"updateLog": "$updateLog"
"updateLog": "${updateLog.replace("\n", "\\n")}"
}
""".trimIndent())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SplashActivityHook : BaseHook() {
}
}.onFailure { LogUtil.e(it, "try lock fail: ") }
}
ConfUnit.versionInfoCache ?: ConfigUtil.checkUpdate(false)
ConfUnit.metaInfoCache ?: ConfigUtil.checkUpdate(false)
autoResetTask(true)
}
handler.sendEmptyMessageDelayed(AUTO_EXEC, 10_000)
Expand All @@ -74,7 +74,7 @@ class SplashActivityHook : BaseHook() {
val context = it.thisObject as Activity
scope.launch {
withContext(Dispatchers.IO) {
if (ConfUnit.versionInfoCache == null
if (ConfUnit.metaInfoCache == null
|| System.currentTimeMillis() - ConfUnit.lastFetchTime > 3 * 60 * 60_000L) {
ConfigUtil.fetchMeta()
}
Expand Down Expand Up @@ -130,17 +130,11 @@ suspend fun Activity.openAppUpdateDialog() {
if (!isInitialized) {
builder = AlertDialog.Builder(this@openAppUpdateDialog, 5).apply {
setTitle("检测到新版本")
val updateList = ConfUnit.versionInfoCache?.updateLog ?: emptyList()
val updateLog = buildList {
updateList.forEach {
if (it.isNotEmpty()) {
add(it)
}
}
}.toTypedArray()
setItems(updateLog, null)
val updateLog = ConfUnit.metaInfoCache?.app?.updateLog ?: ""
val updateLogLines = updateLog.lines().toTypedArray()
setItems(updateLogLines, null)
setNeutralButton("本次更新不再提示") { _, _ ->
ConfUnit.skipUpdateVersion = "${ConfUnit.versionInfoCache?.appVersion}"
ConfUnit.skipUpdateVersion = "${ConfUnit.metaInfoCache?.app?.versionCode}"
}
setNegativeButton("蓝奏云") { _, _ ->
context.startActivity(Intent().apply {
Expand All @@ -161,7 +155,7 @@ suspend fun Activity.openAppUpdateDialog() {
appUpdateDialog = builder!!.create()
}
if (!appUpdateDialog.isShowing && !isFinishing
&& ConfUnit.skipUpdateVersion != "${ConfUnit.versionInfoCache?.appVersion}") {
&& ConfUnit.skipUpdateVersion != "${ConfUnit.metaInfoCache?.app?.versionCode}") {
appUpdateDialog.show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,12 @@ data class MiniProfile(
val nick: String
)

@Serializable
data class VersionInfo(
val appVersion: Int,
val minAppVersion: Int,
val updateLog: List<String>,
val confUrl: String,
val confVersion: Int,
val notice: String,
)

@Serializable
data class AppMeta(
val versionName: String,
val versionCode: Int,
val updateTime: String,
val updateLog: String,
val updateLog: String?,
)

@Serializable
Expand All @@ -67,17 +57,5 @@ data class ConfigMeta(
data class MetaInfo(
val app: AppMeta,
val config: ConfigMeta,
val notice: String,
val notice: String?,
)

@Serializable
data class Result(
val code: Int,
val data: VersionInfo
)

@Serializable
data class PackageData(
val tags: List<String>,
val versions: List<String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@ import cn.hutool.core.io.FileUtil
import cn.hutool.core.util.ReUtil
import com.charleskorn.kaml.Yaml
import me.teble.xposed.autodaily.BuildConfig
import me.teble.xposed.autodaily.config.NOTICE
import me.teble.xposed.autodaily.config.XA_API_URL
import me.teble.xposed.autodaily.hook.base.hostContext
import me.teble.xposed.autodaily.hook.utils.ToastUtil
import me.teble.xposed.autodaily.task.cron.pattent.CronPattern
import me.teble.xposed.autodaily.task.cron.pattent.CronPatternUtil
import me.teble.xposed.autodaily.task.model.MetaInfo
import me.teble.xposed.autodaily.task.model.Result
import me.teble.xposed.autodaily.task.model.Task
import me.teble.xposed.autodaily.task.model.TaskProperties
import me.teble.xposed.autodaily.task.model.VersionInfo
import me.teble.xposed.autodaily.ui.ConfUnit
import me.teble.xposed.autodaily.ui.ConfUnit.lastFetchTime
import me.teble.xposed.autodaily.ui.ConfUnit.metaInfoCache
import me.teble.xposed.autodaily.ui.ConfUnit.versionInfoCache
import me.teble.xposed.autodaily.ui.enable
import me.teble.xposed.autodaily.ui.lastExecTime
import me.teble.xposed.autodaily.ui.nextShouldExecTime
Expand Down Expand Up @@ -250,24 +245,15 @@ object ConfigUtil {
return num
}

fun fetchUpdateInfo(): VersionInfo? {
return try {
val text = "$XA_API_URL$NOTICE".get()
LogUtil.d("getNotice -> $text")
val res: Result = text.parse()
versionInfoCache = res.data
lastFetchTime = System.currentTimeMillis()
return res.data
} catch (e: Exception) {
LogUtil.e(e, "拉取公告失败:")
null
}
}

fun fetchMeta(): MetaInfo? {
val text: String? = RepoFileLoader.load(FileEnum.META)
LogUtil.d("fetch meta -> $text")
val meta = runCatching { text?.parse<MetaInfo>() }.getOrNull()
val meta = runCatching {
text?.parse<MetaInfo>()
}.onFailure {
LogUtil.e(it, "解析meta失败:")
}.getOrNull()
LogUtil.d("fetch meta -> $meta")
metaInfoCache = meta
lastFetchTime = System.currentTimeMillis()
return meta
Expand Down
21 changes: 3 additions & 18 deletions app/src/main/java/me/teble/xposed/autodaily/ui/ConfUnit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import me.teble.xposed.autodaily.hook.config.Config.accountConfig
import me.teble.xposed.autodaily.hook.config.Config.xaConfig
import me.teble.xposed.autodaily.task.model.MetaInfo
import me.teble.xposed.autodaily.task.model.Task
import me.teble.xposed.autodaily.task.model.VersionInfo
import me.teble.xposed.autodaily.task.util.Const.BLOCK_UPDATE_ONE_DAY
import me.teble.xposed.autodaily.task.util.Const.BLOCK_UPDATE_VERSION
import me.teble.xposed.autodaily.task.util.Const.ENABLE
Expand All @@ -28,34 +27,20 @@ import me.teble.xposed.autodaily.task.util.Const.SHOW_TASK_TOAST
import me.teble.xposed.autodaily.task.util.Const.TASK_EXCEPTION_COUNT
import me.teble.xposed.autodaily.task.util.Const.TASK_EXEC_STATUS
import me.teble.xposed.autodaily.task.util.Const.USED_THREAD_POOL
import me.teble.xposed.autodaily.task.util.Const.VERSION_INFO_CACHE
import me.teble.xposed.autodaily.utils.parse
import me.teble.xposed.autodaily.utils.toJsonString

object ConfUnit {
val needUpdate: Boolean get() {
versionInfoCache?.let {
if (BuildConfig.VERSION_CODE < it.appVersion) {
metaInfoCache?.let {
if (BuildConfig.VERSION_CODE < it.app.versionCode) {
return true
}
}
return false
}

// -------------------------------------------------- //
var versionInfoCache: VersionInfo?
get() {
val str = xaConfig.getString(VERSION_INFO_CACHE, "")
return runCatching {
if (str.isNotEmpty()) {
return str.parse()
}
return null
}.getOrNull()
}
set(value) {
xaConfig.putString(VERSION_INFO_CACHE, value.toJsonString())
}
// -------------------------------------------------- //\
var metaInfoCache: MetaInfo?
get() {
val str = xaConfig.getString(META_INFO_CACHE, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fun MainLayout(navController: NavHostController) {
if (res) {
showUpdateDialog.value = true
updateDialogText.value =
ConfUnit.versionInfoCache?.updateLog?.joinToString("\n") ?: ""
ConfUnit.metaInfoCache?.app?.updateLog ?: ""
}
configVersion = loadSaveConf().version
}
Expand Down

0 comments on commit b568003

Please sign in to comment.