Commit 9d5efea6 authored by topjohnwu's avatar topjohnwu

Remove ManagerJson

Everything is now Magisk
parent 658d74e0
package com.topjohnwu.magisk.core package com.topjohnwu.magisk.core
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import androidx.work.* import androidx.work.*
import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.data.repository.NetworkService
import com.topjohnwu.magisk.view.Notifications import com.topjohnwu.magisk.view.Notifications
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
import org.koin.core.inject import org.koin.core.inject
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
...@@ -18,20 +16,15 @@ class UpdateCheckService(context: Context, workerParams: WorkerParameters) ...@@ -18,20 +16,15 @@ class UpdateCheckService(context: Context, workerParams: WorkerParameters)
private val svc: NetworkService by inject() private val svc: NetworkService by inject()
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
// Make sure shell initializer was ran return svc.fetchUpdate()?.run {
withContext(Dispatchers.IO) { if (Info.env.isActive && BuildConfig.VERSION_CODE < magisk.versionCode)
Shell.getShell()
}
return svc.fetchUpdate()?.let {
if (BuildConfig.VERSION_CODE < it.app.versionCode)
Notifications.managerUpdate(applicationContext) Notifications.managerUpdate(applicationContext)
else if (Info.env.isActive && Info.env.magiskVersionCode < it.magisk.versionCode)
Notifications.magiskUpdate(applicationContext)
Result.success() Result.success()
} ?: Result.failure() } ?: Result.failure()
} }
companion object { companion object {
@SuppressLint("NewApi")
fun schedule(context: Context) { fun schedule(context: Context) {
if (Config.checkUpdate) { if (Config.checkUpdate) {
val constraints = Constraints.Builder() val constraints = Constraints.Builder()
......
...@@ -5,7 +5,7 @@ import android.net.Uri ...@@ -5,7 +5,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.ManagerJson import com.topjohnwu.magisk.core.model.MagiskJson
import com.topjohnwu.magisk.core.model.StubJson import com.topjohnwu.magisk.core.model.StubJson
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
...@@ -39,12 +39,12 @@ sealed class Subject : Parcelable { ...@@ -39,12 +39,12 @@ sealed class Subject : Parcelable {
@Parcelize @Parcelize
class Manager( class Manager(
private val app: ManagerJson = Info.remote.app, private val json: MagiskJson = Info.remote.magisk,
val stub: StubJson = Info.remote.stub val stub: StubJson = Info.remote.stub
) : Subject() { ) : Subject() {
override val action get() = Action.Download override val action get() = Action.Download
override val title: String get() = "MagiskManager-${app.version}(${app.versionCode})" override val title: String get() = "Magisk-${json.version}(${json.versionCode})"
override val url: String get() = app.link override val url: String get() = json.link
@IgnoredOnParcel @IgnoredOnParcel
override val file by lazy { override val file by lazy {
......
...@@ -6,11 +6,11 @@ import kotlinx.parcelize.Parcelize ...@@ -6,11 +6,11 @@ import kotlinx.parcelize.Parcelize
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class UpdateInfo( data class UpdateInfo(
val app: ManagerJson = ManagerJson(),
val magisk: MagiskJson = MagiskJson(), val magisk: MagiskJson = MagiskJson(),
val stub: StubJson = StubJson() val stub: StubJson = StubJson()
) )
@Parcelize
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class MagiskJson( data class MagiskJson(
val version: String = "", val version: String = "",
...@@ -18,15 +18,6 @@ data class MagiskJson( ...@@ -18,15 +18,6 @@ data class MagiskJson(
val link: String = "", val link: String = "",
val note: String = "", val note: String = "",
val md5: String = "" val md5: String = ""
)
@Parcelize
@JsonClass(generateAdapter = true)
data class ManagerJson(
val version: String = "",
val versionCode: Int = -1,
val link: String = "",
val note: String = ""
) : Parcelable ) : Parcelable
@Parcelize @Parcelize
......
...@@ -148,7 +148,7 @@ object HideAPK { ...@@ -148,7 +148,7 @@ object HideAPK {
} else { } else {
File(context.cacheDir, "manager.apk").also { apk -> File(context.cacheDir, "manager.apk").also { apk ->
try { try {
svc.fetchFile(Info.remote.app.link).byteStream().writeTo(apk) svc.fetchFile(Info.remote.magisk.link).byteStream().writeTo(apk)
} catch (e: IOException) { } catch (e: IOException) {
Timber.e(e) Timber.e(e)
return false return false
......
...@@ -8,7 +8,9 @@ import com.topjohnwu.magisk.core.Config.Value.DEFAULT_CHANNEL ...@@ -8,7 +8,9 @@ import com.topjohnwu.magisk.core.Config.Value.DEFAULT_CHANNEL
import com.topjohnwu.magisk.core.Config.Value.STABLE_CHANNEL import com.topjohnwu.magisk.core.Config.Value.STABLE_CHANNEL
import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.model.* import com.topjohnwu.magisk.core.model.MagiskJson
import com.topjohnwu.magisk.core.model.StubJson
import com.topjohnwu.magisk.core.model.UpdateInfo
import com.topjohnwu.magisk.data.network.* import com.topjohnwu.magisk.data.network.*
import retrofit2.HttpException import retrofit2.HttpException
import timber.log.Timber import timber.log.Timber
...@@ -47,14 +49,12 @@ class NetworkService( ...@@ -47,14 +49,12 @@ class NetworkService(
val info = jsd.fetchCanaryUpdate(sha) val info = jsd.fetchCanaryUpdate(sha)
fun genCDNUrl(name: String) = "${Const.Url.JS_DELIVR_URL}${MAGISK_FILES}@${sha}/${name}" fun genCDNUrl(name: String) = "${Const.Url.JS_DELIVR_URL}${MAGISK_FILES}@${sha}/${name}"
fun ManagerJson.updateCopy() = copy(link = genCDNUrl(link), note = genCDNUrl(note))
fun MagiskJson.updateCopy() = copy(link = genCDNUrl(link), note = genCDNUrl(note)) fun MagiskJson.updateCopy() = copy(link = genCDNUrl(link), note = genCDNUrl(note))
fun StubJson.updateCopy() = copy(link = genCDNUrl(link)) fun StubJson.updateCopy() = copy(link = genCDNUrl(link))
return info.copy( return info.copy(
app = info.app.updateCopy(),
magisk = info.magisk.updateCopy(), magisk = info.magisk.updateCopy(),
stub = info.stub.updateCopy(), stub = info.stub.updateCopy()
) )
} }
......
...@@ -14,20 +14,22 @@ import com.topjohnwu.magisk.core.Const ...@@ -14,20 +14,22 @@ import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.base.ActivityResultCallback import com.topjohnwu.magisk.core.base.ActivityResultCallback
import com.topjohnwu.magisk.core.base.BaseActivity import com.topjohnwu.magisk.core.base.BaseActivity
import com.topjohnwu.magisk.core.model.module.OnlineModule import com.topjohnwu.magisk.core.model.module.OnlineModule
import com.topjohnwu.magisk.events.dialog.MarkDownDialog
import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.view.MarkDownWindow import com.topjohnwu.magisk.view.MagiskDialog
import com.topjohnwu.magisk.view.Shortcuts import com.topjohnwu.magisk.view.Shortcuts
import kotlinx.coroutines.launch
class ViewActionEvent(val action: BaseActivity.() -> Unit) : ViewEvent(), ActivityExecutor { class ViewActionEvent(val action: BaseActivity.() -> Unit) : ViewEvent(), ActivityExecutor {
override fun invoke(activity: BaseUIActivity<*, *>) = action(activity) override fun invoke(activity: BaseUIActivity<*, *>) = action(activity)
} }
class OpenReadmeEvent(val item: OnlineModule) : ViewEventWithScope(), ContextExecutor { class OpenReadmeEvent(private val item: OnlineModule) : MarkDownDialog() {
override fun invoke(context: Context) { override suspend fun getMarkdownText() = item.notes()
scope.launch { override fun build(dialog: MagiskDialog) {
MarkDownWindow.show(context, null, item::notes) super.build(dialog)
} dialog.applyButton(MagiskDialog.ButtonType.NEGATIVE) {
titleRes = android.R.string.cancel
}.cancellable(true)
} }
} }
......
...@@ -4,37 +4,26 @@ import com.topjohnwu.magisk.R ...@@ -4,37 +4,26 @@ import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.core.download.DownloadService
import com.topjohnwu.magisk.core.download.Subject import com.topjohnwu.magisk.core.download.Subject
import com.topjohnwu.magisk.ktx.res import com.topjohnwu.magisk.data.repository.NetworkService
import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.magisk.view.MagiskDialog
import com.topjohnwu.magisk.view.MarkDownWindow import org.koin.core.inject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
class ManagerInstallDialog : DialogEvent() { class ManagerInstallDialog : MarkDownDialog() {
override fun build(dialog: MagiskDialog) { private val svc: NetworkService by inject()
with(dialog) {
val subject = Subject.Manager()
applyTitle(R.string.repo_install_title.res(R.string.app_name.res())) override suspend fun getMarkdownText() = svc.fetchString(Info.remote.magisk.note)
applyMessage(R.string.repo_install_msg.res(subject.title))
override fun build(dialog: MagiskDialog) {
super.build(dialog)
with(dialog) {
setCancelable(true) setCancelable(true)
applyButton(MagiskDialog.ButtonType.POSITIVE) { applyButton(MagiskDialog.ButtonType.POSITIVE) {
titleRes = R.string.install titleRes = R.string.install
onClick { DownloadService.start(context, subject) } onClick { DownloadService.start(context, Subject.Manager()) }
} }
if (Info.remote.app.note.isEmpty()) return
applyButton(MagiskDialog.ButtonType.NEGATIVE) { applyButton(MagiskDialog.ButtonType.NEGATIVE) {
titleRes = R.string.app_changelog titleRes = android.R.string.cancel
onClick {
GlobalScope.launch(Dispatchers.Main.immediate) {
MarkDownWindow.show(context, null, Info.remote.app.note)
}
}
} }
} }
} }
......
package com.topjohnwu.magisk.events.dialog
import android.view.LayoutInflater
import android.widget.TextView
import androidx.annotation.CallSuper
import androidx.lifecycle.lifecycleScope
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.core.base.BaseActivity
import com.topjohnwu.magisk.ktx.coroutineScope
import com.topjohnwu.magisk.view.MagiskDialog
import io.noties.markwon.Markwon
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.koin.core.KoinComponent
import org.koin.core.inject
import timber.log.Timber
import kotlin.coroutines.cancellation.CancellationException
abstract class MarkDownDialog : DialogEvent(), KoinComponent {
private val markwon: Markwon by inject()
abstract suspend fun getMarkdownText(): String
@CallSuper
override fun build(dialog: MagiskDialog) {
with(dialog) {
val view = LayoutInflater.from(context).inflate(R.layout.markdown_window_md2, null)
applyView(view)
(ownerActivity as BaseActivity).lifecycleScope.launch {
val tv = view.findViewById<TextView>(R.id.md_txt)
tv.coroutineScope = CoroutineScope(coroutineContext)
withContext(Dispatchers.IO) {
try {
markwon.setMarkdown(tv, getMarkdownText())
} catch (e: Exception) {
if (e is CancellationException)
throw e
Timber.e(e)
tv.post { tv.setText(R.string.download_file_error) }
}
}
}
}
}
}
...@@ -313,10 +313,8 @@ class ModuleViewModel( ...@@ -313,10 +313,8 @@ class ModuleViewModel(
fun infoPressed(item: ModuleItem) { fun infoPressed(item: ModuleItem) {
item.repo?.also { item.repo?.also {
if (isConnected.get()) if (isConnected.get()) OpenReadmeEvent(it).publish()
OpenReadmeEvent(it).publish() else SnackbarEvent(R.string.no_connection).publish()
else
SnackbarEvent(R.string.no_connection).publish()
} ?: return } ?: return
} }
} }
...@@ -109,7 +109,7 @@ object Restore : BaseSettingsItem.Blank() { ...@@ -109,7 +109,7 @@ object Restore : BaseSettingsItem.Blank() {
override val title = R.string.settings_restore_manager_title.asTransitive() override val title = R.string.settings_restore_manager_title.asTransitive()
override val description = R.string.settings_restore_manager_summary.asTransitive() override val description = R.string.settings_restore_manager_summary.asTransitive()
override fun refresh() { override fun refresh() {
isEnabled = Info.remote.app.versionCode > 0 isEnabled = Info.remote.magisk.versionCode > 0
} }
} }
......
package com.topjohnwu.magisk.view
import android.content.Context
import android.view.LayoutInflater
import android.widget.TextView
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.data.repository.NetworkService
import com.topjohnwu.magisk.ktx.coroutineScope
import io.noties.markwon.Markwon
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.koin.core.KoinComponent
import org.koin.core.inject
import timber.log.Timber
import kotlin.coroutines.coroutineContext
object MarkDownWindow : KoinComponent {
private val svc: NetworkService by inject()
private val markwon: Markwon by inject()
suspend fun show(activity: Context, title: String?, url: String) {
show(activity, title) {
svc.fetchString(url)
}
}
suspend fun show(activity: Context, title: String?, input: suspend () -> String) {
val view = LayoutInflater.from(activity).inflate(R.layout.markdown_window_md2, null)
MagiskDialog(activity)
.applyTitle(title ?: "")
.applyView(view)
.applyButton(MagiskDialog.ButtonType.NEGATIVE) {
titleRes = android.R.string.cancel
}
.reveal()
val tv = view.findViewById<TextView>(R.id.md_txt)
tv.coroutineScope = CoroutineScope(coroutineContext)
withContext(Dispatchers.IO) {
try {
markwon.setMarkdown(tv, input())
} catch (e: Exception) {
if (e is CancellationException)
throw e
Timber.e(e)
tv.post { tv.setText(R.string.download_file_error) }
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment