forked from Suwayomi/Suwayomi-WebUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
android support! thanks to TachiWeb devs.
- Loading branch information
1 parent
ced07d4
commit 1e46a0c
Showing
291 changed files
with
68,699 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dependencies { | ||
// Config API | ||
// implementation("com.typesafe:config:1.4.0") | ||
} |
12 changes: 12 additions & 0 deletions
12
AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ConfigKodeinModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package xyz.nulldev.ts.config | ||
|
||
import org.kodein.di.DI | ||
import org.kodein.di.bind | ||
import org.kodein.di.singleton | ||
|
||
class ConfigKodeinModule { | ||
fun create() = DI.Module("ConfigManager") { | ||
//Config module | ||
bind<ConfigManager>() with singleton { GlobalConfigManager } | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ConfigManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package xyz.nulldev.ts.config | ||
|
||
import com.typesafe.config.Config | ||
import com.typesafe.config.ConfigFactory | ||
import com.typesafe.config.ConfigRenderOptions | ||
import mu.KotlinLogging | ||
import java.io.File | ||
|
||
/** | ||
* Manages app config. | ||
*/ | ||
open class ConfigManager { | ||
private val generatedModules | ||
= mutableMapOf<Class<out ConfigModule>, ConfigModule>() | ||
val config by lazy { loadConfigs() } | ||
|
||
//Public read-only view of modules | ||
val loadedModules: Map<Class<out ConfigModule>, ConfigModule> | ||
get() = generatedModules | ||
|
||
open val configFolder: String | ||
get() = System.getProperty("compat-configdirs") ?: "tachiserver-data/config" | ||
|
||
val logger = KotlinLogging.logger {} | ||
|
||
/** | ||
* Get a config module | ||
*/ | ||
inline fun <reified T : ConfigModule> module(): T | ||
= loadedModules[T::class.java] as T | ||
|
||
/** | ||
* Get a config module (Java API) | ||
*/ | ||
fun <T : ConfigModule> module(type: Class<T>): T | ||
= loadedModules[type] as T | ||
|
||
/** | ||
* Load configs | ||
*/ | ||
fun loadConfigs(): Config { | ||
val configs = mutableListOf<Config>() | ||
|
||
//Load reference config | ||
configs += ConfigFactory.parseResources("reference.conf") | ||
|
||
//Load custom configs from dir | ||
File(configFolder).listFiles()?.map { | ||
ConfigFactory.parseFile(it) | ||
}?.filterNotNull()?.forEach { | ||
configs += it.withFallback(configs.last()) | ||
} | ||
|
||
val config = configs.last().resolve() | ||
|
||
logger.debug { | ||
"Loaded config:\n" + config.root().render(ConfigRenderOptions.concise().setFormatted(true)) | ||
} | ||
|
||
return config | ||
} | ||
|
||
fun registerModule(module: ConfigModule) { | ||
generatedModules.put(module.javaClass, module) | ||
} | ||
|
||
fun registerModules(vararg modules: ConfigModule) { | ||
modules.forEach { | ||
registerModule(it) | ||
} | ||
} | ||
} | ||
|
||
object GlobalConfigManager : ConfigManager() |
8 changes: 8 additions & 0 deletions
8
AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ConfigModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package xyz.nulldev.ts.config | ||
|
||
import com.typesafe.config.Config | ||
|
||
/** | ||
* Abstract config module. | ||
*/ | ||
abstract class ConfigModule(config: Config) |
35 changes: 35 additions & 0 deletions
35
AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ServerConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package xyz.nulldev.ts.config | ||
|
||
import com.typesafe.config.Config | ||
import java.io.File | ||
|
||
class ServerConfig(config: Config) : ConfigModule(config) { | ||
val ip = config.getString("ip") | ||
val port = config.getInt("port") | ||
|
||
val allowConfigChanges = config.getBoolean("allowConfigChanges") | ||
val enableWebUi = config.getBoolean("enableWebUi") | ||
val useOldWebUi = config.getBoolean("useOldWebUi") | ||
val prettyPrintApi = config.getBoolean("prettyPrintApi") | ||
// TODO Apply to operation IDs | ||
val disabledApiEndpoints = config.getStringList("disabledApiEndpoints").map(String::toLowerCase) | ||
val enabledApiEndpoints = config.getStringList("enabledApiEndpoints").map(String::toLowerCase) | ||
val httpInitializedPrintMessage = config.getString("httpInitializedPrintMessage") | ||
|
||
val useExternalStaticFiles = config.getBoolean("useExternalStaticFiles") | ||
val externalStaticFilesFolder = config.getString("externalStaticFilesFolder") | ||
|
||
val rootDir = registerFile(config.getString("rootDir")) | ||
val patchesDir = registerFile(config.getString("patchesDir")) | ||
|
||
fun registerFile(file: String): File { | ||
return File(file).apply { | ||
mkdirs() | ||
} | ||
} | ||
|
||
companion object { | ||
fun register(config: Config) | ||
= ServerConfig(config.getConfig("ts.server")) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/util/ConfigExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package xyz.nulldev.ts.config.util | ||
|
||
import com.typesafe.config.Config | ||
|
||
operator fun Config.get(key: String) = getString(key) | ||
?: throw IllegalStateException("Could not find value for config entry: $key!") |
1 change: 1 addition & 0 deletions
1
...at/Config/src/main/resources/META-INF/services/xyz.nulldev.ts.api.v2.java.model.ServerAPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
xyz.nulldev.ts.api.v2.java.impl.ServerAPIImpl |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.