code cleanup
This commit is contained in:
@@ -9,11 +9,12 @@ package xyz.nulldev.ts.config
|
||||
|
||||
import net.harawata.appdirs.AppDirsFactory
|
||||
|
||||
const val CONFIG_PREFIX = "suwayomi.tachidesk.config"
|
||||
|
||||
val ApplicationRootDir: String
|
||||
get(): String {
|
||||
return System.getProperty(
|
||||
"suwayomi.tachidesk.server.rootDir",
|
||||
"$CONFIG_PREFIX.server.rootDir",
|
||||
AppDirsFactory.getInstance().getUserDataDir("Tachidesk", null, null)
|
||||
)
|
||||
}
|
||||
@@ -48,7 +48,7 @@ open class ConfigManager {
|
||||
val baseConfig =
|
||||
ConfigFactory.parseMap(
|
||||
mapOf(
|
||||
"ts.server.rootDir" to ApplicationRootDir
|
||||
"androidcompat.rootDir" to "$ApplicationRootDir/android-compat" // override AndroidCompat's rootDir
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -18,22 +18,21 @@ abstract class ConfigModule(config: Config, moduleName: String = "") {
|
||||
val overridableWithSysProperty = SystemPropertyOverrideDelegate(config, moduleName)
|
||||
}
|
||||
|
||||
/** Defines a config property that is overridable with jvm `-D` commandline arguments prefixed with [CONFIG_PREFIX] */
|
||||
class SystemPropertyOverrideDelegate(val config: Config, val moduleName: String) {
|
||||
inline operator fun <R, reified T> getValue(thisRef: R, property: KProperty<*>): T {
|
||||
val configValue: T = config.getValue(thisRef, property)
|
||||
|
||||
val combined = System.getProperty(
|
||||
"suwayomi.tachidesk.config.$moduleName.${property.name}",
|
||||
"$CONFIG_PREFIX.$moduleName.${property.name}",
|
||||
configValue.toString()
|
||||
)
|
||||
|
||||
val asT = when(T::class.simpleName) {
|
||||
return when(T::class.simpleName) {
|
||||
"Int" -> combined.toInt()
|
||||
"Boolean" -> combined.toBoolean()
|
||||
// add more types as needed
|
||||
else -> combined
|
||||
}
|
||||
|
||||
return asT as T
|
||||
} as T
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package xyz.nulldev.androidcompat.config
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import io.github.config4k.getValue
|
||||
import xyz.nulldev.ts.config.ConfigModule
|
||||
|
||||
/**
|
||||
@@ -8,8 +9,8 @@ import xyz.nulldev.ts.config.ConfigModule
|
||||
*/
|
||||
|
||||
class ApplicationInfoConfigModule(config: Config) : ConfigModule(config) {
|
||||
val packageName = config.getString("packageName")!!
|
||||
val debug = config.getBoolean("debug")
|
||||
val packageName: String by config
|
||||
val debug: Boolean by config
|
||||
|
||||
companion object {
|
||||
fun register(config: Config)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package xyz.nulldev.androidcompat.config
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import io.github.config4k.getValue
|
||||
import xyz.nulldev.ts.config.ConfigModule
|
||||
|
||||
/**
|
||||
@@ -8,23 +9,23 @@ import xyz.nulldev.ts.config.ConfigModule
|
||||
*/
|
||||
|
||||
class FilesConfigModule(config: Config) : ConfigModule(config) {
|
||||
val dataDir = config.getString("dataDir")!!
|
||||
val filesDir = config.getString("filesDir")!!
|
||||
val noBackupFilesDir = config.getString("noBackupFilesDir")!!
|
||||
val externalFilesDirs: MutableList<String> = config.getStringList("externalFilesDirs")!!
|
||||
val obbDirs: MutableList<String> = config.getStringList("obbDirs")!!
|
||||
val cacheDir = config.getString("cacheDir")!!
|
||||
val codeCacheDir = config.getString("codeCacheDir")!!
|
||||
val externalCacheDirs: MutableList<String> = config.getStringList("externalCacheDirs")!!
|
||||
val externalMediaDirs: MutableList<String> = config.getStringList("externalMediaDirs")!!
|
||||
val rootDir = config.getString("rootDir")!!
|
||||
val externalStorageDir = config.getString("externalStorageDir")!!
|
||||
val downloadCacheDir = config.getString("downloadCacheDir")!!
|
||||
val databasesDir = config.getString("databasesDir")!!
|
||||
val dataDir:String by config
|
||||
val filesDir:String by config
|
||||
val noBackupFilesDir:String by config
|
||||
val externalFilesDirs: MutableList<String> by config
|
||||
val obbDirs: MutableList<String> by config
|
||||
val cacheDir:String by config
|
||||
val codeCacheDir:String by config
|
||||
val externalCacheDirs: MutableList<String> by config
|
||||
val externalMediaDirs: MutableList<String> by config
|
||||
val rootDir:String by config
|
||||
val externalStorageDir:String by config
|
||||
val downloadCacheDir:String by config
|
||||
val databasesDir:String by config
|
||||
|
||||
val prefsDir = config.getString("prefsDir")!!
|
||||
val prefsDir:String by config
|
||||
|
||||
val packageDir = config.getString("packageDir")!!
|
||||
val packageDir:String by config
|
||||
|
||||
companion object {
|
||||
fun register(config: Config)
|
||||
|
||||
@@ -2,9 +2,10 @@ package xyz.nulldev.androidcompat.config
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import xyz.nulldev.ts.config.ConfigModule
|
||||
import io.github.config4k.getValue
|
||||
|
||||
class SystemConfigModule(val config: Config) : ConfigModule(config) {
|
||||
val isDebuggable = config.getBoolean("isDebuggable")
|
||||
val isDebuggable: Boolean by config
|
||||
|
||||
val propertyPrefix = "properties."
|
||||
|
||||
|
||||
@@ -1,36 +1,12 @@
|
||||
# AndroidComapt Root dir
|
||||
androidcompat.rootDir = androidcompat-root
|
||||
|
||||
# Allow/disallow preference changes (useful for demos)
|
||||
ts.server.allowConfigChanges = true
|
||||
|
||||
# Enable the WebUI? Note: The API and multi-user sync server ui will remain available even if the WebUI is disabled
|
||||
ts.server.enableWebUi = true
|
||||
|
||||
# 'true' to use the old, buggy/memory-leaking WebUI
|
||||
ts.server.useOldWebUi = false
|
||||
|
||||
# 'true' to pretty print all JSON API responses
|
||||
ts.server.prettyPrintApi = false
|
||||
|
||||
# List of blacklisted/whitelisted API endpoints/operation IDs
|
||||
ts.server.disabledApiEndpoints = []
|
||||
ts.server.enabledApiEndpoints = []
|
||||
|
||||
# Message to print in the console when the API has finished booting
|
||||
ts.server.httpInitializedPrintMessage = ""
|
||||
|
||||
# Use external folder for static files
|
||||
ts.server.useExternalStaticFiles = false
|
||||
ts.server.externalStaticFilesFolder = ""
|
||||
|
||||
# Root storage dir
|
||||
ts.server.rootDir = tachiserver-data
|
||||
# Dir to store JVM patches
|
||||
ts.server.patchesDir = ${ts.server.rootDir}/patches
|
||||
####################### `android.files` (FilesConfigModule) #######################
|
||||
|
||||
# Storage dir for the emulated Android app
|
||||
android.files.rootDir = ${ts.server.rootDir}/android-compat/appdata
|
||||
android.files.rootDir = ${androidcompat.rootDir}/appdata
|
||||
# External storage dir for the emulated Android app's
|
||||
android.files.externalStorageDir = ${ts.server.rootDir}/android-compat/extappdata
|
||||
android.files.externalStorageDir = ${androidcompat.rootDir}/extappdata
|
||||
|
||||
# Internal Android directories
|
||||
android.files.dataDir = ${android.files.rootDir}/data
|
||||
@@ -48,37 +24,16 @@ android.files.externalCacheDirs = [${android.files.externalStorageDir}/cache]
|
||||
android.files.externalMediaDirs = [${android.files.externalStorageDir}/media]
|
||||
android.files.downloadCacheDir = ${android.files.externalStorageDir}/downloadCache
|
||||
|
||||
android.files.packageDir = ${ts.server.rootDir}/android-compat/packages
|
||||
android.files.packageDir = ${androidcompat.rootDir}/android-compat/packages
|
||||
|
||||
####################### `android.app` (ApplicationInfoConfigModule) #######################
|
||||
|
||||
# Emulated Android app package name
|
||||
android.app.packageName = eu.kanade.tachiyomi
|
||||
# Debug mode for the emulated Android app
|
||||
android.app.debug = true
|
||||
|
||||
####################### `android.system` (SystemConfigModule) #######################
|
||||
|
||||
# Whether or not the emulated Android system is debuggable
|
||||
android.system.isDebuggable = true
|
||||
|
||||
# Is the multi-user sync server enabled? Does not affect the single-user sync server included in the API.
|
||||
ts.syncd.enable = false
|
||||
|
||||
# The URL of this server (displayed in the sync server web ui)
|
||||
ts.syncd.baseUrl = "http://example.com"
|
||||
|
||||
# 'true' to disable the API and only enable the multi-user sync server
|
||||
ts.syncd.syncOnlyMode = false
|
||||
|
||||
# The root directory to store synchronized data
|
||||
ts.syncd.rootDir = ${ts.server.rootDir}/sync/accounts
|
||||
|
||||
# Location to store config files for the sandbox
|
||||
ts.syncd.sandboxedConfig = ${ts.server.rootDir}/sync/sandboxed_config.config
|
||||
|
||||
# Recaptcha stuff for signup/login
|
||||
ts.syncd.recaptcha.siteKey = ""
|
||||
ts.syncd.recaptcha.secret = ""
|
||||
|
||||
# Sync server display name
|
||||
ts.syncd.name = "Tachiyomi sync server"
|
||||
|
||||
# Header used to forward the IP to the multi-user sync server if the server is behind a reverse proxy
|
||||
ts.syncd.ipHeader = ""
|
||||
|
||||
@@ -12,7 +12,8 @@ import xyz.nulldev.ts.config.ConfigModule
|
||||
import xyz.nulldev.ts.config.GlobalConfigManager
|
||||
import xyz.nulldev.ts.config.debugLogsEnabled
|
||||
|
||||
class ServerConfig(config: Config, moduleName: String = "") : ConfigModule(config, moduleName) {
|
||||
private const val MODULE_NAME = "server"
|
||||
class ServerConfig(config: Config, moduleName: String = MODULE_NAME) : ConfigModule(config, moduleName) {
|
||||
val ip: String by overridableWithSysProperty
|
||||
val port: Int by overridableWithSysProperty
|
||||
|
||||
@@ -33,6 +34,6 @@ class ServerConfig(config: Config, moduleName: String = "") : ConfigModule(confi
|
||||
val electronPath: String by overridableWithSysProperty
|
||||
|
||||
companion object {
|
||||
fun register(config: Config) = ServerConfig(config.getConfig("server"), "server")
|
||||
fun register(config: Config) = ServerConfig(config.getConfig(MODULE_NAME))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user