diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..bf0826a --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +scrcpy \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 13a8247..dd09283 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,14 +4,16 @@ diff --git a/.idea/runConfigurations/buildPlugin.xml b/.idea/runConfigurations/buildPlugin.xml new file mode 100644 index 0000000..770f5c2 --- /dev/null +++ b/.idea/runConfigurations/buildPlugin.xml @@ -0,0 +1,21 @@ + + + + + + + true + + + \ No newline at end of file diff --git a/.idea/runConfigurations/runIde.xml b/.idea/runConfigurations/runIde.xml new file mode 100644 index 0000000..8ed3271 --- /dev/null +++ b/.idea/runConfigurations/runIde.xml @@ -0,0 +1,21 @@ + + + + + + + true + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 19788a9..4317c84 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { - ext.kotlin_version = '1.4.0' + ext.kotlin_version = '1.4.10' repositories { mavenCentral() @@ -31,17 +31,18 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { } } group "com.codertainment" -version "0.1.2" +version "0.1.3" intellij { pluginName 'Scrcpy Controller' updateSinceUntilBuild false - version 'IU-2020.2.1' + version 'IU-2020.2.3' //intellij.localPath = project.hasProperty("StudioRunPath") ? StudioRunPath : StudioCompilePath } patchPluginXml { changeNotes """ + v0.1.3: Add option to set adb path (use only if scrcpy can't detect ADB Path) (maybe necessary for macOS)
v0.1.2: Really fix shortcut MOD setting not working (this time I've tested it :P)
v0.1.1: Fix Shortcut MOD setting not working
v0.1.0:
diff --git a/src/main/kotlin/com/codertainment/scrcpy/controller/model/ScrcpyProps.kt b/src/main/kotlin/com/codertainment/scrcpy/controller/model/ScrcpyProps.kt index e72c661..bfa6763 100644 --- a/src/main/kotlin/com/codertainment/scrcpy/controller/model/ScrcpyProps.kt +++ b/src/main/kotlin/com/codertainment/scrcpy/controller/model/ScrcpyProps.kt @@ -15,6 +15,7 @@ import java.io.File @State(name = "com.codertainment.scrcpy.controller.model.ScrcpyProps", storages = [Storage("ScrcpyProps.xml")]) data class ScrcpyProps( var scrcpyPath: String? = null, + var adbPath: String? = null, //adb var ip1: Int? = 192, var ip2: Int? = 168, var ip3: Int? = null, var ip4: Int? = null, var port: Int? = 5555, @@ -84,14 +85,7 @@ data class ScrcpyProps( val isIpValid get() = ip1 != null && ip2 != null && ip3 != null && ip4 != null && port != null val ip get() = listOf(ip1, ip2, ip3, ip4).joinToString(".") - fun pathTestCommand() = arrayListOf().apply { - if (scrcpyPath != null) { - add(scrcpyPath + File.separator + "scrcpy") - } else { - add("scrcpy") - } - add("-v") - } + fun adbPath() = adbPath ?: "adb" fun buildCommand(serial: String) = arrayListOf().apply { if (scrcpyPath != null) { diff --git a/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyController.kt b/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyController.kt index 7de9977..dffc95b 100644 --- a/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyController.kt +++ b/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyController.kt @@ -141,7 +141,7 @@ internal class ScrcpyController(private val toolWindow: ToolWindow) : DeviceDete try { selectedDevices.iterator().forEach { if (!commandExecutors.containsKey(it)) { - val cmd = CommandExecutor(props.buildCommand(it)) { exit, msg, fullOp, ioe -> + val cmd = CommandExecutor(props.buildCommand(it), adbPath = props.adbPath) { exit, msg, fullOp, ioe -> exit?.let { _ -> commandExecutors.remove(it) println("Exited: $exit") @@ -380,7 +380,7 @@ internal class ScrcpyController(private val toolWindow: ToolWindow) : DeviceDete toWifi.forEach { serial -> runInBg { try { - CommandExecutor(listOf("adb", "-s", serial, "tcpip", props.port?.toString() ?: "5555")) { exitCode, _, fullOp, _ -> + CommandExecutor(listOf(props.adbPath(), "-s", serial, "tcpip", props.port?.toString() ?: "5555")) { exitCode, _, fullOp, _ -> exitCode?.let { if (it != 0) { Notifier.notify( @@ -391,7 +391,7 @@ internal class ScrcpyController(private val toolWindow: ToolWindow) : DeviceDete ) } else { Thread.sleep(1500) - CommandExecutor(listOf("adb", "-s", serial, "shell", "ip -f inet addr show wlan0")) { exitCode, _, fullOp, _ -> + CommandExecutor(listOf(props.adbPath(), "-s", serial, "shell", "ip -f inet addr show wlan0")) { exitCode, _, fullOp, _ -> exitCode?.let { if (it == 0 && fullOp != null) { val ip = fullOp.split("inet ")[1].split("/")[0] diff --git a/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyControllerSettingsComponent.form b/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyControllerSettingsComponent.form index ba17128..2228596 100644 --- a/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyControllerSettingsComponent.form +++ b/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyControllerSettingsComponent.form @@ -1,9 +1,9 @@
- + - + @@ -32,10 +32,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyControllerSettingsComponent.kt b/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyControllerSettingsComponent.kt index 5069ab4..0d40d04 100644 --- a/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyControllerSettingsComponent.kt +++ b/src/main/kotlin/com/codertainment/scrcpy/controller/ui/ScrcpyControllerSettingsComponent.kt @@ -27,7 +27,9 @@ internal class ScrcpyControllerSettingsComponent { var settingsPanel: JPanel? = null private var scrcpyPath: TextFieldWithBrowseButton? = null + private var adbPath: TextFieldWithBrowseButton? = null private var pathTest: JButton? = null + private var adbTest: JButton? = null private var forceAdbForward: JCheckBox? = null private var noMipmaps: JCheckBox? = null @@ -45,7 +47,13 @@ internal class ScrcpyControllerSettingsComponent { return if (modProps.scrcpyPath == null) null else LocalFileSystem.getInstance().findFileByIoFile(File(modProps.scrcpyPath)) } }) + adbPath?.addBrowseFolderListener(object : TextBrowseFolderListener(FileChooserDescriptor(true, false, false, false, false, false)) { + override fun getInitialFile(): VirtualFile? { + return if (modProps.scrcpyPath == null) null else LocalFileSystem.getInstance().findFileByIoFile(File(modProps.adbPath)) + } + }) scrcpyPath?.textField?.bindString(ScrcpyProps::scrcpyPath) + adbPath?.textField?.bindString(ScrcpyProps::adbPath) forceAdbForward?.bind(ScrcpyProps::forceAdbForward) noMipmaps?.bind(ScrcpyProps::noMipmaps) @@ -66,7 +74,7 @@ internal class ScrcpyControllerSettingsComponent { shortcutMod?.bindString(ScrcpyProps::shortcutMod) pathTest?.addActionListener { - CommandExecutor(modProps.pathTestCommand(), ModalityState.current()) { e, _, fullOp, ioe -> + CommandExecutor(pathTestCommand(), modalityState = ModalityState.current()) { e, _, fullOp, ioe -> if (ioe) { TextDialog("Path Invalid", "Provided path does not contain scrcpy executable", false).showAndGet() } else if (e != null) { @@ -79,11 +87,26 @@ internal class ScrcpyControllerSettingsComponent { } }.start() } + adbTest?.addActionListener { + CommandExecutor(adbTestCommand(), modalityState = ModalityState.current()) { e, _, fullOp, ioe -> + if (ioe) { + TextDialog("Invalid Executable", "Provided path does not contain adb executable", false).showAndGet() + } else if (e != null) { + val output = if (fullOp != null) { + "adb executable is valid

Version Info:
${fullOp.replace("\n", "
")}" + } else { + "Valid executable" + } + TextDialog("Valid executable", output, false).showAndGet() + } + }.start() + } } fun init() { modProps = props.copy() scrcpyPath?.textField?.text = modProps.scrcpyPath ?: "" + adbPath?.textField?.text = modProps.adbPath ?: "" forceAdbForward?.isSelected = modProps.forceAdbForward noMipmaps?.isSelected = modProps.noMipmaps startPort?.text = modProps.startPort?.toString() ?: "" @@ -101,6 +124,7 @@ internal class ScrcpyControllerSettingsComponent { fun apply() { modProps.apply { props.scrcpyPath = scrcpyPath + props.adbPath = adbPath props.forceAdbForward = forceAdbForward props.noMipmaps = noMipmaps props.startPort = startPort @@ -133,4 +157,25 @@ internal class ScrcpyControllerSettingsComponent { prop.set(modProps, isSelected) } } + + + private fun pathTestCommand() = arrayListOf().apply { + val path = scrcpyPath?.textField?.text + if (path != null) { + add(path + File.separator + "scrcpy") + } else { + add("scrcpy") + } + add("-v") + } + + private fun adbTestCommand() = arrayListOf().apply { + val adb = adbPath?.textField?.text + if (adb != null) { + add(adb) + } else { + add("adb") + } + add("version") + } } \ No newline at end of file diff --git a/src/main/kotlin/com/codertainment/scrcpy/controller/util/CommandExecutor.kt b/src/main/kotlin/com/codertainment/scrcpy/controller/util/CommandExecutor.kt index be394d2..416a10e 100644 --- a/src/main/kotlin/com/codertainment/scrcpy/controller/util/CommandExecutor.kt +++ b/src/main/kotlin/com/codertainment/scrcpy/controller/util/CommandExecutor.kt @@ -11,13 +11,21 @@ import java.io.InputStreamReader * on 19/06/2020 */ -class CommandExecutor(cmds: List, var modalityState: ModalityState? = null, private val onUpdate: (exitCode: Int?, line: String?, fullOutput: String?, ioe: Boolean) -> Unit) : Thread() { +class CommandExecutor( + cmds: List, + private var adbPath: String? = null, + private var modalityState: ModalityState? = null, + private val onUpdate: (exitCode: Int?, line: String?, fullOutput: String?, ioe: Boolean) -> Unit +) : Thread() { init { println("Got Command: ${cmds.joinToString(" ")}") } private val processBuilder = ProcessBuilder(cmds).apply { + adbPath?.let { + environment().put("ADB", it) + } redirectError(ProcessBuilder.Redirect.PIPE) redirectOutput(ProcessBuilder.Redirect.PIPE) redirectInput(ProcessBuilder.Redirect.PIPE)