mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-05-30 21:40:13 +02:00
Directly use MagiskJson
This commit is contained in:
parent
adbea7e313
commit
4c89c7e2b3
@ -3,7 +3,6 @@ package com.topjohnwu.magisk.dialog
|
|||||||
import com.topjohnwu.magisk.core.AppContext
|
import com.topjohnwu.magisk.core.AppContext
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.R
|
import com.topjohnwu.magisk.core.R
|
||||||
import com.topjohnwu.magisk.core.di.ServiceLocator
|
|
||||||
import com.topjohnwu.magisk.core.download.DownloadEngine
|
import com.topjohnwu.magisk.core.download.DownloadEngine
|
||||||
import com.topjohnwu.magisk.core.download.Subject
|
import com.topjohnwu.magisk.core.download.Subject
|
||||||
import com.topjohnwu.magisk.view.MagiskDialog
|
import com.topjohnwu.magisk.view.MagiskDialog
|
||||||
@ -12,9 +11,9 @@ import java.io.File
|
|||||||
class ManagerInstallDialog : MarkDownDialog() {
|
class ManagerInstallDialog : MarkDownDialog() {
|
||||||
|
|
||||||
override suspend fun getMarkdownText(): String {
|
override suspend fun getMarkdownText(): String {
|
||||||
val text = Info.remote.magisk.note
|
val text = Info.update.note
|
||||||
// Cache the changelog
|
// Cache the changelog
|
||||||
File(AppContext.cacheDir, "${Info.remote.magisk.versionCode}.md").writeText(text)
|
File(AppContext.cacheDir, "${Info.update.versionCode}.md").writeText(text)
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,16 +91,15 @@ class HomeViewModel(
|
|||||||
|
|
||||||
override suspend fun doLoadWork() {
|
override suspend fun doLoadWork() {
|
||||||
appState = State.LOADING
|
appState = State.LOADING
|
||||||
Info.getRemote(svc)?.apply {
|
Info.fetchUpdate(svc)?.apply {
|
||||||
appState = when {
|
appState = when {
|
||||||
BuildConfig.APP_VERSION_CODE < magisk.versionCode -> State.OUTDATED
|
BuildConfig.APP_VERSION_CODE < versionCode -> State.OUTDATED
|
||||||
else -> State.UP_TO_DATE
|
else -> State.UP_TO_DATE
|
||||||
}
|
}
|
||||||
|
|
||||||
val isDebug = Config.updateChannel == Config.Value.DEBUG_CHANNEL
|
val isDebug = Config.updateChannel == Config.Value.DEBUG_CHANNEL
|
||||||
managerRemoteVersion =
|
managerRemoteVersion =
|
||||||
("${magisk.version} (${magisk.versionCode})" +
|
("$version (${versionCode})" + if (isDebug) " (D)" else "").asText()
|
||||||
if (isDebug) " (D)" else "").asText()
|
|
||||||
} ?: run {
|
} ?: run {
|
||||||
appState = State.INVALID
|
appState = State.INVALID
|
||||||
managerRemoteVersion = CoreR.string.not_available.asText()
|
managerRemoteVersion = CoreR.string.not_available.asText()
|
||||||
|
@ -74,7 +74,7 @@ class InstallViewModel(svc: NetworkService, markwon: Markwon) : BaseViewModel()
|
|||||||
val text = when {
|
val text = when {
|
||||||
file.exists() -> file.readText()
|
file.exists() -> file.readText()
|
||||||
else -> {
|
else -> {
|
||||||
val str = if (Const.APP_IS_CANARY) Info.remote.magisk.note
|
val str = if (Const.APP_IS_CANARY) Info.update.note
|
||||||
else svc.fetchString(Const.Url.CHANGELOG_URL)
|
else svc.fetchString(Const.Url.CHANGELOG_URL)
|
||||||
file.writeText(str)
|
file.writeText(str)
|
||||||
str
|
str
|
||||||
|
@ -147,7 +147,7 @@ object UpdateChannel : BaseSettingsItem.Selector() {
|
|||||||
get() = Config.updateChannel
|
get() = Config.updateChannel
|
||||||
set(value) {
|
set(value) {
|
||||||
Config.updateChannel = value
|
Config.updateChannel = value
|
||||||
Info.remote = Info.EMPTY_REMOTE
|
Info.resetUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
override val title = CoreR.string.settings_update_channel_title.asText()
|
override val title = CoreR.string.settings_update_channel_title.asText()
|
||||||
@ -169,7 +169,7 @@ object UpdateChannelUrl : BaseSettingsItem.Input() {
|
|||||||
get() = Config.customChannelUrl
|
get() = Config.customChannelUrl
|
||||||
set(value) {
|
set(value) {
|
||||||
Config.customChannelUrl = value
|
Config.customChannelUrl = value
|
||||||
Info.remote = Info.EMPTY_REMOTE
|
Info.resetUpdate()
|
||||||
notifyPropertyChanged(BR.description)
|
notifyPropertyChanged(BR.description)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,12 +19,18 @@ object Info {
|
|||||||
|
|
||||||
var stub: StubApk.Data? = null
|
var stub: StubApk.Data? = null
|
||||||
|
|
||||||
val EMPTY_REMOTE = UpdateInfo()
|
private val EMPTY_UPDATE = UpdateInfo()
|
||||||
var remote = EMPTY_REMOTE
|
var update = EMPTY_UPDATE
|
||||||
suspend fun getRemote(svc: NetworkService): UpdateInfo? {
|
private set
|
||||||
return if (remote === EMPTY_REMOTE) {
|
|
||||||
svc.fetchUpdate()?.apply { remote = this }
|
suspend fun fetchUpdate(svc: NetworkService): UpdateInfo? {
|
||||||
} else remote
|
return if (update === EMPTY_UPDATE) {
|
||||||
|
svc.fetchUpdate()?.apply { update = this }
|
||||||
|
} else update
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resetUpdate() {
|
||||||
|
update = EMPTY_UPDATE
|
||||||
}
|
}
|
||||||
|
|
||||||
var isRooted = false
|
var isRooted = false
|
||||||
|
@ -75,9 +75,8 @@ class JobService : BaseJobService() {
|
|||||||
|
|
||||||
private fun checkUpdate(params: JobParameters): Boolean {
|
private fun checkUpdate(params: JobParameters): Boolean {
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
ServiceLocator.networkService.fetchUpdate()?.let {
|
Info.fetchUpdate(ServiceLocator.networkService)?.let {
|
||||||
Info.remote = it
|
if (Info.env.isActive && BuildConfig.APP_VERSION_CODE < it.versionCode)
|
||||||
if (Info.env.isActive && BuildConfig.APP_VERSION_CODE < it.magisk.versionCode)
|
|
||||||
Notifications.updateAvailable()
|
Notifications.updateAvailable()
|
||||||
jobFinished(params, false)
|
jobFinished(params, false)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package com.topjohnwu.magisk.core.data
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.core.model.ModuleJson
|
import com.topjohnwu.magisk.core.model.ModuleJson
|
||||||
import com.topjohnwu.magisk.core.model.Release
|
import com.topjohnwu.magisk.core.model.Release
|
||||||
import com.topjohnwu.magisk.core.model.UpdateInfo
|
import com.topjohnwu.magisk.core.model.UpdateJson
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
@ -25,7 +25,7 @@ interface RawUrl {
|
|||||||
suspend fun fetchModuleJson(@Url url: String): ModuleJson
|
suspend fun fetchModuleJson(@Url url: String): ModuleJson
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
suspend fun fetchUpdateJson(@Url url: String): UpdateInfo
|
suspend fun fetchUpdateJson(@Url url: String): UpdateJson
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GithubApiServices {
|
interface GithubApiServices {
|
||||||
|
@ -8,7 +8,7 @@ import android.net.Uri
|
|||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.model.MagiskJson
|
import com.topjohnwu.magisk.core.model.UpdateInfo
|
||||||
import com.topjohnwu.magisk.core.model.module.OnlineModule
|
import com.topjohnwu.magisk.core.model.module.OnlineModule
|
||||||
import com.topjohnwu.magisk.core.utils.MediaStoreUtils
|
import com.topjohnwu.magisk.core.utils.MediaStoreUtils
|
||||||
import com.topjohnwu.magisk.view.Notifications
|
import com.topjohnwu.magisk.view.Notifications
|
||||||
@ -38,7 +38,7 @@ abstract class Subject : Parcelable {
|
|||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
class App(
|
class App(
|
||||||
private val json: MagiskJson = Info.remote.magisk,
|
private val json: UpdateInfo = Info.update,
|
||||||
override val notifyId: Int = Notifications.nextId()
|
override val notifyId: Int = Notifications.nextId()
|
||||||
) : Subject() {
|
) : Subject() {
|
||||||
override val title: String get() = "Magisk-${json.version}(${json.versionCode})"
|
override val title: String get() = "Magisk-${json.version}(${json.versionCode})"
|
||||||
|
@ -11,13 +11,13 @@ import java.time.LocalDateTime
|
|||||||
import java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME
|
import java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class UpdateInfo(
|
class UpdateJson(
|
||||||
val magisk: MagiskJson = MagiskJson(),
|
val magisk: UpdateInfo = UpdateInfo(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class MagiskJson(
|
data class UpdateInfo(
|
||||||
val version: String = "",
|
val version: String = "",
|
||||||
val versionCode: Int = -1,
|
val versionCode: Int = -1,
|
||||||
val link: String = "",
|
val link: String = "",
|
||||||
|
@ -10,7 +10,6 @@ import com.topjohnwu.magisk.core.Config.Value.STABLE_CHANNEL
|
|||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.data.GithubApiServices
|
import com.topjohnwu.magisk.core.data.GithubApiServices
|
||||||
import com.topjohnwu.magisk.core.data.RawUrl
|
import com.topjohnwu.magisk.core.data.RawUrl
|
||||||
import com.topjohnwu.magisk.core.model.MagiskJson
|
|
||||||
import com.topjohnwu.magisk.core.model.Release
|
import com.topjohnwu.magisk.core.model.Release
|
||||||
import com.topjohnwu.magisk.core.model.UpdateInfo
|
import com.topjohnwu.magisk.core.model.UpdateInfo
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
@ -31,7 +30,7 @@ class NetworkService(
|
|||||||
CUSTOM_CHANNEL -> fetchCustomUpdate(Config.customChannelUrl)
|
CUSTOM_CHANNEL -> fetchCustomUpdate(Config.customChannelUrl)
|
||||||
else -> throw IllegalArgumentException()
|
else -> throw IllegalArgumentException()
|
||||||
}
|
}
|
||||||
if (info.magisk.versionCode < Info.env.versionCode &&
|
if (info.versionCode < Info.env.versionCode &&
|
||||||
Config.updateChannel == DEFAULT_CHANNEL) {
|
Config.updateChannel == DEFAULT_CHANNEL) {
|
||||||
Config.updateChannel = BETA_CHANNEL
|
Config.updateChannel = BETA_CHANNEL
|
||||||
info = fetchBetaUpdate()
|
info = fetchBetaUpdate()
|
||||||
@ -59,23 +58,21 @@ class NetworkService(
|
|||||||
private fun Release.asPublicInfo(): UpdateInfo {
|
private fun Release.asPublicInfo(): UpdateInfo {
|
||||||
val version = tag.drop(1)
|
val version = tag.drop(1)
|
||||||
val date = createdTime.format(DateTimeFormatter.ofPattern("yyyy.M.d"))
|
val date = createdTime.format(DateTimeFormatter.ofPattern("yyyy.M.d"))
|
||||||
val info = MagiskJson(
|
return UpdateInfo(
|
||||||
version = version,
|
version = version,
|
||||||
versionCode = (version.toFloat() * 1000).toInt(),
|
versionCode = (version.toFloat() * 1000).toInt(),
|
||||||
link = assets[0].url,
|
link = assets[0].url,
|
||||||
note = "## $date $name\n\n$body"
|
note = "## $date $name\n\n$body"
|
||||||
)
|
)
|
||||||
return UpdateInfo(info)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Release.asCanaryInfo(assetSelector: String): UpdateInfo {
|
private fun Release.asCanaryInfo(assetSelector: String): UpdateInfo {
|
||||||
val info = MagiskJson(
|
return UpdateInfo(
|
||||||
version = name.substring(8, 16),
|
version = name.substring(8, 16),
|
||||||
versionCode = tag.drop(7).toInt(),
|
versionCode = tag.drop(7).toInt(),
|
||||||
link = assets.find { it.name == assetSelector }!!.url,
|
link = assets.find { it.name == assetSelector }!!.url,
|
||||||
note = "## $name\n\n$body"
|
note = "## $name\n\n$body"
|
||||||
)
|
)
|
||||||
return UpdateInfo(info)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun fetchStableUpdate() = api.fetchLatestRelease().asPublicInfo()
|
private suspend fun fetchStableUpdate() = api.fetchLatestRelease().asPublicInfo()
|
||||||
@ -90,7 +87,7 @@ class NetworkService(
|
|||||||
|
|
||||||
private suspend fun fetchCustomUpdate(url: String): UpdateInfo {
|
private suspend fun fetchCustomUpdate(url: String): UpdateInfo {
|
||||||
val info = raw.fetchUpdateJson(url).magisk
|
val info = raw.fetchUpdateJson(url).magisk
|
||||||
return UpdateInfo(info.let { it.copy(note = raw.fetchString(it.note)) })
|
return info.let { it.copy(note = raw.fetchString(it.note)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <T> safe(factory: () -> T): T? {
|
private inline fun <T> safe(factory: () -> T): T? {
|
||||||
|
@ -62,7 +62,7 @@ class NetworkObserver(context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun postValue(b: Boolean) {
|
private fun postValue(b: Boolean) {
|
||||||
Info.remote = Info.EMPTY_REMOTE
|
Info.resetUpdate()
|
||||||
Info.isConnected.postValue(b)
|
Info.isConnected.postValue(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user