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"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 25
|
||||
versionCode 15
|
||||
versionName "1.2.0-rc4"
|
||||
versionCode 16
|
||||
versionName "1.2.0-rc5"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
resConfigs "zh-rCN", "zh-rTW"
|
||||
externalNativeBuild {
|
||||
|
@ -5,6 +5,6 @@ import android.util.Log;
|
||||
public final class EmulatorDebug {
|
||||
|
||||
/** 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.widget.TextView
|
||||
import io.neoterm.R
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.PrintStream
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
@ -24,14 +26,12 @@ class CrashActivity : AppCompatActivity() {
|
||||
private fun collectExceptionInfo(): String {
|
||||
val extra = intent.getSerializableExtra("exception")
|
||||
if (extra != null && extra is Throwable) {
|
||||
val s = StringBuilder(extra.toString() + "\n\n")
|
||||
for ((index, trace) in extra.stackTrace.withIndex()) {
|
||||
s.append(String.format(" #%02d ", index))
|
||||
s.append("${trace.className}(${trace.fileName}:${trace.lineNumber})(native=${trace.isNativeMethod})")
|
||||
return s.toString()
|
||||
val byteArrayOutput = ByteArrayOutputStream()
|
||||
val printStream = PrintStream(byteArrayOutput)
|
||||
extra.printStackTrace(printStream)
|
||||
return byteArrayOutput.toString("utf-8")
|
||||
}
|
||||
}
|
||||
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 {
|
||||
|
@ -15,9 +15,9 @@ import io.neoterm.R
|
||||
import io.neoterm.customize.script.UserScript
|
||||
import io.neoterm.customize.script.UserScriptManager
|
||||
import io.neoterm.frontend.ShellParameter
|
||||
import io.neoterm.frontend.client.TermSessionCallback
|
||||
import io.neoterm.preference.NeoPreference
|
||||
import io.neoterm.services.NeoTermService
|
||||
import io.neoterm.frontend.client.TermSessionCallback
|
||||
import io.neoterm.utils.TerminalUtils
|
||||
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() {
|
||||
if (intent.hasExtra(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)
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildUserScriptArgument(files: List<String>): String {
|
||||
val builder = StringBuilder()
|
||||
files.forEach {
|
||||
builder.append(TerminalUtils.escapeString(it))
|
||||
builder.append(" ")
|
||||
private fun buildUserScriptArgument(userScriptPath: String, files: List<String>): Array<String> {
|
||||
val arguments = mutableListOf(userScriptPath)
|
||||
arguments.addAll(files)
|
||||
return arguments.toTypedArray()
|
||||
}
|
||||
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 {
|
||||
gravity = Gravity.TOP
|
||||
orientation = LinearLayout.VERTICAL
|
||||
|
||||
val scrollOne = HorizontalScrollView(context)
|
||||
val scrollTwo = HorizontalScrollView(context)
|
||||
loadDefaultBuiltinExtraKeys()
|
||||
loadDefaultUserDefinedExtraKeys()
|
||||
lineOne = initLine(scrollOne)
|
||||
lineTwo = initLine(scrollTwo)
|
||||
addView(scrollOne)
|
||||
addView(scrollTwo)
|
||||
|
||||
loadDefaultBuiltinExtraKeys()
|
||||
loadDefaultUserDefinedExtraKeys()
|
||||
updateButtons()
|
||||
}
|
||||
|
||||
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)
|
||||
line.gravity = Gravity.START
|
||||
line.orientation = LinearLayout.HORIZONTAL
|
||||
|
||||
scroll.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)
|
||||
scroll.isFillViewport = true
|
||||
scroll.isHorizontalScrollBarEnabled = false
|
||||
scroll.addView(line)
|
||||
return line
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user