mirror of
https://github.com/openflocon/Flocon.git
synced 2026-05-05 18:43:18 +00:00
feat: [DEVICES] being able to target one spceific device with adb (#110)
Co-authored-by: Florent Champigny <florent@bere.al>
This commit is contained in:
parent
0321da0c4a
commit
e9cb50dbd8
9 changed files with 68 additions and 21 deletions
|
|
@ -2,7 +2,11 @@ package io.github.openflocon.flocondesktop.common
|
|||
|
||||
import io.github.openflocon.domain.common.Either
|
||||
|
||||
actual fun localExecuteAdbCommand(adbPath: String, command: String): Either<Throwable, String> {
|
||||
actual fun localExecuteAdbCommand(
|
||||
adbPath: String,
|
||||
command: String,
|
||||
deviceSerial: String?,
|
||||
): Either<Throwable, String> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package io.github.openflocon.flocondesktop.adb
|
||||
|
||||
import io.github.openflocon.domain.adb.AdbCommandTargetDomainModel
|
||||
import io.github.openflocon.domain.adb.repository.AdbRepository
|
||||
import io.github.openflocon.domain.common.Either
|
||||
import io.github.openflocon.flocondesktop.common.askSerialToAllDevices
|
||||
|
|
@ -24,8 +25,18 @@ class AdbRepositoryImpl : AdbRepository {
|
|||
// TODO be able to pass a serial
|
||||
override fun executeAdbCommand(
|
||||
adbPath: String,
|
||||
target: AdbCommandTargetDomainModel,
|
||||
command: String,
|
||||
): Either<Throwable, String> = localExecuteAdbCommand(adbPath = adbPath, command = command)
|
||||
): Either<Throwable, String> {
|
||||
return localExecuteAdbCommand(
|
||||
adbPath = adbPath,
|
||||
command = command,
|
||||
deviceSerial = when(target) {
|
||||
is AdbCommandTargetDomainModel.Device -> getAdbSerial(target.deviceId)
|
||||
is AdbCommandTargetDomainModel.AllDevices -> null
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
override fun executeAdbAskSerialToAllDevices(
|
||||
adbPath: String,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@ import io.github.openflocon.domain.common.Either
|
|||
|
||||
expect fun localFindAdbPath(): String?
|
||||
|
||||
expect fun localExecuteAdbCommand(adbPath: String, command: String): Either<Throwable, String>
|
||||
expect fun localExecuteAdbCommand(
|
||||
adbPath: String,
|
||||
command: String,
|
||||
deviceSerial: String?,
|
||||
): Either<Throwable, String>
|
||||
|
||||
expect fun askSerialToAllDevices(adbPath: String, command: String, serialVariableName: String): Either<Throwable, String>
|
||||
|
|
|
|||
|
|
@ -55,20 +55,28 @@ actual fun localFindAdbPath(): String? {
|
|||
return null
|
||||
}
|
||||
|
||||
actual fun localExecuteAdbCommand(adbPath: String, command: String): Either<Throwable, String> = try {
|
||||
val devices = listConnectedDevices(adbPath)
|
||||
if (devices.isEmpty() || devices.size == 1) {
|
||||
singleDeviceExecuteSystemCommand(adbPath = adbPath, command = command)
|
||||
actual fun localExecuteAdbCommand(
|
||||
adbPath: String,
|
||||
command: String,
|
||||
deviceSerial: String?,
|
||||
): Either<Throwable, String> = try {
|
||||
if(deviceSerial != null) {
|
||||
singleDeviceExecuteSystemCommand(adbPath = "$adbPath -s $deviceSerial", command = command)
|
||||
} else {
|
||||
devices.map { serial ->
|
||||
singleDeviceExecuteSystemCommand(adbPath = "$adbPath -s $serial", command = command)
|
||||
}.let {
|
||||
it.forEach {
|
||||
// return a failure if there's on in the list
|
||||
if (it is Failure)
|
||||
return it
|
||||
val devices = listConnectedDevices(adbPath)
|
||||
if (devices.isEmpty() || devices.size == 1) {
|
||||
singleDeviceExecuteSystemCommand(adbPath = adbPath, command = command)
|
||||
} else {
|
||||
devices.map { serial ->
|
||||
singleDeviceExecuteSystemCommand(adbPath = "$adbPath -s $serial", command = command)
|
||||
}.let {
|
||||
it.forEach {
|
||||
// return a failure if there's on in the list
|
||||
if (it is Failure)
|
||||
return it
|
||||
}
|
||||
return it.firstOrNull() ?: Success("")
|
||||
}
|
||||
return it.firstOrNull() ?: Success("")
|
||||
}
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue