diff --git a/AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/RootDir.kt b/AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ApplicationRootDir.kt similarity index 59% rename from AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/RootDir.kt rename to AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ApplicationRootDir.kt index ccfdd87..cc30fec 100644 --- a/AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/RootDir.kt +++ b/AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ApplicationRootDir.kt @@ -9,9 +9,10 @@ import net.harawata.appdirs.AppDirsFactory * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -fun tachideskRootDir(): String { - return System.getProperty( - "ir.armor.tachidesk.rootDir", - AppDirsFactory.getInstance().getUserDataDir("Tachidesk", null, null) - ) -} \ No newline at end of file +val ApplicationRootDir: String + get(): String { + return System.getProperty( + "ir.armor.tachidesk.rootDir", + AppDirsFactory.getInstance().getUserDataDir("Tachidesk", null, null) + ) + } \ No newline at end of file diff --git a/AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ConfigManager.kt b/AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ConfigManager.kt index f1e941d..817083e 100644 --- a/AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ConfigManager.kt +++ b/AndroidCompat/Config/src/main/java/xyz/nulldev/ts/config/ConfigManager.kt @@ -46,7 +46,7 @@ open class ConfigManager { //Load user config val userConfig = - File(tachideskRootDir(), "server.conf").let { + File(ApplicationRootDir, "server.conf").let { ConfigFactory.parseFile(it) } diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt index 3adef0b..dced2e5 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt @@ -50,10 +50,9 @@ object Extension { private val logger = KotlinLogging.logger {} private val applicationDirs by DI.global.instance() - data class InstallableAPK( - val apkFilePath: String, - val pkgName: String + val apkFilePath: String, + val pkgName: String ) suspend fun installExtension(pkgName: String): Int { @@ -99,8 +98,8 @@ object Extension { val libVersion = packageInfo.versionName.substringBeforeLast('.').toDouble() if (libVersion < LIB_VERSION_MIN || libVersion > LIB_VERSION_MAX) { throw Exception( - "Lib version is $libVersion, while only versions " + - "$LIB_VERSION_MIN to $LIB_VERSION_MAX are allowed" + "Lib version is $libVersion, while only versions " + + "$LIB_VERSION_MIN to $LIB_VERSION_MAX are allowed" ) } @@ -241,7 +240,7 @@ object Extension { return getCachedImageResponse(saveDir, apkName) { network.client.newCall( - GET(iconUrl) + GET(iconUrl) ).await() } } diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt index 1d9a271..9534abe 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt @@ -20,15 +20,15 @@ import org.kodein.di.singleton import org.slf4j.Logger import xyz.nulldev.androidcompat.AndroidCompat import xyz.nulldev.androidcompat.AndroidCompatInitializer +import xyz.nulldev.ts.config.ApplicationRootDir import xyz.nulldev.ts.config.ConfigKodeinModule import xyz.nulldev.ts.config.GlobalConfigManager -import xyz.nulldev.ts.config.tachideskRootDir import java.io.File private val logger = KotlinLogging.logger {} class ApplicationDirs( - val dataRoot: String = tachideskRootDir() + val dataRoot: String = ApplicationRootDir ) { val extensionsRoot = "$dataRoot/extensions" val thumbnailsRoot = "$dataRoot/thumbnails" @@ -44,9 +44,11 @@ val androidCompat by lazy { AndroidCompat() } fun applicationSetup() { // Application dirs val applicationDirs = ApplicationDirs() - DI.global.addImport(DI.Module("Server") { - bind() with singleton { applicationDirs } - }) + DI.global.addImport( + DI.Module("Server") { + bind() with singleton { applicationDirs } + } + ) // make dirs we need listOf( @@ -58,6 +60,7 @@ fun applicationSetup() { File(it).mkdirs() } + // register Tachidesk's config which is dubbed "ServerConfig" GlobalConfigManager.registerModule( ServerConfig.register(GlobalConfigManager.config) ) diff --git a/server/src/test/kotlin/ir/armor/tachidesk/TestExtensions.kt b/server/src/test/kotlin/ir/armor/tachidesk/TestExtensions.kt index 716d042..15085cc 100644 --- a/server/src/test/kotlin/ir/armor/tachidesk/TestExtensions.kt +++ b/server/src/test/kotlin/ir/armor/tachidesk/TestExtensions.kt @@ -75,9 +75,11 @@ class TestExtensions { semaphore.withPermit { logger.info { "$index - Now fetching popular manga from $source" } try { - mangaToFetch += source to (source.fetchPopularManga(1) - .awaitSingleRepeat().mangas.firstOrNull() - ?: throw Exception("Source returned no manga")) + mangaToFetch += source to ( + source.fetchPopularManga(1) + .awaitSingleRepeat().mangas.firstOrNull() + ?: throw Exception("Source returned no manga") + ) } catch (e: Exception) { logger.warn { "Failed to fetch popular manga from $source: ${e.message}" } failedToFetch += source to e @@ -185,4 +187,4 @@ class TestExtensions { } return awaitSingle() } -} \ No newline at end of file +} diff --git a/server/src/test/kotlin/ir/armor/tachidesk/TestUtils.kt b/server/src/test/kotlin/ir/armor/tachidesk/TestUtils.kt index 685a6ff..878fbbf 100644 --- a/server/src/test/kotlin/ir/armor/tachidesk/TestUtils.kt +++ b/server/src/test/kotlin/ir/armor/tachidesk/TestUtils.kt @@ -9,4 +9,4 @@ fun setLoggingEnabled(enabled: Boolean = true) { logger.level = if (enabled) { Level.DEBUG } else Level.ERROR -} \ No newline at end of file +}