Component: Make component base dir a default value

This commit is contained in:
zt515 2017-12-26 23:51:00 +08:00
parent 72bfe2c784
commit 8445254e0d
36 changed files with 55 additions and 87 deletions

View File

@ -9,10 +9,10 @@ import io.neoterm.component.extrakey.ExtraKeyComponent
import io.neoterm.component.font.FontComponent
import io.neoterm.component.pm.PackageComponent
import io.neoterm.component.profile.ProfileComponent
import io.neoterm.component.userscript.UserScriptComponent
import io.neoterm.component.session.SessionComponent
import io.neoterm.frontend.logging.NLog
import io.neoterm.component.userscript.UserScriptComponent
import io.neoterm.frontend.component.ComponentManager
import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.session.shell.ShellProfile
/**

View File

@ -1,7 +1,7 @@
package io.neoterm.component.codegen
import io.neoterm.component.codegen.interfaces.CodeGenerator
import io.neoterm.component.codegen.interfaces.CodeGenObject
import io.neoterm.component.codegen.interfaces.CodeGenerator
import io.neoterm.frontend.component.NeoComponent
/**

View File

@ -1,8 +1,8 @@
package io.neoterm.component.codegen.generators
import io.neoterm.component.codegen.CodeGenParameter
import io.neoterm.component.codegen.interfaces.CodeGenerator
import io.neoterm.component.codegen.interfaces.CodeGenObject
import io.neoterm.component.codegen.interfaces.CodeGenerator
import io.neoterm.component.colorscheme.NeoColorScheme
import io.neoterm.component.config.ConfigureComponent
import io.neoterm.frontend.component.ComponentManager

View File

@ -1,8 +1,8 @@
package io.neoterm.component.codegen.generators
import io.neoterm.component.codegen.CodeGenParameter
import io.neoterm.component.codegen.interfaces.CodeGenerator
import io.neoterm.component.codegen.interfaces.CodeGenObject
import io.neoterm.component.codegen.interfaces.CodeGenerator
/**
* @author kiva

View File

@ -19,7 +19,7 @@ import java.io.File
/**
* @author kiva
*/
class ColorSchemeComponent : ConfigFileBasedComponent<NeoColorScheme>() {
class ColorSchemeComponent : ConfigFileBasedComponent<NeoColorScheme>(NeoTermPath.COLORS_PATH) {
companion object {
fun colorFile(colorName: String): File {
return File("${NeoTermPath.COLORS_PATH}/$colorName.nl")
@ -29,12 +29,9 @@ class ColorSchemeComponent : ConfigFileBasedComponent<NeoColorScheme>() {
override val checkComponentFileWhenObtained = true
private lateinit var DEFAULT_COLOR: NeoColorScheme
private lateinit var colors: MutableMap<String, NeoColorScheme>
private var colors: MutableMap<String, NeoColorScheme> = mutableMapOf()
override fun onCheckComponentFiles() {
File(NeoTermPath.COLORS_PATH).mkdirs()
colors = mutableMapOf()
val defaultColorFile = colorFile(DefaultColorScheme.colorName)
if (!defaultColorFile.exists()) {
if (!extractDefaultColor(App.get())) {
@ -50,9 +47,7 @@ class ColorSchemeComponent : ConfigFileBasedComponent<NeoColorScheme>() {
}
}
override fun onCreateComponentObject(configVisitor: ConfigVisitor): NeoColorScheme {
return NeoColorScheme()
}
override fun onCreateComponentObject(configVisitor: ConfigVisitor) = NeoColorScheme()
fun reloadColorSchemes(): Boolean {
colors.clear()

View File

@ -4,9 +4,9 @@ import io.neolang.visitor.ConfigVisitor
import io.neoterm.backend.TerminalColorScheme
import io.neoterm.backend.TerminalColors
import io.neoterm.component.codegen.CodeGenParameter
import io.neoterm.component.codegen.interfaces.CodeGenerator
import io.neoterm.component.codegen.interfaces.CodeGenObject
import io.neoterm.component.codegen.generators.NeoColorGenerator
import io.neoterm.component.codegen.interfaces.CodeGenObject
import io.neoterm.component.codegen.interfaces.CodeGenerator
import io.neoterm.component.config.ConfigureComponent
import io.neoterm.frontend.component.ComponentManager
import io.neoterm.frontend.component.helper.ConfigFileBasedObject

View File

@ -1,8 +1,8 @@
package io.neoterm.component.config.loaders
import io.neolang.runtime.type.NeoLangValue
import io.neoterm.component.colorscheme.NeoColorScheme
import io.neolang.visitor.ConfigVisitor
import io.neoterm.component.colorscheme.NeoColorScheme
import io.neoterm.frontend.config.NeoConfigureFile
import io.neoterm.frontend.logging.NLog
import java.io.File

View File

@ -14,7 +14,7 @@ import java.io.FileFilter
/**
* @author kiva
*/
class ExtraKeyComponent : ConfigFileBasedComponent<NeoExtraKey>() {
class ExtraKeyComponent : ConfigFileBasedComponent<NeoExtraKey>(NeoTermPath.EKS_PATH) {
companion object {
private val FILTER = FileFilter {
it.extension == "nl"
@ -26,8 +26,6 @@ class ExtraKeyComponent : ConfigFileBasedComponent<NeoExtraKey>() {
private val extraKeys: MutableMap<String, NeoExtraKey> = mutableMapOf()
override fun onCheckComponentFiles() {
File(NeoTermPath.EKS_PATH).mkdirs()
val defaultFile = File(NeoTermPath.EKS_DEFAULT_FILE)
if (!defaultFile.exists()) {
extractDefaultConfig(App.get())

View File

@ -4,10 +4,10 @@ import android.content.Context
import android.graphics.Typeface
import io.neoterm.App
import io.neoterm.R
import io.neoterm.frontend.config.NeoPreference
import io.neoterm.frontend.config.NeoTermPath
import io.neoterm.frontend.component.NeoComponent
import io.neoterm.frontend.config.DefaultValues
import io.neoterm.frontend.config.NeoPreference
import io.neoterm.frontend.config.NeoTermPath
import io.neoterm.frontend.terminal.TerminalView
import io.neoterm.frontend.terminal.extrakey.ExtraKeysView
import io.neoterm.utils.AssetsUtils

View File

@ -1,9 +1,9 @@
package io.neoterm.component.pm
import io.neoterm.R
import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.config.NeoPreference
import io.neoterm.frontend.config.NeoTermPath
import io.neoterm.frontend.logging.NLog
import java.io.File
import java.net.URL

View File

@ -1,9 +1,9 @@
package io.neoterm.component.profile
import io.neoterm.component.codegen.CodeGenParameter
import io.neoterm.component.codegen.interfaces.CodeGenerator
import io.neoterm.component.codegen.generators.NeoProfileGenerator
import io.neoterm.component.codegen.interfaces.CodeGenObject
import io.neoterm.component.codegen.interfaces.CodeGenerator
import io.neoterm.frontend.component.helper.ConfigFileBasedObject
/**

View File

@ -1,26 +1,19 @@
package io.neoterm.component.profile
import io.neolang.visitor.ConfigVisitor
import io.neoterm.component.config.ConfigureComponent
import io.neoterm.frontend.component.ComponentManager
import io.neoterm.frontend.component.NeoComponent
import io.neoterm.frontend.component.helper.ConfigFileBasedComponent
import io.neoterm.frontend.config.NeoConfigureFile
import io.neoterm.frontend.config.NeoTermPath
import io.neoterm.frontend.logging.NLog
import org.jetbrains.annotations.TestOnly
import java.io.File
/**
* @author kiva
*/
class ProfileComponent : ConfigFileBasedComponent<NeoProfile>() {
override fun onCheckComponentFiles() {
val profileDir = File(NeoTermPath.PROFILE_PATH)
if (!profileDir.exists()) {
profileDir.mkdirs()
}
}
class ProfileComponent : ConfigFileBasedComponent<NeoProfile>(NeoTermPath.PROFILE_PATH) {
override val checkComponentFileWhenObtained = true
private val profileRegistry = mutableMapOf<String, Class<out NeoProfile>>()
private val profileList = mutableListOf<NeoProfile>()
override fun onCheckComponentFiles() = reloadProfiles()
override fun onCreateComponentObject(configVisitor: ConfigVisitor): NeoProfile {
val rootContext = configVisitor.getRootContext()
@ -36,8 +29,9 @@ class ProfileComponent : ConfigFileBasedComponent<NeoProfile>() {
throw IllegalArgumentException("No proper profile registry for found")
}
private val profileRegistry = mutableMapOf<String, Class<out NeoProfile>>()
private val profileList = mutableListOf<NeoProfile>()
fun reloadProfiles() {
profileList.clear()
}
fun registerProfile(metaName: String, prototype: Class<out NeoProfile>) {
profileRegistry[metaName] = prototype

View File

@ -5,14 +5,13 @@ import android.app.Activity
import android.content.Context
import io.neoterm.Globals
import io.neoterm.frontend.component.NeoComponent
import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.config.NeoTermPath
import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.session.shell.ShellParameter
import io.neoterm.frontend.session.shell.ShellTermSession
import io.neoterm.frontend.session.xorg.XParameter
import io.neoterm.frontend.session.xorg.XSession
import io.neoterm.frontend.session.xorg.client.XSessionData
import io.neoterm.utils.TerminalUtils
/**
* @author kiva

View File

@ -4,8 +4,8 @@ import android.content.Context
import android.system.Os
import io.neoterm.App
import io.neoterm.frontend.component.NeoComponent
import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.config.NeoTermPath
import io.neoterm.frontend.logging.NLog
import io.neoterm.utils.AssetsUtils
import java.io.File

View File

@ -10,7 +10,7 @@ import java.io.File
/**
* @author kiva
*/
abstract class ConfigFileBasedComponent<out T : ConfigFileBasedObject> : NeoComponent {
abstract class ConfigFileBasedComponent<out T : ConfigFileBasedObject>(protected val baseDir: String) : NeoComponent {
companion object {
private val TAG = ConfigFileBasedComponent::class.java.simpleName
}
@ -18,6 +18,12 @@ abstract class ConfigFileBasedComponent<out T : ConfigFileBasedObject> : NeoComp
open val checkComponentFileWhenObtained = false
override fun onServiceInit() {
val baseDirFile = File(this.baseDir)
if (!baseDirFile.exists()) {
if (!baseDirFile.mkdirs()) {
throw RuntimeException("Cannot create component config directory: ${baseDirFile.absolutePath}")
}
}
onCheckComponentFiles()
}

View File

@ -5,10 +5,10 @@ import android.content.Context
import android.content.DialogInterface
import io.neoterm.R
import io.neoterm.backend.TerminalSession
import io.neoterm.frontend.session.shell.client.BasicSessionCallback
import io.neoterm.frontend.session.shell.client.BasicViewClient
import io.neoterm.frontend.session.shell.ShellParameter
import io.neoterm.frontend.session.shell.ShellTermSession
import io.neoterm.frontend.session.shell.client.BasicSessionCallback
import io.neoterm.frontend.session.shell.client.BasicViewClient
import io.neoterm.utils.TerminalUtils
/**

View File

@ -6,9 +6,9 @@ import android.view.LayoutInflater
import android.view.View
import io.neoterm.R
import io.neoterm.backend.TerminalSession
import io.neoterm.utils.TerminalUtils
import io.neoterm.frontend.terminal.TerminalView
import io.neoterm.frontend.terminal.TerminalViewClient
import io.neoterm.utils.TerminalUtils
/**
* @author kiva

View File

@ -4,15 +4,12 @@ import android.app.Activity
import android.app.AlertDialog
import android.app.ProgressDialog
import android.content.Context
import android.content.DialogInterface
import android.os.Build
import java.io.File
import java.util.Arrays
import io.neoterm.App
import io.neoterm.R
import io.neoterm.frontend.config.NeoTermPath
import java.io.File
import java.util.*
/**
* @author kiva

View File

@ -1,11 +1,10 @@
package io.neoterm.setup.connections
import java.io.IOException
import java.io.InputStream
import io.neoterm.App
import io.neoterm.setup.SetupHelper
import io.neoterm.utils.AssetsUtils
import java.io.IOException
import java.io.InputStream
/**
* @author kiva

View File

@ -1,13 +1,12 @@
package io.neoterm.setup.connections
import io.neoterm.setup.SetupHelper
import io.neoterm.setup.SourceConnection
import java.io.IOException
import java.io.InputStream
import java.net.HttpURLConnection
import java.net.URL
import io.neoterm.setup.SetupHelper
import io.neoterm.setup.SourceConnection
/**
* @author kiva
*/

View File

@ -1,10 +1,9 @@
package io.neoterm.setup.connections
import io.neoterm.setup.SourceConnection
import java.io.IOException
import java.io.InputStream
import io.neoterm.setup.SourceConnection
/**
* @author kiva
*/

View File

@ -13,17 +13,10 @@ import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.OvalShape
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.DisplayMetrics
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup
import android.view.ViewOutlineProvider
import android.view.WindowManager
import android.view.*
import android.view.animation.PathInterpolator
import android.widget.FrameLayout
import android.widget.ImageView
import io.neoterm.R
/**

View File

@ -3,7 +3,6 @@ package io.neoterm.ui.crash
import android.os.Build
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.widget.TextView
import io.neoterm.R
import java.io.ByteArrayOutputStream

View File

@ -10,9 +10,9 @@ import io.neoterm.frontend.config.NeoTermPath
import io.neoterm.frontend.session.shell.ShellParameter
import io.neoterm.frontend.session.shell.client.BasicSessionCallback
import io.neoterm.frontend.session.shell.client.BasicViewClient
import io.neoterm.utils.TerminalUtils
import io.neoterm.frontend.terminal.TerminalView
import io.neoterm.frontend.terminal.extrakey.ExtraKeysView
import io.neoterm.utils.TerminalUtils
/**
* @author kiva

View File

@ -19,9 +19,9 @@ import io.neoterm.component.pm.PackageComponent
import io.neoterm.component.pm.SourceManager
import io.neoterm.component.pm.SourceUtils
import io.neoterm.frontend.component.ComponentManager
import io.neoterm.frontend.floating.TerminalDialog
import io.neoterm.frontend.config.NeoPreference
import io.neoterm.frontend.config.NeoTermPath
import io.neoterm.frontend.floating.TerminalDialog
import io.neoterm.ui.pm.adapter.PackageAdapter
import io.neoterm.ui.pm.model.PackageModel
import io.neoterm.utils.PackageUtils

View File

@ -21,7 +21,6 @@ import android.preference.PreferenceActivity
import android.support.annotation.LayoutRes
import android.support.v7.app.ActionBar
import android.support.v7.app.AppCompatDelegate
import android.support.v7.widget.Toolbar
import android.view.MenuInflater
import android.view.View
import android.view.ViewGroup

View File

@ -2,11 +2,7 @@ package io.neoterm.ui.support
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.support.v7.app.AlertDialog
import android.widget.ImageView
import io.neoterm.R
import java.net.URISyntaxException
object Donation {

View File

@ -2,7 +2,6 @@ package io.neoterm.ui.support
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.MenuItem
import io.neoterm.R

View File

@ -20,16 +20,16 @@ import de.mrapp.android.tabswitcher.*
import io.neoterm.App
import io.neoterm.R
import io.neoterm.backend.TerminalSession
import io.neoterm.setup.SetupHelper
import io.neoterm.frontend.session.shell.client.TermSessionCallback
import io.neoterm.frontend.session.shell.client.TermViewClient
import io.neoterm.frontend.session.shell.client.event.*
import io.neoterm.frontend.config.NeoPermission
import io.neoterm.frontend.config.NeoPreference
import io.neoterm.frontend.session.shell.ShellParameter
import io.neoterm.frontend.session.shell.client.TermSessionCallback
import io.neoterm.frontend.session.shell.client.TermViewClient
import io.neoterm.frontend.session.shell.client.event.*
import io.neoterm.frontend.session.xorg.XParameter
import io.neoterm.frontend.session.xorg.XSession
import io.neoterm.services.NeoTermService
import io.neoterm.setup.SetupHelper
import io.neoterm.ui.pm.PackageManagerActivity
import io.neoterm.ui.settings.SettingActivity
import io.neoterm.ui.setup.SetupActivity

View File

@ -14,10 +14,10 @@ import io.neoterm.App
import io.neoterm.R
import io.neoterm.component.userscript.UserScript
import io.neoterm.component.userscript.UserScriptComponent
import io.neoterm.frontend.session.shell.client.TermSessionCallback
import io.neoterm.frontend.component.ComponentManager
import io.neoterm.frontend.config.NeoPreference
import io.neoterm.frontend.session.shell.ShellParameter
import io.neoterm.frontend.session.shell.client.TermSessionCallback
import io.neoterm.services.NeoTermService
import io.neoterm.utils.MediaUtils
import io.neoterm.utils.TerminalUtils

View File

@ -1,7 +1,6 @@
package io.neoterm.ui.term.tab
import android.content.res.Configuration
import android.util.Log
import de.mrapp.android.tabswitcher.Tab
/**

View File

@ -4,10 +4,10 @@ import android.content.Context
import android.support.v7.widget.Toolbar
import android.view.inputmethod.InputMethodManager
import io.neoterm.component.colorscheme.ColorSchemeComponent
import io.neoterm.frontend.component.ComponentManager
import io.neoterm.frontend.session.shell.client.TermSessionData
import io.neoterm.frontend.session.shell.client.TermUiPresenter
import io.neoterm.frontend.session.shell.client.event.*
import io.neoterm.frontend.component.ComponentManager
import org.greenrobot.eventbus.EventBus
/**

View File

@ -1,7 +1,6 @@
package io.neoterm.utils
import android.content.Intent
import android.os.Process
import io.neoterm.App
import io.neoterm.ui.crash.CrashActivity

View File

@ -1,7 +1,6 @@
package io.neoterm.utils
import android.app.Activity
import android.content.Context
import android.graphics.Rect
import android.view.View
import android.widget.FrameLayout

View File

@ -9,7 +9,6 @@ import android.os.Build
import android.os.Environment
import android.provider.DocumentsContract
import android.provider.MediaStore
import io.neoterm.frontend.logging.NLog
/**
* @author kiva

View File

@ -3,9 +3,9 @@ package io.neoterm.utils
import android.content.Context
import io.neoterm.R
import io.neoterm.backend.TerminalSession
import io.neoterm.frontend.floating.TerminalDialog
import io.neoterm.frontend.config.NeoPreference
import io.neoterm.frontend.config.NeoTermPath
import io.neoterm.frontend.floating.TerminalDialog
import java.io.File
/**