app: use github api to check updates

This commit is contained in:
vvb2060
2025-05-09 09:22:43 +00:00
committed by John Wu
parent a4b8c5e46b
commit 76962f965e
9 changed files with 88 additions and 66 deletions

View File

@@ -14,7 +14,8 @@ class ManagerInstallDialog : MarkDownDialog() {
private val svc get() = ServiceLocator.networkService
override suspend fun getMarkdownText(): String {
val text = svc.fetchString(Info.remote.magisk.note)
val str = Info.remote.magisk.note
val text = if (str.startsWith("http", true)) svc.fetchString(str) else str
// Cache the changelog
AppContext.cacheDir.listFiles { _, name -> name.endsWith(".md") }.orEmpty().forEach {
it.delete()

View File

@@ -71,11 +71,14 @@ class InstallViewModel(svc: NetworkService, markwon: Markwon) : BaseViewModel()
viewModelScope.launch(Dispatchers.IO) {
try {
val file = File(AppContext.cacheDir, "${BuildConfig.APP_VERSION_CODE}.md")
val note = Info.remote.magisk.note
val text = when {
file.exists() -> file.readText()
Const.Url.CHANGELOG_URL.isEmpty() -> ""
Const.APP_IS_CANARY && note.isEmpty() -> ""
Const.APP_IS_CANARY && !note.startsWith("http", true) -> note
else -> {
val str = svc.fetchString(Const.Url.CHANGELOG_URL)
val url = if (Const.APP_IS_CANARY) note else Const.Url.CHANGELOG_URL
val str = svc.fetchString(url)
file.writeText(str)
str
}