Skip to content

Commit 3300e6b

Browse files
committed
feat: Show error about no installation device found at the beginning
1 parent ba159a3 commit 3300e6b

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/main/kotlin/app/revanced/cli/command/PatchCommand.kt

+27-7
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,32 @@ internal object PatchCommand : Runnable {
245245
keyStoreFilePath ?: outputFilePath.parentFile
246246
.resolve("${outputFilePath.nameWithoutExtension}.keystore")
247247

248+
val installer = if (deviceSerial != null) {
249+
try {
250+
if (mount) {
251+
AdbRootInstaller(deviceSerial)
252+
} else {
253+
AdbInstaller(deviceSerial)
254+
}
255+
} catch (e: DeviceNotFoundException) {
256+
if (deviceSerial!!.isNotEmpty()) {
257+
logger.severe(
258+
"Device with serial $deviceSerial not found to install to. " +
259+
"Ensure the device is connected and the serial is correct when using the --install option.",
260+
)
261+
} else {
262+
logger.severe(
263+
"No device has been found to install to. " +
264+
"Ensure a device is connected when using the --install option.",
265+
)
266+
}
267+
268+
return
269+
}
270+
} else {
271+
null
272+
}
273+
248274
// endregion
249275

250276
// region Load patches
@@ -332,13 +358,7 @@ internal object PatchCommand : Runnable {
332358
val deviceSerial = it.ifEmpty { null }
333359

334360
runBlocking {
335-
val result = if (mount) {
336-
AdbRootInstaller(deviceSerial)
337-
} else {
338-
AdbInstaller(deviceSerial)
339-
}.install(Installer.Apk(outputFilePath, packageName))
340-
341-
when (result) {
361+
when (val result = installer!!.install(Installer.Apk(outputFilePath, packageName))) {
342362
RootInstallerResult.FAILURE -> logger.severe("Failed to mount the patched APK file")
343363
is AdbInstallerResult.Failure -> logger.severe(result.exception.toString())
344364
else -> logger.info("Installed the patched APK file")

0 commit comments

Comments
 (0)