Improve: UserScript will be executed like a shell
This commit is contained in:
parent
3681806910
commit
6b3f9e2a39
@ -17,8 +17,8 @@ android {
|
|||||||
applicationId "io.neoterm"
|
applicationId "io.neoterm"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 15
|
versionCode 16
|
||||||
versionName "1.2.0-rc4"
|
versionName "1.2.0-rc5"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
resConfigs "zh-rCN", "zh-rTW"
|
resConfigs "zh-rCN", "zh-rTW"
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
|
@ -5,6 +5,6 @@ import android.util.Log;
|
|||||||
public final class EmulatorDebug {
|
public final class EmulatorDebug {
|
||||||
|
|
||||||
/** The tag to use with {@link Log}. */
|
/** The tag to use with {@link Log}. */
|
||||||
public static final String LOG_TAG = "neoterm";
|
public static final String LOG_TAG = "NeoTerm-Emulator";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import android.support.v7.app.AppCompatActivity
|
|||||||
import android.support.v7.widget.Toolbar
|
import android.support.v7.widget.Toolbar
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import io.neoterm.R
|
import io.neoterm.R
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.PrintStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kiva
|
* @author kiva
|
||||||
@ -24,14 +26,12 @@ class CrashActivity : AppCompatActivity() {
|
|||||||
private fun collectExceptionInfo(): String {
|
private fun collectExceptionInfo(): String {
|
||||||
val extra = intent.getSerializableExtra("exception")
|
val extra = intent.getSerializableExtra("exception")
|
||||||
if (extra != null && extra is Throwable) {
|
if (extra != null && extra is Throwable) {
|
||||||
val s = StringBuilder(extra.toString() + "\n\n")
|
val byteArrayOutput = ByteArrayOutputStream()
|
||||||
for ((index, trace) in extra.stackTrace.withIndex()) {
|
val printStream = PrintStream(byteArrayOutput)
|
||||||
s.append(String.format(" #%02d ", index))
|
extra.printStackTrace(printStream)
|
||||||
s.append("${trace.className}(${trace.fileName}:${trace.lineNumber})(native=${trace.isNativeMethod})")
|
return byteArrayOutput.toString("utf-8")
|
||||||
return s.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return "are.you.kidding.me.NoExceptionFoundException: This is a bug, please contact me!"
|
return "are.you.kidding.me.NoExceptionFoundException: This is a bug, please contact developers!"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun collectAppInfo(): String {
|
fun collectAppInfo(): String {
|
||||||
|
@ -15,9 +15,9 @@ import io.neoterm.R
|
|||||||
import io.neoterm.customize.script.UserScript
|
import io.neoterm.customize.script.UserScript
|
||||||
import io.neoterm.customize.script.UserScriptManager
|
import io.neoterm.customize.script.UserScriptManager
|
||||||
import io.neoterm.frontend.ShellParameter
|
import io.neoterm.frontend.ShellParameter
|
||||||
|
import io.neoterm.frontend.client.TermSessionCallback
|
||||||
import io.neoterm.preference.NeoPreference
|
import io.neoterm.preference.NeoPreference
|
||||||
import io.neoterm.services.NeoTermService
|
import io.neoterm.services.NeoTermService
|
||||||
import io.neoterm.frontend.client.TermSessionCallback
|
|
||||||
import io.neoterm.utils.TerminalUtils
|
import io.neoterm.utils.TerminalUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -68,24 +68,6 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openTerm(initialCommand: String?) {
|
|
||||||
// TODO: check whether system executablePath we should use
|
|
||||||
val parameter = ShellParameter()
|
|
||||||
.initialCommand(initialCommand)
|
|
||||||
.callback(TermSessionCallback())
|
|
||||||
.systemShell(false)
|
|
||||||
val session = termService!!.createTermSession(parameter)
|
|
||||||
|
|
||||||
// Set current session to our new one
|
|
||||||
// In order to switch to it when entering NeoTermActivity
|
|
||||||
NeoPreference.storeCurrentSession(session)
|
|
||||||
|
|
||||||
val intent = Intent(this, NeoTermActivity::class.java)
|
|
||||||
intent.addCategory(Intent.CATEGORY_DEFAULT)
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
startActivity(intent)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleTermHere() {
|
private fun handleTermHere() {
|
||||||
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
|
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
|
||||||
val extra = intent.extras.get(Intent.EXTRA_STREAM)
|
val extra = intent.extras.get(Intent.EXTRA_STREAM)
|
||||||
@ -150,21 +132,55 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
|
|||||||
|
|
||||||
val scriptsAdapter = ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, scriptsListItem)
|
val scriptsAdapter = ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, scriptsListItem)
|
||||||
scriptsList.adapter = scriptsAdapter
|
scriptsList.adapter = scriptsAdapter
|
||||||
scriptsList.setOnItemClickListener { _, _, position, _ ->
|
|
||||||
val script = userScripts[position].scriptFile.absoluteFile
|
|
||||||
val argument = buildUserScriptArgument(filesToHandle)
|
|
||||||
|
|
||||||
openTerm("$script $argument")
|
scriptsList.setOnItemClickListener { _, _, position, _ ->
|
||||||
|
val userScript = userScripts[position]
|
||||||
|
val userScriptPath = userScript.scriptFile.absolutePath
|
||||||
|
val arguments = buildUserScriptArgument(userScriptPath, filesToHandle)
|
||||||
|
|
||||||
|
openCustomExecTerm(userScriptPath, arguments, userScript.scriptFile.parent)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildUserScriptArgument(files: List<String>): String {
|
private fun buildUserScriptArgument(userScriptPath: String, files: List<String>): Array<String> {
|
||||||
val builder = StringBuilder()
|
val arguments = mutableListOf(userScriptPath)
|
||||||
files.forEach {
|
arguments.addAll(files)
|
||||||
builder.append(TerminalUtils.escapeString(it))
|
return arguments.toTypedArray()
|
||||||
builder.append(" ")
|
}
|
||||||
}
|
|
||||||
return builder.toString()
|
private fun openTerm(parameter: ShellParameter) {
|
||||||
|
val session = termService!!.createTermSession(parameter)
|
||||||
|
|
||||||
|
// Set current session to our new one
|
||||||
|
// In order to switch to it when entering NeoTermActivity
|
||||||
|
NeoPreference.storeCurrentSession(session)
|
||||||
|
|
||||||
|
val intent = Intent(this, NeoTermActivity::class.java)
|
||||||
|
intent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun openCustomExecTerm(executablePath: String?, arguments: Array<String>?, cwd: String?) {
|
||||||
|
val parameter = ShellParameter()
|
||||||
|
.executablePath(executablePath)
|
||||||
|
.arguments(arguments)
|
||||||
|
.currentWorkingDirectory(cwd)
|
||||||
|
.callback(TermSessionCallback())
|
||||||
|
.systemShell(detectSystemShell())
|
||||||
|
openTerm(parameter)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun openTerm(initialCommand: String?) {
|
||||||
|
val parameter = ShellParameter()
|
||||||
|
.initialCommand(initialCommand)
|
||||||
|
.callback(TermSessionCallback())
|
||||||
|
.systemShell(detectSystemShell())
|
||||||
|
openTerm(parameter)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun detectSystemShell(): Boolean {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -38,24 +38,27 @@ class ExtraKeysView(context: Context, attrs: AttributeSet) : LinearLayout(contex
|
|||||||
init {
|
init {
|
||||||
gravity = Gravity.TOP
|
gravity = Gravity.TOP
|
||||||
orientation = LinearLayout.VERTICAL
|
orientation = LinearLayout.VERTICAL
|
||||||
|
|
||||||
val scrollOne = HorizontalScrollView(context)
|
val scrollOne = HorizontalScrollView(context)
|
||||||
val scrollTwo = HorizontalScrollView(context)
|
val scrollTwo = HorizontalScrollView(context)
|
||||||
loadDefaultBuiltinExtraKeys()
|
|
||||||
loadDefaultUserDefinedExtraKeys()
|
|
||||||
lineOne = initLine(scrollOne)
|
lineOne = initLine(scrollOne)
|
||||||
lineTwo = initLine(scrollTwo)
|
lineTwo = initLine(scrollTwo)
|
||||||
addView(scrollOne)
|
addView(scrollOne)
|
||||||
addView(scrollTwo)
|
addView(scrollTwo)
|
||||||
|
|
||||||
|
loadDefaultBuiltinExtraKeys()
|
||||||
|
loadDefaultUserDefinedExtraKeys()
|
||||||
updateButtons()
|
updateButtons()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initLine(scroll: HorizontalScrollView): LinearLayout {
|
private fun initLine(scroll: HorizontalScrollView): LinearLayout {
|
||||||
scroll.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)
|
|
||||||
scroll.isFillViewport = true
|
|
||||||
scroll.isHorizontalScrollBarEnabled = false
|
|
||||||
val line = LinearLayout(context)
|
val line = LinearLayout(context)
|
||||||
line.gravity = Gravity.START
|
line.gravity = Gravity.START
|
||||||
line.orientation = LinearLayout.HORIZONTAL
|
line.orientation = LinearLayout.HORIZONTAL
|
||||||
|
|
||||||
|
scroll.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)
|
||||||
|
scroll.isFillViewport = true
|
||||||
|
scroll.isHorizontalScrollBarEnabled = false
|
||||||
scroll.addView(line)
|
scroll.addView(line)
|
||||||
return line
|
return line
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user