Fixed modules screen not offering reboot when local modules change

This commit is contained in:
Viktor De Pasquale 2020-03-29 11:55:37 +02:00 committed by John Wu
parent ea855837df
commit 6e14a727b1
3 changed files with 15 additions and 11 deletions

View File

@ -18,12 +18,13 @@ class Module(path: String) : BaseModule() {
private val updateFile = SuFile(path, "update") private val updateFile = SuFile(path, "update")
private val ruleFile = SuFile(path, "sepolicy.rule") private val ruleFile = SuFile(path, "sepolicy.rule")
val updated: Boolean = updateFile.exists() val updated: Boolean get() = updateFile.exists()
var enable: Boolean = !disableFile.exists() var enable: Boolean
get() = !disableFile.exists()
set(enable) { set(enable) {
val dir = "$PERSIST/$id" val dir = "$PERSIST/$id"
field = if (enable) { if (enable) {
Shell.su("mkdir -p $dir", "cp -af $ruleFile $dir").submit() Shell.su("mkdir -p $dir", "cp -af $ruleFile $dir").submit()
disableFile.delete() disableFile.delete()
} else { } else {
@ -32,9 +33,10 @@ class Module(path: String) : BaseModule() {
} }
} }
var remove: Boolean = removeFile.exists() var remove: Boolean
get() = removeFile.exists()
set(remove) { set(remove) {
field = if (remove) { if (remove) {
Shell.su("rm -rf $PERSIST/$id").submit() Shell.su("rm -rf $PERSIST/$id").submit()
removeFile.createNewFile() removeFile.createNewFile()
} else { } else {
@ -67,7 +69,7 @@ class Module(path: String) : BaseModule() {
val moduleList = mutableListOf<Module>() val moduleList = mutableListOf<Module>()
val path = SuFile(Const.MAGISK_PATH) val path = SuFile(Const.MAGISK_PATH)
val modules = val modules =
path.listFiles { _, name -> name != "lost+found" && name != ".core" }.orEmpty() path.listFiles { _, name -> name != "lost+found" && name != ".core" }.orEmpty()
for (file in modules) { for (file in modules) {
if (file.isFile) continue if (file.isFile) continue
val module = Module(Const.MAGISK_PATH + "/" + file.name) val module = Module(Const.MAGISK_PATH + "/" + file.name)

View File

@ -110,22 +110,23 @@ class ModuleItem(val item: Module) : ObservableItem<ModuleItem>(), Observable {
} }
@get:Bindable @get:Bindable
var isEnabled = item.enable var isEnabled
get() = item.enable
set(value) { set(value) {
field = value
item.enable = value item.enable = value
notifyChange(BR.enabled) notifyChange(BR.enabled)
} }
@get:Bindable @get:Bindable
var isRemoved = item.remove var isRemoved
get() = item.remove
set(value) { set(value) {
field = value
item.remove = value item.remove = value
notifyChange(BR.removed) notifyChange(BR.removed)
} }
val isUpdated get() = item.updated val isUpdated get() = item.updated
val isModified get() = isRemoved || item.updated val isModified get() = isRemoved || isUpdated
fun toggle() { fun toggle() {
isEnabled = !isEnabled isEnabled = !isEnabled

View File

@ -193,6 +193,7 @@ class ModuleViewModel(
.doOnSuccess { .doOnSuccess {
addInstalledEmptyMessage() addInstalledEmptyMessage()
addUpdatableEmptyMessage() addUpdatableEmptyMessage()
updateActiveState()
} }
.ignoreElement()!! .ignoreElement()!!