code cleanup

This commit is contained in:
Aria Moradi
2021-08-30 02:38:15 +04:30
parent c86ee53f66
commit 37cf80a188
8 changed files with 41 additions and 82 deletions
@@ -9,11 +9,12 @@ package xyz.nulldev.ts.config
import net.harawata.appdirs.AppDirsFactory import net.harawata.appdirs.AppDirsFactory
const val CONFIG_PREFIX = "suwayomi.tachidesk.config"
val ApplicationRootDir: String val ApplicationRootDir: String
get(): String { get(): String {
return System.getProperty( return System.getProperty(
"suwayomi.tachidesk.server.rootDir", "$CONFIG_PREFIX.server.rootDir",
AppDirsFactory.getInstance().getUserDataDir("Tachidesk", null, null) AppDirsFactory.getInstance().getUserDataDir("Tachidesk", null, null)
) )
} }
@@ -48,7 +48,7 @@ open class ConfigManager {
val baseConfig = val baseConfig =
ConfigFactory.parseMap( ConfigFactory.parseMap(
mapOf( 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) 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) { class SystemPropertyOverrideDelegate(val config: Config, val moduleName: String) {
inline operator fun <R, reified T> getValue(thisRef: R, property: KProperty<*>): T { inline operator fun <R, reified T> getValue(thisRef: R, property: KProperty<*>): T {
val configValue: T = config.getValue(thisRef, property) val configValue: T = config.getValue(thisRef, property)
val combined = System.getProperty( val combined = System.getProperty(
"suwayomi.tachidesk.config.$moduleName.${property.name}", "$CONFIG_PREFIX.$moduleName.${property.name}",
configValue.toString() configValue.toString()
) )
val asT = when(T::class.simpleName) { return when(T::class.simpleName) {
"Int" -> combined.toInt() "Int" -> combined.toInt()
"Boolean" -> combined.toBoolean() "Boolean" -> combined.toBoolean()
// add more types as needed // add more types as needed
else -> combined else -> combined
} } as T
return asT as T
} }
} }
@@ -1,6 +1,7 @@
package xyz.nulldev.androidcompat.config package xyz.nulldev.androidcompat.config
import com.typesafe.config.Config import com.typesafe.config.Config
import io.github.config4k.getValue
import xyz.nulldev.ts.config.ConfigModule import xyz.nulldev.ts.config.ConfigModule
/** /**
@@ -8,8 +9,8 @@ import xyz.nulldev.ts.config.ConfigModule
*/ */
class ApplicationInfoConfigModule(config: Config) : ConfigModule(config) { class ApplicationInfoConfigModule(config: Config) : ConfigModule(config) {
val packageName = config.getString("packageName")!! val packageName: String by config
val debug = config.getBoolean("debug") val debug: Boolean by config
companion object { companion object {
fun register(config: Config) fun register(config: Config)
@@ -1,6 +1,7 @@
package xyz.nulldev.androidcompat.config package xyz.nulldev.androidcompat.config
import com.typesafe.config.Config import com.typesafe.config.Config
import io.github.config4k.getValue
import xyz.nulldev.ts.config.ConfigModule import xyz.nulldev.ts.config.ConfigModule
/** /**
@@ -8,23 +9,23 @@ import xyz.nulldev.ts.config.ConfigModule
*/ */
class FilesConfigModule(config: Config) : ConfigModule(config) { class FilesConfigModule(config: Config) : ConfigModule(config) {
val dataDir = config.getString("dataDir")!! val dataDir:String by config
val filesDir = config.getString("filesDir")!! val filesDir:String by config
val noBackupFilesDir = config.getString("noBackupFilesDir")!! val noBackupFilesDir:String by config
val externalFilesDirs: MutableList<String> = config.getStringList("externalFilesDirs")!! val externalFilesDirs: MutableList<String> by config
val obbDirs: MutableList<String> = config.getStringList("obbDirs")!! val obbDirs: MutableList<String> by config
val cacheDir = config.getString("cacheDir")!! val cacheDir:String by config
val codeCacheDir = config.getString("codeCacheDir")!! val codeCacheDir:String by config
val externalCacheDirs: MutableList<String> = config.getStringList("externalCacheDirs")!! val externalCacheDirs: MutableList<String> by config
val externalMediaDirs: MutableList<String> = config.getStringList("externalMediaDirs")!! val externalMediaDirs: MutableList<String> by config
val rootDir = config.getString("rootDir")!! val rootDir:String by config
val externalStorageDir = config.getString("externalStorageDir")!! val externalStorageDir:String by config
val downloadCacheDir = config.getString("downloadCacheDir")!! val downloadCacheDir:String by config
val databasesDir = config.getString("databasesDir")!! 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 { companion object {
fun register(config: Config) fun register(config: Config)
@@ -2,9 +2,10 @@ package xyz.nulldev.androidcompat.config
import com.typesafe.config.Config import com.typesafe.config.Config
import xyz.nulldev.ts.config.ConfigModule import xyz.nulldev.ts.config.ConfigModule
import io.github.config4k.getValue
class SystemConfigModule(val config: Config) : ConfigModule(config) { class SystemConfigModule(val config: Config) : ConfigModule(config) {
val isDebuggable = config.getBoolean("isDebuggable") val isDebuggable: Boolean by config
val propertyPrefix = "properties." val propertyPrefix = "properties."
@@ -1,36 +1,12 @@
# AndroidComapt Root dir
androidcompat.rootDir = androidcompat-root
# Allow/disallow preference changes (useful for demos) ####################### `android.files` (FilesConfigModule) #######################
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
# Storage dir for the emulated Android app # 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 # 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 # Internal Android directories
android.files.dataDir = ${android.files.rootDir}/data 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.externalMediaDirs = [${android.files.externalStorageDir}/media]
android.files.downloadCacheDir = ${android.files.externalStorageDir}/downloadCache 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 # Emulated Android app package name
android.app.packageName = eu.kanade.tachiyomi android.app.packageName = eu.kanade.tachiyomi
# Debug mode for the emulated Android app # Debug mode for the emulated Android app
android.app.debug = true android.app.debug = true
####################### `android.system` (SystemConfigModule) #######################
# Whether or not the emulated Android system is debuggable # Whether or not the emulated Android system is debuggable
android.system.isDebuggable = true 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.GlobalConfigManager
import xyz.nulldev.ts.config.debugLogsEnabled 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 ip: String by overridableWithSysProperty
val port: Int by overridableWithSysProperty val port: Int by overridableWithSysProperty
@@ -33,6 +34,6 @@ class ServerConfig(config: Config, moduleName: String = "") : ConfigModule(confi
val electronPath: String by overridableWithSysProperty val electronPath: String by overridableWithSysProperty
companion object { companion object {
fun register(config: Config) = ServerConfig(config.getConfig("server"), "server") fun register(config: Config) = ServerConfig(config.getConfig(MODULE_NAME))
} }
} }