Add action.sh for user to manually trigger modules' functionality from app

This commit is contained in:
LoveSy
2024-09-01 23:08:38 +08:00
committed by John Wu
parent a9f8c20703
commit fbebb6ac10
13 changed files with 363 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ data class LocalModule(
val isRiru: Boolean get() = (id == "riru-core") || riruFolder.exists()
val isZygisk: Boolean get() = zygiskFolder.exists()
val zygiskUnloaded: Boolean get() = unloaded.exists()
val hasAction: Boolean;
var enable: Boolean
get() = !disableFile.exists()
@@ -100,6 +101,8 @@ data class LocalModule(
if (name.isEmpty()) {
name = id
}
hasAction = RootUtils.fs.getFile(path, "action.sh").exists()
}
suspend fun fetch(): Boolean {

View File

@@ -0,0 +1,42 @@
package com.topjohnwu.magisk.core.tasks
import android.net.Uri
import androidx.core.net.toFile
import com.topjohnwu.magisk.core.AppContext
import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.ktx.writeTo
import com.topjohnwu.magisk.core.utils.MediaStoreUtils.displayName
import com.topjohnwu.magisk.core.utils.MediaStoreUtils.inputStream
import com.topjohnwu.magisk.core.utils.unzip
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.io.File
import java.io.FileNotFoundException
import java.io.IOException
open class RunAction(
private val module: String,
private val console: MutableList<String>,
private val logs: MutableList<String>
) {
@Throws(IOException::class)
private suspend fun run(): Boolean {
return Shell.cmd("run_action \'$module\'").to(console, logs).exec().isSuccess
}
open suspend fun exec() = withContext(Dispatchers.IO) {
try {
if (!run()) {
console.add("! Run action failed")
false
} else {
true
}
} catch (e: IOException) {
Timber.e(e)
false
}
}
}

View File

@@ -109,6 +109,7 @@
<string name="reboot_safe_mode">Safe mode</string>
<string name="module_version_author">%1$s by %2$s</string>
<string name="module_state_remove">Remove</string>
<string name="module_action">Action</string>
<string name="module_state_restore">Restore</string>
<string name="module_action_install_external">Install from storage</string>
<string name="update_available">Update Available</string>
@@ -211,8 +212,10 @@
<string name="repo_install_title">Install %1$s %2$s(%3$d)</string>
<string name="download">Download</string>
<string name="reboot">Reboot</string>
<string name="close">Close</string>
<string name="release_notes">Release notes</string>
<string name="flashing">Flashing…</string>
<string name="running">Running...</string>
<string name="done">Done!</string>
<string name="failure">Failed!</string>
<string name="hide_app_title">Hiding the Magisk app…</string>