Add missing settings to gql (#738)

* Add missing settings to gql

* Cleanup updating settings
This commit is contained in:
schroda
2023-10-29 16:02:13 +01:00
committed by GitHub
parent 616ed4637d
commit 05707e29d7
2 changed files with 74 additions and 83 deletions

View File

@@ -1,5 +1,6 @@
package suwayomi.tachidesk.graphql.mutations package suwayomi.tachidesk.graphql.mutations
import kotlinx.coroutines.flow.MutableStateFlow
import suwayomi.tachidesk.graphql.types.PartialSettingsType import suwayomi.tachidesk.graphql.types.PartialSettingsType
import suwayomi.tachidesk.graphql.types.Settings import suwayomi.tachidesk.graphql.types.Settings
import suwayomi.tachidesk.graphql.types.SettingsType import suwayomi.tachidesk.graphql.types.SettingsType
@@ -19,99 +20,68 @@ class SettingsMutation {
val settings: SettingsType, val settings: SettingsType,
) )
private fun <SettingType : Any> updateSetting(
newSetting: SettingType?,
configSetting: MutableStateFlow<SettingType>,
) {
if (newSetting == null) {
return
}
configSetting.value = newSetting
}
private fun updateSettings(settings: Settings) { private fun updateSettings(settings: Settings) {
if (settings.ip != null) serverConfig.ip.value = settings.ip!! updateSetting(settings.ip, serverConfig.ip)
if (settings.port != null) serverConfig.port.value = settings.port!! updateSetting(settings.port, serverConfig.port)
if (settings.socksProxyEnabled != null) { // proxy
serverConfig.socksProxyEnabled.value = settings.socksProxyEnabled!! updateSetting(settings.socksProxyEnabled, serverConfig.socksProxyEnabled)
} updateSetting(settings.socksProxyHost, serverConfig.socksProxyHost)
if (settings.socksProxyHost != null) { updateSetting(settings.socksProxyPort, serverConfig.socksProxyPort)
serverConfig.socksProxyHost.value = settings.socksProxyHost!!
}
if (settings.socksProxyPort != null) {
serverConfig.socksProxyPort.value = settings.socksProxyPort!!
}
if (settings.webUIFlavor != null) { // webUI
serverConfig.webUIFlavor.value = settings.webUIFlavor!!.uiName updateSetting(settings.webUIFlavor?.uiName, serverConfig.webUIFlavor)
} updateSetting(settings.initialOpenInBrowserEnabled, serverConfig.initialOpenInBrowserEnabled)
if (settings.initialOpenInBrowserEnabled != null) { updateSetting(settings.webUIInterface?.name?.lowercase(), serverConfig.webUIInterface)
serverConfig.initialOpenInBrowserEnabled.value = settings.initialOpenInBrowserEnabled!! updateSetting(settings.electronPath, serverConfig.electronPath)
} updateSetting(settings.webUIChannel?.name?.lowercase(), serverConfig.webUIChannel)
if (settings.webUIInterface != null) { updateSetting(settings.webUIUpdateCheckInterval, serverConfig.webUIUpdateCheckInterval)
serverConfig.webUIInterface.value = settings.webUIInterface!!.name.lowercase()
}
if (settings.electronPath != null) {
serverConfig.electronPath.value = settings.electronPath!!
}
if (settings.webUIChannel != null) {
serverConfig.webUIChannel.value = settings.webUIChannel!!.name.lowercase()
}
if (settings.webUIUpdateCheckInterval != null) {
serverConfig.webUIUpdateCheckInterval.value = settings.webUIUpdateCheckInterval!!
}
if (settings.downloadAsCbz != null) { // downloader
serverConfig.downloadAsCbz.value = settings.downloadAsCbz!! updateSetting(settings.downloadAsCbz, serverConfig.downloadAsCbz)
} updateSetting(settings.downloadsPath, serverConfig.downloadsPath)
if (settings.downloadsPath != null) { updateSetting(settings.autoDownloadNewChapters, serverConfig.autoDownloadNewChapters)
serverConfig.downloadsPath.value = settings.downloadsPath!! updateSetting(settings.excludeEntryWithUnreadChapters, serverConfig.excludeEntryWithUnreadChapters)
} updateSetting(settings.autoDownloadAheadLimit, serverConfig.autoDownloadAheadLimit)
if (settings.autoDownloadNewChapters != null) {
serverConfig.autoDownloadNewChapters.value = settings.autoDownloadNewChapters!!
}
if (settings.maxSourcesInParallel != null) { // requests
serverConfig.maxSourcesInParallel.value = settings.maxSourcesInParallel!! updateSetting(settings.maxSourcesInParallel, serverConfig.maxSourcesInParallel)
}
if (settings.excludeUnreadChapters != null) { // updater
serverConfig.excludeUnreadChapters.value = settings.excludeUnreadChapters!! updateSetting(settings.excludeUnreadChapters, serverConfig.excludeUnreadChapters)
} updateSetting(settings.excludeNotStarted, serverConfig.excludeNotStarted)
if (settings.excludeNotStarted != null) { updateSetting(settings.excludeCompleted, serverConfig.excludeCompleted)
serverConfig.excludeNotStarted.value = settings.excludeNotStarted!! updateSetting(settings.globalUpdateInterval, serverConfig.globalUpdateInterval)
}
if (settings.excludeCompleted != null) {
serverConfig.excludeCompleted.value = settings.excludeCompleted!!
}
if (settings.globalUpdateInterval != null) {
serverConfig.globalUpdateInterval.value = settings.globalUpdateInterval!!
}
if (settings.basicAuthEnabled != null) { // Authentication
serverConfig.basicAuthEnabled.value = settings.basicAuthEnabled!! updateSetting(settings.basicAuthEnabled, serverConfig.basicAuthEnabled)
} updateSetting(settings.basicAuthUsername, serverConfig.basicAuthUsername)
if (settings.basicAuthUsername != null) { updateSetting(settings.basicAuthPassword, serverConfig.basicAuthPassword)
serverConfig.basicAuthUsername.value = settings.basicAuthUsername!!
}
if (settings.basicAuthPassword != null) {
serverConfig.basicAuthPassword.value = settings.basicAuthPassword!!
}
if (settings.debugLogsEnabled != null) { // misc
serverConfig.debugLogsEnabled.value = settings.debugLogsEnabled!! updateSetting(settings.debugLogsEnabled, serverConfig.debugLogsEnabled)
} updateSetting(settings.gqlDebugLogsEnabled, serverConfig.gqlDebugLogsEnabled)
if (settings.systemTrayEnabled != null) { updateSetting(settings.systemTrayEnabled, serverConfig.systemTrayEnabled)
serverConfig.systemTrayEnabled.value = settings.systemTrayEnabled!!
}
if (settings.backupPath != null) { // backup
serverConfig.backupPath.value = settings.backupPath!! updateSetting(settings.backupPath, serverConfig.backupPath)
} updateSetting(settings.backupTime, serverConfig.backupTime)
if (settings.backupTime != null) { updateSetting(settings.backupInterval, serverConfig.backupInterval)
serverConfig.backupTime.value = settings.backupTime!! updateSetting(settings.backupTTL, serverConfig.backupTTL)
}
if (settings.backupInterval != null) {
serverConfig.backupInterval.value = settings.backupInterval!!
}
if (settings.backupTTL != null) {
serverConfig.backupTTL.value = settings.backupTTL!!
}
if (settings.localSourcePath != null) { // local source
serverConfig.localSourcePath.value = settings.localSourcePath!! updateSetting(settings.localSourcePath, serverConfig.localSourcePath)
}
} }
fun setSettings(input: SetSettingsInput): SetSettingsPayload { fun setSettings(input: SetSettingsInput): SetSettingsPayload {

View File

@@ -37,6 +37,8 @@ interface Settings : Node {
val downloadAsCbz: Boolean? val downloadAsCbz: Boolean?
val downloadsPath: String? val downloadsPath: String?
val autoDownloadNewChapters: Boolean? val autoDownloadNewChapters: Boolean?
val excludeEntryWithUnreadChapters: Boolean?
val autoDownloadAheadLimit: Int?
// requests // requests
val maxSourcesInParallel: Int? val maxSourcesInParallel: Int?
@@ -54,6 +56,7 @@ interface Settings : Node {
// misc // misc
val debugLogsEnabled: Boolean? val debugLogsEnabled: Boolean?
val gqlDebugLogsEnabled: Boolean?
val systemTrayEnabled: Boolean? val systemTrayEnabled: Boolean?
// backup // backup
@@ -84,6 +87,8 @@ data class PartialSettingsType(
override val downloadAsCbz: Boolean?, override val downloadAsCbz: Boolean?,
override val downloadsPath: String?, override val downloadsPath: String?,
override val autoDownloadNewChapters: Boolean?, override val autoDownloadNewChapters: Boolean?,
override val excludeEntryWithUnreadChapters: Boolean?,
override val autoDownloadAheadLimit: Int?,
// requests // requests
override val maxSourcesInParallel: Int?, override val maxSourcesInParallel: Int?,
// updater // updater
@@ -97,6 +102,7 @@ data class PartialSettingsType(
override val basicAuthPassword: String?, override val basicAuthPassword: String?,
// misc // misc
override val debugLogsEnabled: Boolean?, override val debugLogsEnabled: Boolean?,
override val gqlDebugLogsEnabled: Boolean?,
override val systemTrayEnabled: Boolean?, override val systemTrayEnabled: Boolean?,
// backup // backup
override val backupPath: String?, override val backupPath: String?,
@@ -125,6 +131,8 @@ class SettingsType(
override val downloadAsCbz: Boolean, override val downloadAsCbz: Boolean,
override val downloadsPath: String, override val downloadsPath: String,
override val autoDownloadNewChapters: Boolean, override val autoDownloadNewChapters: Boolean,
override val excludeEntryWithUnreadChapters: Boolean?,
override val autoDownloadAheadLimit: Int?,
// requests // requests
override val maxSourcesInParallel: Int, override val maxSourcesInParallel: Int,
// updater // updater
@@ -138,6 +146,7 @@ class SettingsType(
override val basicAuthPassword: String, override val basicAuthPassword: String,
// misc // misc
override val debugLogsEnabled: Boolean, override val debugLogsEnabled: Boolean,
override val gqlDebugLogsEnabled: Boolean?,
override val systemTrayEnabled: Boolean, override val systemTrayEnabled: Boolean,
// backup // backup
override val backupPath: String, override val backupPath: String,
@@ -150,32 +159,44 @@ class SettingsType(
constructor(config: ServerConfig = serverConfig) : this( constructor(config: ServerConfig = serverConfig) : this(
config.ip.value, config.ip.value,
config.port.value, config.port.value,
// proxy
config.socksProxyEnabled.value, config.socksProxyEnabled.value,
config.socksProxyHost.value, config.socksProxyHost.value,
config.socksProxyPort.value, config.socksProxyPort.value,
// webUI
WebUIFlavor.from(config.webUIFlavor.value), WebUIFlavor.from(config.webUIFlavor.value),
config.initialOpenInBrowserEnabled.value, config.initialOpenInBrowserEnabled.value,
WebUIInterface.from(config.webUIInterface.value), WebUIInterface.from(config.webUIInterface.value),
config.electronPath.value, config.electronPath.value,
WebUIChannel.from(config.webUIChannel.value), WebUIChannel.from(config.webUIChannel.value),
config.webUIUpdateCheckInterval.value, config.webUIUpdateCheckInterval.value,
// downloader
config.downloadAsCbz.value, config.downloadAsCbz.value,
config.downloadsPath.value, config.downloadsPath.value,
config.autoDownloadNewChapters.value, config.autoDownloadNewChapters.value,
config.excludeEntryWithUnreadChapters.value,
config.autoDownloadAheadLimit.value,
// requests
config.maxSourcesInParallel.value, config.maxSourcesInParallel.value,
// updater
config.excludeUnreadChapters.value, config.excludeUnreadChapters.value,
config.excludeNotStarted.value, config.excludeNotStarted.value,
config.excludeCompleted.value, config.excludeCompleted.value,
config.globalUpdateInterval.value, config.globalUpdateInterval.value,
// Authentication
config.basicAuthEnabled.value, config.basicAuthEnabled.value,
config.basicAuthUsername.value, config.basicAuthUsername.value,
config.basicAuthPassword.value, config.basicAuthPassword.value,
// misc
config.debugLogsEnabled.value, config.debugLogsEnabled.value,
config.gqlDebugLogsEnabled.value,
config.systemTrayEnabled.value, config.systemTrayEnabled.value,
// backup
config.backupPath.value, config.backupPath.value,
config.backupTime.value, config.backupTime.value,
config.backupInterval.value, config.backupInterval.value,
config.backupTTL.value, config.backupTTL.value,
// local source
config.localSourcePath.value, config.localSourcePath.value,
) )
} }