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
|
package io.neoterm.customize.shortcut.builtin
|
||||||
|
|
||||||
import io.neoterm.customize.shortcut.ShortcutKey
|
import io.neoterm.customize.NeoTermPath
|
||||||
import io.neoterm.customize.shortcut.ShortcutKeysManager
|
import io.neoterm.customize.shortcut.ShortcutConfigParser
|
||||||
import io.neoterm.view.ExtraKeysView
|
import io.neoterm.utils.FileUtils
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kiva
|
* @author kiva
|
||||||
*/
|
*/
|
||||||
object BuiltinShortcutKeys {
|
object BuiltinShortcutKeys {
|
||||||
val vim = object : ShortcutKey {
|
private const val vimKeys = "version ${ShortcutConfigParser.PARSER_VERSION}\n" +
|
||||||
override fun applyShortcutKeys(extraKeysView: ExtraKeysView) {
|
"program vim neovim vi\n" +
|
||||||
extraKeysView.addExternalButton(ExtraKeysView.SLASH) // Search
|
"define / false\n" +
|
||||||
extraKeysView.addExternalButton(ExtraKeysView.TextButton(":w", true)) // Save
|
"define :w true\n" +
|
||||||
extraKeysView.addExternalButton(ExtraKeysView.TextButton("dd", true)) // Delete
|
"define dd true\n" +
|
||||||
extraKeysView.addExternalButton(ExtraKeysView.TextButton(":q", true)) // Quit
|
"define :q true\n"
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val moreAndLess = object : ShortcutKey {
|
private const val moreKeys = "version ${ShortcutConfigParser.PARSER_VERSION}\n" +
|
||||||
override fun applyShortcutKeys(extraKeysView: ExtraKeysView) {
|
"program more less\n" +
|
||||||
extraKeysView.addExternalButton(ExtraKeysView.TextButton("R", true)) // Rest
|
"define R false\n" +
|
||||||
extraKeysView.addExternalButton(ExtraKeysView.TextButton("Q", true)) // Quit
|
"define Q false\n"
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun registerAll() {
|
fun registerAll() {
|
||||||
ShortcutKeysManager.registerShortcutKeys("vim", vim)
|
val vimFile = File(NeoTermPath.EKS_PATH, "vim.eks")
|
||||||
ShortcutKeysManager.registerShortcutKeys("more", moreAndLess)
|
if (!vimFile.exists()) {
|
||||||
ShortcutKeysManager.registerShortcutKeys("less", moreAndLess)
|
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 java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
import io.neoterm.backend.EmulatorDebug;
|
import io.neoterm.backend.EmulatorDebug;
|
||||||
|
import io.neoterm.customize.NeoTermPath;
|
||||||
import io.neoterm.preference.NeoTermPreference;
|
import io.neoterm.preference.NeoTermPreference;
|
||||||
|
|
||||||
public final class BaseFileInstaller {
|
public final class BaseFileInstaller {
|
||||||
public static interface ResultListener {
|
public interface ResultListener {
|
||||||
void onResult(Exception error);
|
void onResult(Exception error);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void installBaseFiles(final Activity activity, final ResultListener resultListener) {
|
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()) {
|
if (PREFIX_FILE.isDirectory()) {
|
||||||
resultListener.onResult(null);
|
resultListener.onResult(null);
|
||||||
return;
|
return;
|
||||||
@ -39,7 +40,7 @@ public final class BaseFileInstaller {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
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);
|
final File STAGING_PREFIX_FILE = new File(STAGING_PREFIX_PATH);
|
||||||
|
|
||||||
if (STAGING_PREFIX_FILE.exists()) {
|
if (STAGING_PREFIX_FILE.exists()) {
|
||||||
|
@ -13,6 +13,7 @@ import android.util.Log
|
|||||||
import io.neoterm.R
|
import io.neoterm.R
|
||||||
import io.neoterm.backend.EmulatorDebug
|
import io.neoterm.backend.EmulatorDebug
|
||||||
import io.neoterm.backend.TerminalSession
|
import io.neoterm.backend.TerminalSession
|
||||||
|
import io.neoterm.customize.NeoTermPath
|
||||||
import io.neoterm.preference.NeoTermPreference
|
import io.neoterm.preference.NeoTermPreference
|
||||||
import io.neoterm.ui.NeoTermActivity
|
import io.neoterm.ui.NeoTermActivity
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -74,17 +75,17 @@ class NeoTermService : Service() {
|
|||||||
|
|
||||||
var cwd = cwd
|
var cwd = cwd
|
||||||
if (cwd == null) {
|
if (cwd == null) {
|
||||||
cwd = NeoTermPreference.HOME_PATH
|
cwd = NeoTermPath.HOME_PATH
|
||||||
}
|
}
|
||||||
|
|
||||||
if (executablePath == null) {
|
if (executablePath == null) {
|
||||||
executablePath = if (systemShell)
|
executablePath = if (systemShell)
|
||||||
"/system/bin/sh"
|
"/system/bin/sh"
|
||||||
else
|
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()) {
|
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 de.mrapp.android.tabswitcher.view.TabSwitcherButton
|
||||||
import io.neoterm.R
|
import io.neoterm.R
|
||||||
import io.neoterm.backend.TerminalSession
|
import io.neoterm.backend.TerminalSession
|
||||||
|
import io.neoterm.customize.shortcut.ShortcutConfigLoader
|
||||||
import io.neoterm.customize.shortcut.builtin.BuiltinShortcutKeys
|
import io.neoterm.customize.shortcut.builtin.BuiltinShortcutKeys
|
||||||
import io.neoterm.installer.BaseFileInstaller
|
import io.neoterm.installer.BaseFileInstaller
|
||||||
import io.neoterm.preference.NeoPermission
|
import io.neoterm.preference.NeoPermission
|
||||||
@ -82,7 +83,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection {
|
|||||||
|
|
||||||
NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION)
|
NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION)
|
||||||
NeoTermPreference.init(this)
|
NeoTermPreference.init(this)
|
||||||
BuiltinShortcutKeys.registerAll()
|
initShortcutKeys()
|
||||||
|
|
||||||
if (NeoTermPreference.loadBoolean(R.string.key_ui_fullscreen, false)) {
|
if (NeoTermPreference.loadBoolean(R.string.key_ui_fullscreen, false)) {
|
||||||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
@ -104,6 +105,13 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection {
|
|||||||
bindService(serviceIntent, this, 0)
|
bindService(serviceIntent, this, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initShortcutKeys() {
|
||||||
|
Thread {
|
||||||
|
BuiltinShortcutKeys.registerAll()
|
||||||
|
ShortcutConfigLoader.loadDefinedConfigs()
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
tabSwitcher.addListener(object : TabSwitcherListener {
|
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