Fix module auto install

Fix #8208
This commit is contained in:
topjohnwu 2024-08-20 01:09:25 -07:00
parent 3f061c1a1e
commit 5604074eba
2 changed files with 19 additions and 20 deletions

View File

@ -1,5 +1,6 @@
package com.topjohnwu.magisk.dialog package com.topjohnwu.magisk.dialog
import android.content.Context
import com.topjohnwu.magisk.core.R import com.topjohnwu.magisk.core.R
import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.di.ServiceLocator
import com.topjohnwu.magisk.core.download.DownloadEngine import com.topjohnwu.magisk.core.download.DownloadEngine
@ -7,6 +8,8 @@ import com.topjohnwu.magisk.core.download.Subject
import com.topjohnwu.magisk.core.model.module.OnlineModule import com.topjohnwu.magisk.core.model.module.OnlineModule
import com.topjohnwu.magisk.ui.flash.FlashFragment import com.topjohnwu.magisk.ui.flash.FlashFragment
import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.magisk.view.MagiskDialog
import com.topjohnwu.magisk.view.Notifications
import kotlinx.parcelize.Parcelize
class OnlineModuleInstallDialog(private val item: OnlineModule) : MarkDownDialog() { class OnlineModuleInstallDialog(private val item: OnlineModule) : MarkDownDialog() {
@ -17,14 +20,21 @@ class OnlineModuleInstallDialog(private val item: OnlineModule) : MarkDownDialog
return if (str.length > 1000) str.substring(0, 1000) else str return if (str.length > 1000) str.substring(0, 1000) else str
} }
@Parcelize
class Module(
override val module: OnlineModule,
override val autoLaunch: Boolean,
override val notifyId: Int = Notifications.nextId()
) : Subject.Module() {
override fun pendingIntent(context: Context) = FlashFragment.installIntent(context, file)
}
override fun build(dialog: MagiskDialog) { override fun build(dialog: MagiskDialog) {
super.build(dialog) super.build(dialog)
dialog.apply { dialog.apply {
fun download(install: Boolean) { fun download(install: Boolean) {
val module = Subject.Module(item, install) DownloadEngine.startWithActivity(activity, Module(item, install))
module.piCreator = FlashFragment::installIntent
DownloadEngine.startWithActivity(activity, module)
} }
val title = context.getString(R.string.repo_install_title, val title = context.getString(R.string.repo_install_title,

View File

@ -17,7 +17,7 @@ import kotlinx.parcelize.Parcelize
import java.io.File import java.io.File
import java.util.UUID import java.util.UUID
sealed class Subject : Parcelable { abstract class Subject : Parcelable {
abstract val url: String abstract val url: String
abstract val file: Uri abstract val file: Uri
@ -27,24 +27,13 @@ sealed class Subject : Parcelable {
open fun pendingIntent(context: Context): PendingIntent? = null open fun pendingIntent(context: Context): PendingIntent? = null
@Parcelize abstract class Module : Subject() {
class Module( abstract val module: OnlineModule
private val module: OnlineModule, final override val url: String get() = module.zipUrl
override val autoLaunch: Boolean, final override val title: String get() = module.downloadFilename
override val notifyId: Int = Notifications.nextId() final override val file by lazy {
) : Subject() {
override val url: String get() = module.zipUrl
override val title: String get() = module.downloadFilename
@IgnoredOnParcel
override val file by lazy {
MediaStoreUtils.getFile(title).uri MediaStoreUtils.getFile(title).uri
} }
@IgnoredOnParcel
var piCreator: ((Context, Uri) -> PendingIntent)? = null
override fun pendingIntent(context: Context) = piCreator?.invoke(context, file)
} }
@Parcelize @Parcelize