mirror of
https://github.com/ReVanced/revanced-cli.git
synced 2026-01-30 06:31:06 +00:00
refactor!: restructure code
This commit focuses on improving code quality in a couple of places and bumping the dependency to ReVanced Patcher. BREAKING CHANGE: This introduces major changes to how ReVanced CLI is used from the command line.
This commit is contained in:
@@ -2,28 +2,28 @@ package app.revanced.utils.adb
|
||||
|
||||
import se.vidstige.jadb.JadbDevice
|
||||
import se.vidstige.jadb.RemoteFile
|
||||
import se.vidstige.jadb.ShellProcessBuilder
|
||||
import java.io.File
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
internal fun JadbDevice.buildCommand(command: String, su: Boolean = true): ShellProcessBuilder {
|
||||
if (su) {
|
||||
return shellProcessBuilder("su -c \'$command\'")
|
||||
// return the input or output stream, depending on which first returns a value
|
||||
internal fun JadbDevice.run(command: String, su: Boolean = false) = with(this.startCommand(command, su)) {
|
||||
Executors.newFixedThreadPool(2).let { service ->
|
||||
arrayOf(inputStream, errorStream).map { stream ->
|
||||
Callable { stream.bufferedReader().use { it.readLine() } }
|
||||
}.let { tasks -> service.invokeAny(tasks).also { service.shutdown() } }
|
||||
}
|
||||
|
||||
val args = command.split(" ") as ArrayList<String>
|
||||
val cmd = args.removeFirst()
|
||||
|
||||
return shellProcessBuilder(cmd, *args.toTypedArray())
|
||||
}
|
||||
|
||||
internal fun JadbDevice.run(command: String, su: Boolean = true): Int {
|
||||
return this.buildCommand(command, su).start().waitFor()
|
||||
}
|
||||
internal fun JadbDevice.hasSu() =
|
||||
this.startCommand("su -h", false).waitFor() == 0
|
||||
|
||||
internal fun JadbDevice.copy(targetPath: String, file: File) {
|
||||
push(file, RemoteFile(targetPath))
|
||||
}
|
||||
internal fun JadbDevice.copyFile(file: File, targetFile: String) =
|
||||
push(file, RemoteFile(targetFile))
|
||||
|
||||
internal fun JadbDevice.createFile(targetFile: String, content: String) {
|
||||
internal fun JadbDevice.createFile(targetFile: String, content: String) =
|
||||
push(content.byteInputStream(), System.currentTimeMillis(), 644, RemoteFile(targetFile))
|
||||
}
|
||||
|
||||
|
||||
private fun JadbDevice.startCommand(command: String, su: Boolean) =
|
||||
shellProcessBuilder(if (su) "su -c '$command'" else command).start()
|
||||
Reference in New Issue
Block a user