Skip to content

Commit

Permalink
0.1.3: Add option to specify ADB Executable in IDE Settings
Browse files Browse the repository at this point in the history
Signed-off-by: Shripal Jain <[email protected]>
  • Loading branch information
shripal17 committed Oct 27, 2020
1 parent e8d832d commit e9b38ab
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 20 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/runConfigurations/buildPlugin.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/runConfigurations/runIde.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {

ext.kotlin_version = '1.4.0'
ext.kotlin_version = '1.4.10'

repositories {
mavenCentral()
Expand Down Expand Up @@ -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 """
<b>v0.1.3</b>: Add option to set adb path (use only if scrcpy can't detect ADB Path) (maybe necessary for macOS)<br>
<b>v0.1.2</b>: Really fix shortcut MOD setting not working (this time I've tested it :P)<br>
<b>v0.1.1</b>: Fix Shortcut MOD setting not working<br>
<b>v0.1.0</b>: <br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<String>().apply {
if (scrcpyPath != null) {
add(scrcpyPath + File.separator + "scrcpy")
} else {
add("scrcpy")
}
add("-v")
}
fun adbPath() = adbPath ?: "adb"

fun buildCommand(serial: String) = arrayListOf<String>().apply {
if (scrcpyPath != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.codertainment.scrcpy.controller.ui.ScrcpyControllerSettingsComponent">
<grid id="27dc6" binding="settingsPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="settingsPanel" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="5" left="5" bottom="5" right="5"/>
<constraints>
<xy x="20" y="20" width="586" height="580"/>
<xy x="20" y="20" width="624" height="580"/>
</constraints>
<properties>
<alignmentY value="0.0"/>
Expand Down Expand Up @@ -32,10 +32,40 @@
<text value="Test"/>
</properties>
</component>
<component id="fb3aa" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="ADB Executable"/>
</properties>
</component>
<component id="e82af" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="(Only use if scrcpy can't find ADB) (only required on unix-based systems)"/>
</properties>
</component>
<component id="718cb" class="javax.swing.JButton" binding="adbTest">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Test"/>
</properties>
</component>
<component id="afad1" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="adbPath">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<grid id="20f5" layout-manager="GridLayoutManager" row-count="9" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Advanced scrcpy Settings" title-justification="4"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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) {
Expand All @@ -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<br><br>Version Info:<br>${fullOp.replace("\n", "<br>")}"
} 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() ?: ""
Expand All @@ -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
Expand Down Expand Up @@ -133,4 +157,25 @@ internal class ScrcpyControllerSettingsComponent {
prop.set(modProps, isSelected)
}
}


private fun pathTestCommand() = arrayListOf<String>().apply {
val path = scrcpyPath?.textField?.text
if (path != null) {
add(path + File.separator + "scrcpy")
} else {
add("scrcpy")
}
add("-v")
}

private fun adbTestCommand() = arrayListOf<String>().apply {
val adb = adbPath?.textField?.text
if (adb != null) {
add(adb)
} else {
add("adb")
}
add("version")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ import java.io.InputStreamReader
* on 19/06/2020
*/

class CommandExecutor(cmds: List<String>, var modalityState: ModalityState? = null, private val onUpdate: (exitCode: Int?, line: String?, fullOutput: String?, ioe: Boolean) -> Unit) : Thread() {
class CommandExecutor(
cmds: List<String>,
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)
Expand Down

0 comments on commit e9b38ab

Please sign in to comment.