Feature: Customize EKS
This commit is contained in:
@ -0,0 +1,42 @@
|
||||
package io.neoterm.customize.shortcut
|
||||
|
||||
import android.util.Log
|
||||
import io.neoterm.customize.NeoTermPath
|
||||
import io.neoterm.view.ExtraKeysView
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
object ShortcutConfigLoader {
|
||||
class ConfiguredShortcutKey(val config: ShortcutConfig) : ShortcutKey {
|
||||
override fun applyShortcutKeys(extraKeysView: ExtraKeysView) {
|
||||
for (button in config.shortcutKeys) {
|
||||
extraKeysView.addExternalButton(button)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadDefinedConfigs() {
|
||||
val configDir = File(NeoTermPath.EKS_PATH)
|
||||
configDir.mkdirs()
|
||||
|
||||
val parser = ShortcutConfigParser()
|
||||
for (file in configDir.listFiles()) {
|
||||
try {
|
||||
parser.setInput(file)
|
||||
val config = parser.parse()
|
||||
registerConfig(config)
|
||||
} catch (e: Exception) {
|
||||
Log.e("NeoTerm-EKS", "Load $file failed: " + e.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerConfig(config: ShortcutConfig) {
|
||||
val shortcutKey = ConfiguredShortcutKey(config)
|
||||
for (programName in config.programNames) {
|
||||
ShortcutKeysManager.registerShortcutKeys(programName, shortcutKey)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +1,35 @@
|
||||
package io.neoterm.customize.shortcut.builtin
|
||||
|
||||
import io.neoterm.customize.shortcut.ShortcutKey
|
||||
import io.neoterm.customize.shortcut.ShortcutKeysManager
|
||||
import io.neoterm.view.ExtraKeysView
|
||||
import io.neoterm.customize.NeoTermPath
|
||||
import io.neoterm.customize.shortcut.ShortcutConfigParser
|
||||
import io.neoterm.utils.FileUtils
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
object BuiltinShortcutKeys {
|
||||
val vim = object : ShortcutKey {
|
||||
override fun applyShortcutKeys(extraKeysView: ExtraKeysView) {
|
||||
extraKeysView.addExternalButton(ExtraKeysView.SLASH) // Search
|
||||
extraKeysView.addExternalButton(ExtraKeysView.TextButton(":w", true)) // Save
|
||||
extraKeysView.addExternalButton(ExtraKeysView.TextButton("dd", true)) // Delete
|
||||
extraKeysView.addExternalButton(ExtraKeysView.TextButton(":q", true)) // Quit
|
||||
}
|
||||
}
|
||||
private const val vimKeys = "version ${ShortcutConfigParser.PARSER_VERSION}\n" +
|
||||
"program vim neovim vi\n" +
|
||||
"define / false\n" +
|
||||
"define :w true\n" +
|
||||
"define dd true\n" +
|
||||
"define :q true\n"
|
||||
|
||||
val moreAndLess = object : ShortcutKey {
|
||||
override fun applyShortcutKeys(extraKeysView: ExtraKeysView) {
|
||||
extraKeysView.addExternalButton(ExtraKeysView.TextButton("R", true)) // Rest
|
||||
extraKeysView.addExternalButton(ExtraKeysView.TextButton("Q", true)) // Quit
|
||||
}
|
||||
}
|
||||
private const val moreKeys = "version ${ShortcutConfigParser.PARSER_VERSION}\n" +
|
||||
"program more less\n" +
|
||||
"define R false\n" +
|
||||
"define Q false\n"
|
||||
|
||||
fun registerAll() {
|
||||
ShortcutKeysManager.registerShortcutKeys("vim", vim)
|
||||
ShortcutKeysManager.registerShortcutKeys("more", moreAndLess)
|
||||
ShortcutKeysManager.registerShortcutKeys("less", moreAndLess)
|
||||
val vimFile = File(NeoTermPath.EKS_PATH, "vim.eks")
|
||||
if (!vimFile.exists()) {
|
||||
FileUtils.writeFile(vimFile, vimKeys.toByteArray())
|
||||
}
|
||||
|
||||
val moreFile = File(NeoTermPath.EKS_PATH, "more-less.eks")
|
||||
if (!moreFile.exists()) {
|
||||
FileUtils.writeFile(moreFile, moreKeys.toByteArray())
|
||||
}
|
||||
}
|
||||
}
|
@ -20,15 +20,16 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import io.neoterm.backend.EmulatorDebug;
|
||||
import io.neoterm.customize.NeoTermPath;
|
||||
import io.neoterm.preference.NeoTermPreference;
|
||||
|
||||
public final class BaseFileInstaller {
|
||||
public static interface ResultListener {
|
||||
public interface ResultListener {
|
||||
void onResult(Exception error);
|
||||
}
|
||||
|
||||
public static void installBaseFiles(final Activity activity, final ResultListener resultListener) {
|
||||
final File PREFIX_FILE = new File(NeoTermPreference.USR_PATH);
|
||||
final File PREFIX_FILE = new File(NeoTermPath.USR_PATH);
|
||||
if (PREFIX_FILE.isDirectory()) {
|
||||
resultListener.onResult(null);
|
||||
return;
|
||||
@ -39,7 +40,7 @@ public final class BaseFileInstaller {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final String STAGING_PREFIX_PATH = NeoTermPreference.ROOT_PATH + "/usr-staging";
|
||||
final String STAGING_PREFIX_PATH = NeoTermPath.ROOT_PATH + "/usr-staging";
|
||||
final File STAGING_PREFIX_FILE = new File(STAGING_PREFIX_PATH);
|
||||
|
||||
if (STAGING_PREFIX_FILE.exists()) {
|
||||
|
@ -13,6 +13,7 @@ import android.util.Log
|
||||
import io.neoterm.R
|
||||
import io.neoterm.backend.EmulatorDebug
|
||||
import io.neoterm.backend.TerminalSession
|
||||
import io.neoterm.customize.NeoTermPath
|
||||
import io.neoterm.preference.NeoTermPreference
|
||||
import io.neoterm.ui.NeoTermActivity
|
||||
import java.io.File
|
||||
@ -74,17 +75,17 @@ class NeoTermService : Service() {
|
||||
|
||||
var cwd = cwd
|
||||
if (cwd == null) {
|
||||
cwd = NeoTermPreference.HOME_PATH
|
||||
cwd = NeoTermPath.HOME_PATH
|
||||
}
|
||||
|
||||
if (executablePath == null) {
|
||||
executablePath = if (systemShell)
|
||||
"/system/bin/sh"
|
||||
else
|
||||
NeoTermPreference.USR_PATH + "/bin/" + NeoTermPreference.loadString(R.string.key_general_shell, "sh")
|
||||
NeoTermPath.USR_PATH + "/bin/" + NeoTermPreference.loadString(R.string.key_general_shell, "sh")
|
||||
|
||||
if (!File(executablePath).exists()) {
|
||||
NeoTermPreference.USR_PATH + "/bin/sh"
|
||||
NeoTermPath.USR_PATH + "/bin/sh"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import de.mrapp.android.tabswitcher.*
|
||||
import de.mrapp.android.tabswitcher.view.TabSwitcherButton
|
||||
import io.neoterm.R
|
||||
import io.neoterm.backend.TerminalSession
|
||||
import io.neoterm.customize.shortcut.ShortcutConfigLoader
|
||||
import io.neoterm.customize.shortcut.builtin.BuiltinShortcutKeys
|
||||
import io.neoterm.installer.BaseFileInstaller
|
||||
import io.neoterm.preference.NeoPermission
|
||||
@ -82,7 +83,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection {
|
||||
|
||||
NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION)
|
||||
NeoTermPreference.init(this)
|
||||
BuiltinShortcutKeys.registerAll()
|
||||
initShortcutKeys()
|
||||
|
||||
if (NeoTermPreference.loadBoolean(R.string.key_ui_fullscreen, false)) {
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
@ -104,6 +105,13 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection {
|
||||
bindService(serviceIntent, this, 0)
|
||||
}
|
||||
|
||||
private fun initShortcutKeys() {
|
||||
Thread {
|
||||
BuiltinShortcutKeys.registerAll()
|
||||
ShortcutConfigLoader.loadDefinedConfigs()
|
||||
}.start()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
tabSwitcher.addListener(object : TabSwitcherListener {
|
||||
|
31
app/src/main/java/io/neoterm/utils/FileUtils.kt
Normal file
31
app/src/main/java/io/neoterm/utils/FileUtils.kt
Normal file
@ -0,0 +1,31 @@
|
||||
package io.neoterm.utils
|
||||
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
object FileUtils {
|
||||
fun writeFile(path: File, bytes: ByteArray): Boolean {
|
||||
var output: OutputStream? = null
|
||||
var success = true
|
||||
try {
|
||||
output = FileOutputStream(path)
|
||||
output.write(bytes)
|
||||
output.flush()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
success = false
|
||||
} finally {
|
||||
if (output != null) {
|
||||
try {
|
||||
output.close()
|
||||
} catch (ignore: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return success
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user