mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -05:00
ability to override server.conf with java -D arguments
This commit is contained in:
@@ -1,8 +1,40 @@
|
|||||||
package xyz.nulldev.ts.config
|
package xyz.nulldev.ts.config
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) Contributors to the Suwayomi project
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* 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/. */
|
||||||
|
|
||||||
import com.typesafe.config.Config
|
import com.typesafe.config.Config
|
||||||
|
import io.github.config4k.getValue
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract config module.
|
* Abstract config module.
|
||||||
*/
|
*/
|
||||||
abstract class ConfigModule(config: Config)
|
abstract class ConfigModule(config: Config, moduleName: String = "") {
|
||||||
|
val overridableWithSysProperty = SystemPropertyOverrideDelegate(config, moduleName)
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
println("getting " + "suwayomi.tachidesk.config.$moduleName.${property.name}")
|
||||||
|
val combined = System.getProperty(
|
||||||
|
"suwayomi.tachidesk.config.$moduleName.${property.name}",
|
||||||
|
configValue.toString()
|
||||||
|
)
|
||||||
|
|
||||||
|
val asT = when(T::class.simpleName) {
|
||||||
|
"Int" -> combined.toInt()
|
||||||
|
"Boolean" -> combined.toBoolean()
|
||||||
|
// add more types as needed
|
||||||
|
else -> combined
|
||||||
|
}
|
||||||
|
|
||||||
|
return asT as T
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,30 +8,31 @@ package suwayomi.tachidesk.server
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
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
|
||||||
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) : ConfigModule(config) {
|
class ServerConfig(config: Config, moduleName: String = "") : ConfigModule(config, moduleName) {
|
||||||
val ip: String by config
|
val ip: String by overridableWithSysProperty
|
||||||
val port: Int by config
|
val port: Int by overridableWithSysProperty
|
||||||
|
|
||||||
val webUIEnabled: Boolean = System.getProperty(
|
|
||||||
"suwayomi.tachidesk.server.webUIEnabled", config.getString("webUIEnabled")
|
|
||||||
).toBoolean()
|
|
||||||
|
|
||||||
// proxy
|
// proxy
|
||||||
val socksProxyEnabled: Boolean by config
|
val socksProxyEnabled: Boolean by overridableWithSysProperty
|
||||||
val socksProxyHost: String by config
|
|
||||||
val socksProxyPort: String by config
|
val socksProxyHost: String by overridableWithSysProperty
|
||||||
|
val socksProxyPort: String by overridableWithSysProperty
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
val debugLogsEnabled: Boolean = debugLogsEnabled(GlobalConfigManager.config)
|
val debugLogsEnabled: Boolean = debugLogsEnabled(GlobalConfigManager.config)
|
||||||
val systemTrayEnabled: Boolean by config
|
val systemTrayEnabled: Boolean by overridableWithSysProperty
|
||||||
val initialOpenInBrowserEnabled: Boolean by config
|
|
||||||
|
// webUI
|
||||||
|
val webUIEnabled: Boolean by overridableWithSysProperty
|
||||||
|
val initialOpenInBrowserEnabled: Boolean by overridableWithSysProperty
|
||||||
|
val webUIBrowser: String by overridableWithSysProperty
|
||||||
|
val electronPath: String by overridableWithSysProperty
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun register(config: Config) = ServerConfig(config.getConfig("server"))
|
fun register(config: Config) = ServerConfig(config.getConfig("server"), "server")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,9 @@ object Browser {
|
|||||||
private val electronInstances = mutableListOf<Any>()
|
private val electronInstances = mutableListOf<Any>()
|
||||||
|
|
||||||
fun openInBrowser() {
|
fun openInBrowser() {
|
||||||
|
if (serverConfig.webUIBrowser == ("electron")) {
|
||||||
val openInElectron = System.getProperty("suwayomi.tachidesk.server.webInterface")?.equals("electron")
|
|
||||||
|
|
||||||
if (openInElectron == true) {
|
|
||||||
try {
|
try {
|
||||||
val electronPath = System.getProperty("suwayomi.tachidesk.server.electronPath")!!
|
val electronPath = serverConfig.electronPath
|
||||||
electronInstances.add(ProcessBuilder(electronPath, appBaseUrl).start())
|
electronInstances.add(ProcessBuilder(electronPath, appBaseUrl).start())
|
||||||
} catch (e: Throwable) { // cover both java.lang.Exception and java.lang.Error
|
} catch (e: Throwable) { // cover both java.lang.Exception and java.lang.Error
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
|||||||
@@ -14,3 +14,5 @@ server.systemTrayEnabled = true
|
|||||||
# webUI
|
# webUI
|
||||||
server.webUIEnabled = true
|
server.webUIEnabled = true
|
||||||
server.initialOpenInBrowserEnabled = true
|
server.initialOpenInBrowserEnabled = true
|
||||||
|
server.webUIBrowser = "browser" # "browser" or "electron"
|
||||||
|
server.electronPath = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user