mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 06:42:05 +01:00
Automatic Lint
This commit is contained in:
@@ -71,9 +71,10 @@ internal class StandardPreference<T>(
|
||||
/**
|
||||
* Returns a cold [Flow] of this preference to receive updates when its value changes.
|
||||
*/
|
||||
override fun changes(): Flow<T> = listener
|
||||
.filter { it == key }
|
||||
.map { get() }
|
||||
override fun changes(): Flow<T> =
|
||||
listener
|
||||
.filter { it == key }
|
||||
.map { get() }
|
||||
|
||||
/**
|
||||
* Returns a hot [StateFlow] of this preference bound to the given [scope], allowing to read the
|
||||
|
||||
@@ -51,7 +51,7 @@ interface DataComponent {
|
||||
.serverUrl(
|
||||
URLBuilder(serverPreferences.serverUrl().get())
|
||||
.appendPathSegments("api", "graphql")
|
||||
.buildString()
|
||||
.buildString(),
|
||||
)
|
||||
.ktorClient(http)
|
||||
.build()
|
||||
@@ -90,6 +90,5 @@ interface DataComponent {
|
||||
fun updatesRepository(ktorfit: Ktorfit) = ktorfit.create<UpdatesRepository>()
|
||||
|
||||
@Provides
|
||||
fun settingsRepository(apolloClient: ApolloClient): SettingsRepository =
|
||||
SettingsRepositoryImpl(apolloClient)
|
||||
fun settingsRepository(apolloClient: ApolloClient): SettingsRepository = SettingsRepositoryImpl(apolloClient)
|
||||
}
|
||||
|
||||
@@ -26,154 +26,160 @@ import ca.gosyer.jui.domain.settings.model.WebUIChannel as DomainWebUIChannel
|
||||
import ca.gosyer.jui.domain.settings.model.WebUIFlavor as DomainWebUIFlavor
|
||||
import ca.gosyer.jui.domain.settings.model.WebUIInterface as DomainWebUIInterface
|
||||
|
||||
class SettingsRepositoryImpl(private val apolloClient: ApolloClient) : SettingsRepository {
|
||||
class SettingsRepositoryImpl(
|
||||
private val apolloClient: ApolloClient,
|
||||
) : SettingsRepository {
|
||||
private fun SettingsTypeFragment.toSettings() =
|
||||
Settings(
|
||||
autoDownloadNewChapters = autoDownloadNewChapters,
|
||||
autoDownloadNewChaptersLimit = autoDownloadNewChaptersLimit,
|
||||
backupInterval = backupInterval,
|
||||
backupPath = backupPath,
|
||||
backupTTL = backupTTL,
|
||||
backupTime = backupTime,
|
||||
basicAuthEnabled = basicAuthEnabled,
|
||||
basicAuthPassword = basicAuthPassword,
|
||||
basicAuthUsername = basicAuthUsername,
|
||||
debugLogsEnabled = debugLogsEnabled,
|
||||
downloadAsCbz = downloadAsCbz,
|
||||
downloadsPath = downloadsPath,
|
||||
electronPath = electronPath,
|
||||
excludeCompleted = excludeCompleted,
|
||||
excludeEntryWithUnreadChapters = excludeEntryWithUnreadChapters,
|
||||
excludeNotStarted = excludeNotStarted,
|
||||
excludeUnreadChapters = excludeUnreadChapters,
|
||||
extensionRepos = extensionRepos,
|
||||
flareSolverrEnabled = flareSolverrEnabled,
|
||||
flareSolverrSessionName = flareSolverrSessionName,
|
||||
flareSolverrSessionTtl = flareSolverrSessionTtl,
|
||||
flareSolverrTimeout = flareSolverrTimeout,
|
||||
flareSolverrUrl = flareSolverrUrl,
|
||||
globalUpdateInterval = globalUpdateInterval,
|
||||
gqlDebugLogsEnabled = gqlDebugLogsEnabled,
|
||||
initialOpenInBrowserEnabled = initialOpenInBrowserEnabled,
|
||||
ip = ip,
|
||||
localSourcePath = localSourcePath,
|
||||
maxSourcesInParallel = maxSourcesInParallel,
|
||||
port = port,
|
||||
socksProxyEnabled = socksProxyEnabled,
|
||||
socksProxyHost = socksProxyHost,
|
||||
socksProxyPassword = socksProxyPassword,
|
||||
socksProxyPort = socksProxyPort,
|
||||
socksProxyUsername = socksProxyUsername,
|
||||
socksProxyVersion = socksProxyVersion,
|
||||
systemTrayEnabled = systemTrayEnabled,
|
||||
updateMangas = updateMangas,
|
||||
webUIChannel = webUIChannel.toDomain(),
|
||||
webUIFlavor = webUIFlavor.toDomain(),
|
||||
webUIInterface = webUIInterface.toDomain(),
|
||||
webUIUpdateCheckInterval = webUIUpdateCheckInterval,
|
||||
)
|
||||
|
||||
private fun SettingsTypeFragment.toSettings() = Settings(
|
||||
autoDownloadNewChapters = autoDownloadNewChapters,
|
||||
autoDownloadNewChaptersLimit = autoDownloadNewChaptersLimit,
|
||||
backupInterval = backupInterval,
|
||||
backupPath = backupPath,
|
||||
backupTTL = backupTTL,
|
||||
backupTime = backupTime,
|
||||
basicAuthEnabled = basicAuthEnabled,
|
||||
basicAuthPassword = basicAuthPassword,
|
||||
basicAuthUsername = basicAuthUsername,
|
||||
debugLogsEnabled = debugLogsEnabled,
|
||||
downloadAsCbz = downloadAsCbz,
|
||||
downloadsPath = downloadsPath,
|
||||
electronPath = electronPath,
|
||||
excludeCompleted = excludeCompleted,
|
||||
excludeEntryWithUnreadChapters = excludeEntryWithUnreadChapters,
|
||||
excludeNotStarted = excludeNotStarted,
|
||||
excludeUnreadChapters = excludeUnreadChapters,
|
||||
extensionRepos = extensionRepos,
|
||||
flareSolverrEnabled = flareSolverrEnabled,
|
||||
flareSolverrSessionName = flareSolverrSessionName,
|
||||
flareSolverrSessionTtl = flareSolverrSessionTtl,
|
||||
flareSolverrTimeout = flareSolverrTimeout,
|
||||
flareSolverrUrl = flareSolverrUrl,
|
||||
globalUpdateInterval = globalUpdateInterval,
|
||||
gqlDebugLogsEnabled = gqlDebugLogsEnabled,
|
||||
initialOpenInBrowserEnabled = initialOpenInBrowserEnabled,
|
||||
ip = ip,
|
||||
localSourcePath = localSourcePath,
|
||||
maxSourcesInParallel = maxSourcesInParallel,
|
||||
port = port,
|
||||
socksProxyEnabled = socksProxyEnabled,
|
||||
socksProxyHost = socksProxyHost,
|
||||
socksProxyPassword = socksProxyPassword,
|
||||
socksProxyPort = socksProxyPort,
|
||||
socksProxyUsername = socksProxyUsername,
|
||||
socksProxyVersion = socksProxyVersion,
|
||||
systemTrayEnabled = systemTrayEnabled,
|
||||
updateMangas = updateMangas,
|
||||
webUIChannel = webUIChannel.toDomain(),
|
||||
webUIFlavor = webUIFlavor.toDomain(),
|
||||
webUIInterface = webUIInterface.toDomain(),
|
||||
webUIUpdateCheckInterval = webUIUpdateCheckInterval
|
||||
)
|
||||
private fun WebUIChannel.toDomain() =
|
||||
when (this) {
|
||||
WebUIChannel.BUNDLED -> DomainWebUIChannel.BUNDLED
|
||||
WebUIChannel.STABLE -> DomainWebUIChannel.STABLE
|
||||
WebUIChannel.PREVIEW -> DomainWebUIChannel.PREVIEW
|
||||
WebUIChannel.UNKNOWN__ -> DomainWebUIChannel.UNKNOWN__
|
||||
}
|
||||
|
||||
private fun WebUIChannel.toDomain() = when (this) {
|
||||
WebUIChannel.BUNDLED -> DomainWebUIChannel.BUNDLED
|
||||
WebUIChannel.STABLE -> DomainWebUIChannel.STABLE
|
||||
WebUIChannel.PREVIEW -> DomainWebUIChannel.PREVIEW
|
||||
WebUIChannel.UNKNOWN__ -> DomainWebUIChannel.UNKNOWN__
|
||||
}
|
||||
private fun WebUIFlavor.toDomain() =
|
||||
when (this) {
|
||||
WebUIFlavor.WEBUI -> DomainWebUIFlavor.WEBUI
|
||||
WebUIFlavor.VUI -> DomainWebUIFlavor.VUI
|
||||
WebUIFlavor.CUSTOM -> DomainWebUIFlavor.CUSTOM
|
||||
WebUIFlavor.UNKNOWN__ -> DomainWebUIFlavor.UNKNOWN__
|
||||
}
|
||||
|
||||
private fun WebUIFlavor.toDomain() = when (this) {
|
||||
WebUIFlavor.WEBUI -> DomainWebUIFlavor.WEBUI
|
||||
WebUIFlavor.VUI -> DomainWebUIFlavor.VUI
|
||||
WebUIFlavor.CUSTOM -> DomainWebUIFlavor.CUSTOM
|
||||
WebUIFlavor.UNKNOWN__ -> DomainWebUIFlavor.UNKNOWN__
|
||||
}
|
||||
private fun WebUIInterface.toDomain() =
|
||||
when (this) {
|
||||
WebUIInterface.BROWSER -> DomainWebUIInterface.BROWSER
|
||||
WebUIInterface.ELECTRON -> DomainWebUIInterface.ELECTRON
|
||||
WebUIInterface.UNKNOWN__ -> DomainWebUIInterface.UNKNOWN__
|
||||
}
|
||||
|
||||
private fun WebUIInterface.toDomain() = when (this) {
|
||||
WebUIInterface.BROWSER -> DomainWebUIInterface.BROWSER
|
||||
WebUIInterface.ELECTRON -> DomainWebUIInterface.ELECTRON
|
||||
WebUIInterface.UNKNOWN__ -> DomainWebUIInterface.UNKNOWN__
|
||||
}
|
||||
private fun DomainWebUIChannel.toGraphQL() =
|
||||
when (this) {
|
||||
DomainWebUIChannel.BUNDLED -> WebUIChannel.BUNDLED
|
||||
DomainWebUIChannel.STABLE -> WebUIChannel.STABLE
|
||||
DomainWebUIChannel.PREVIEW -> WebUIChannel.PREVIEW
|
||||
DomainWebUIChannel.UNKNOWN__ -> WebUIChannel.UNKNOWN__
|
||||
}
|
||||
|
||||
private fun DomainWebUIChannel.toGraphQL() = when (this) {
|
||||
DomainWebUIChannel.BUNDLED -> WebUIChannel.BUNDLED
|
||||
DomainWebUIChannel.STABLE -> WebUIChannel.STABLE
|
||||
DomainWebUIChannel.PREVIEW -> WebUIChannel.PREVIEW
|
||||
DomainWebUIChannel.UNKNOWN__ -> WebUIChannel.UNKNOWN__
|
||||
}
|
||||
private fun DomainWebUIFlavor.toGraphQL() =
|
||||
when (this) {
|
||||
DomainWebUIFlavor.WEBUI -> WebUIFlavor.WEBUI
|
||||
DomainWebUIFlavor.VUI -> WebUIFlavor.VUI
|
||||
DomainWebUIFlavor.CUSTOM -> WebUIFlavor.CUSTOM
|
||||
DomainWebUIFlavor.UNKNOWN__ -> WebUIFlavor.UNKNOWN__
|
||||
}
|
||||
|
||||
private fun DomainWebUIFlavor.toGraphQL() = when (this) {
|
||||
DomainWebUIFlavor.WEBUI -> WebUIFlavor.WEBUI
|
||||
DomainWebUIFlavor.VUI -> WebUIFlavor.VUI
|
||||
DomainWebUIFlavor.CUSTOM -> WebUIFlavor.CUSTOM
|
||||
DomainWebUIFlavor.UNKNOWN__ -> WebUIFlavor.UNKNOWN__
|
||||
}
|
||||
private fun DomainWebUIInterface.toGraphQL() =
|
||||
when (this) {
|
||||
DomainWebUIInterface.BROWSER -> WebUIInterface.BROWSER
|
||||
DomainWebUIInterface.ELECTRON -> WebUIInterface.ELECTRON
|
||||
DomainWebUIInterface.UNKNOWN__ -> WebUIInterface.UNKNOWN__
|
||||
}
|
||||
|
||||
private fun DomainWebUIInterface.toGraphQL() = when (this) {
|
||||
DomainWebUIInterface.BROWSER -> WebUIInterface.BROWSER
|
||||
DomainWebUIInterface.ELECTRON -> WebUIInterface.ELECTRON
|
||||
DomainWebUIInterface.UNKNOWN__ -> WebUIInterface.UNKNOWN__
|
||||
}
|
||||
|
||||
override fun getSettings(): Flow<Settings> {
|
||||
return apolloClient.query(AllSettingsQuery()).toFlow()
|
||||
override fun getSettings(): Flow<Settings> =
|
||||
apolloClient.query(AllSettingsQuery()).toFlow()
|
||||
.map {
|
||||
it.dataOrThrow().settings.settingsTypeFragment.toSettings()
|
||||
}
|
||||
.flowOn(Dispatchers.IO)
|
||||
}
|
||||
|
||||
private fun SetSettingsInput.toMutation() =
|
||||
SetSettingsMutation(
|
||||
autoDownloadNewChapters = autoDownloadNewChapters.toOptional(),
|
||||
autoDownloadNewChaptersLimit = autoDownloadNewChaptersLimit.toOptional(),
|
||||
backupInterval = backupInterval.toOptional(),
|
||||
backupPath = backupPath.toOptional(),
|
||||
backupTTL = backupTTL.toOptional(),
|
||||
backupTime = backupTime.toOptional(),
|
||||
basicAuthEnabled = basicAuthEnabled.toOptional(),
|
||||
basicAuthPassword = basicAuthPassword.toOptional(),
|
||||
basicAuthUsername = basicAuthUsername.toOptional(),
|
||||
debugLogsEnabled = debugLogsEnabled.toOptional(),
|
||||
downloadAsCbz = downloadAsCbz.toOptional(),
|
||||
downloadsPath = downloadsPath.toOptional(),
|
||||
electronPath = electronPath.toOptional(),
|
||||
excludeCompleted = excludeCompleted.toOptional(),
|
||||
excludeEntryWithUnreadChapters = excludeEntryWithUnreadChapters.toOptional(),
|
||||
excludeNotStarted = excludeNotStarted.toOptional(),
|
||||
excludeUnreadChapters = excludeUnreadChapters.toOptional(),
|
||||
extensionRepos = extensionRepos.toOptional(),
|
||||
flareSolverrEnabled = flareSolverrEnabled.toOptional(),
|
||||
flareSolverrSessionName = flareSolverrSessionName.toOptional(),
|
||||
flareSolverrSessionTtl = flareSolverrSessionTtl.toOptional(),
|
||||
flareSolverrTimeout = flareSolverrTimeout.toOptional(),
|
||||
flareSolverrUrl = flareSolverrUrl.toOptional(),
|
||||
globalUpdateInterval = globalUpdateInterval.toOptional(),
|
||||
gqlDebugLogsEnabled = gqlDebugLogsEnabled.toOptional(),
|
||||
initialOpenInBrowserEnabled = initialOpenInBrowserEnabled.toOptional(),
|
||||
ip = ip.toOptional(),
|
||||
localSourcePath = localSourcePath.toOptional(),
|
||||
maxSourcesInParallel = maxSourcesInParallel.toOptional(),
|
||||
port = port.toOptional(),
|
||||
socksProxyEnabled = socksProxyEnabled.toOptional(),
|
||||
socksProxyHost = socksProxyHost.toOptional(),
|
||||
socksProxyPassword = socksProxyPassword.toOptional(),
|
||||
socksProxyPort = socksProxyPort.toOptional(),
|
||||
socksProxyUsername = socksProxyUsername.toOptional(),
|
||||
socksProxyVersion = socksProxyVersion.toOptional(),
|
||||
systemTrayEnabled = systemTrayEnabled.toOptional(),
|
||||
updateMangas = updateMangas.toOptional(),
|
||||
webUIChannel = webUIChannel?.toGraphQL().toOptional(),
|
||||
webUIFlavor = webUIFlavor?.toGraphQL().toOptional(),
|
||||
webUIInterface = webUIInterface?.toGraphQL().toOptional(),
|
||||
webUIUpdateCheckInterval = webUIUpdateCheckInterval.toOptional(),
|
||||
)
|
||||
|
||||
private fun SetSettingsInput.toMutation() = SetSettingsMutation(
|
||||
autoDownloadNewChapters = autoDownloadNewChapters.toOptional(),
|
||||
autoDownloadNewChaptersLimit = autoDownloadNewChaptersLimit.toOptional(),
|
||||
backupInterval = backupInterval.toOptional(),
|
||||
backupPath = backupPath.toOptional(),
|
||||
backupTTL = backupTTL.toOptional(),
|
||||
backupTime = backupTime.toOptional(),
|
||||
basicAuthEnabled = basicAuthEnabled.toOptional(),
|
||||
basicAuthPassword = basicAuthPassword.toOptional(),
|
||||
basicAuthUsername = basicAuthUsername.toOptional(),
|
||||
debugLogsEnabled = debugLogsEnabled.toOptional(),
|
||||
downloadAsCbz = downloadAsCbz.toOptional(),
|
||||
downloadsPath = downloadsPath.toOptional(),
|
||||
electronPath = electronPath.toOptional(),
|
||||
excludeCompleted = excludeCompleted.toOptional(),
|
||||
excludeEntryWithUnreadChapters = excludeEntryWithUnreadChapters.toOptional(),
|
||||
excludeNotStarted = excludeNotStarted.toOptional(),
|
||||
excludeUnreadChapters = excludeUnreadChapters.toOptional(),
|
||||
extensionRepos = extensionRepos.toOptional(),
|
||||
flareSolverrEnabled = flareSolverrEnabled.toOptional(),
|
||||
flareSolverrSessionName = flareSolverrSessionName.toOptional(),
|
||||
flareSolverrSessionTtl = flareSolverrSessionTtl.toOptional(),
|
||||
flareSolverrTimeout = flareSolverrTimeout.toOptional(),
|
||||
flareSolverrUrl = flareSolverrUrl.toOptional(),
|
||||
globalUpdateInterval = globalUpdateInterval.toOptional(),
|
||||
gqlDebugLogsEnabled = gqlDebugLogsEnabled.toOptional(),
|
||||
initialOpenInBrowserEnabled = initialOpenInBrowserEnabled.toOptional(),
|
||||
ip = ip.toOptional(),
|
||||
localSourcePath = localSourcePath.toOptional(),
|
||||
maxSourcesInParallel = maxSourcesInParallel.toOptional(),
|
||||
port = port.toOptional(),
|
||||
socksProxyEnabled = socksProxyEnabled.toOptional(),
|
||||
socksProxyHost = socksProxyHost.toOptional(),
|
||||
socksProxyPassword = socksProxyPassword.toOptional(),
|
||||
socksProxyPort = socksProxyPort.toOptional(),
|
||||
socksProxyUsername = socksProxyUsername.toOptional(),
|
||||
socksProxyVersion = socksProxyVersion.toOptional(),
|
||||
systemTrayEnabled = systemTrayEnabled.toOptional(),
|
||||
updateMangas = updateMangas.toOptional(),
|
||||
webUIChannel = webUIChannel?.toGraphQL().toOptional(),
|
||||
webUIFlavor = webUIFlavor?.toGraphQL().toOptional(),
|
||||
webUIInterface = webUIInterface?.toGraphQL().toOptional(),
|
||||
webUIUpdateCheckInterval = webUIUpdateCheckInterval.toOptional(),
|
||||
)
|
||||
|
||||
override fun setSettings(input: SetSettingsInput): Flow<Unit> {
|
||||
return apolloClient.mutation(input.toMutation())
|
||||
override fun setSettings(input: SetSettingsInput): Flow<Unit> =
|
||||
apolloClient.mutation(input.toMutation())
|
||||
.toFlow()
|
||||
.map {
|
||||
it.dataOrThrow()
|
||||
Unit
|
||||
}
|
||||
.flowOn(Dispatchers.IO)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,22 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
actual class ServerHostPreferences actual constructor(
|
||||
@Suppress("unused") private val preferenceStore: PreferenceStore,
|
||||
) {
|
||||
actual fun host(): Preference<Boolean> = object : Preference<Boolean> {
|
||||
override fun key(): String = "host"
|
||||
override fun get(): Boolean = false
|
||||
override fun isSet(): Boolean = false
|
||||
override fun delete() {}
|
||||
override fun defaultValue(): Boolean = false
|
||||
override fun changes(): Flow<Boolean> = MutableStateFlow(false)
|
||||
override fun stateIn(scope: CoroutineScope): StateFlow<Boolean> = MutableStateFlow(false)
|
||||
override fun set(value: Boolean) {}
|
||||
}
|
||||
actual fun host(): Preference<Boolean> =
|
||||
object : Preference<Boolean> {
|
||||
override fun key(): String = "host"
|
||||
|
||||
override fun get(): Boolean = false
|
||||
|
||||
override fun isSet(): Boolean = false
|
||||
|
||||
override fun delete() {}
|
||||
|
||||
override fun defaultValue(): Boolean = false
|
||||
|
||||
override fun changes(): Flow<Boolean> = MutableStateFlow(false)
|
||||
|
||||
override fun stateIn(scope: CoroutineScope): StateFlow<Boolean> = MutableStateFlow(false)
|
||||
|
||||
override fun set(value: Boolean) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,15 @@ class SetSettings
|
||||
constructor(
|
||||
private val settingsRepository: SettingsRepository,
|
||||
) {
|
||||
suspend fun await(input: SetSettingsInput, onError: suspend (Throwable) -> Unit = {}) =
|
||||
asFlow(input)
|
||||
.catch {
|
||||
onError(it)
|
||||
log.warn(it) { "Failed to check for server updates" }
|
||||
}
|
||||
.singleOrNull()
|
||||
suspend fun await(
|
||||
input: SetSettingsInput,
|
||||
onError: suspend (Throwable) -> Unit = {},
|
||||
) = asFlow(input)
|
||||
.catch {
|
||||
onError(it)
|
||||
log.warn(it) { "Failed to check for server updates" }
|
||||
}
|
||||
.singleOrNull()
|
||||
|
||||
fun asFlow(input: SetSettingsInput) = settingsRepository.setSettings(input)
|
||||
|
||||
|
||||
@@ -10,5 +10,5 @@ enum class WebUIChannel {
|
||||
BUNDLED,
|
||||
STABLE,
|
||||
PREVIEW,
|
||||
UNKNOWN__;
|
||||
UNKNOWN__,
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ enum class WebUIFlavor {
|
||||
WEBUI,
|
||||
VUI,
|
||||
CUSTOM,
|
||||
UNKNOWN__;
|
||||
UNKNOWN__,
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@ package ca.gosyer.jui.domain.settings.model
|
||||
enum class WebUIInterface {
|
||||
BROWSER,
|
||||
ELECTRON,
|
||||
UNKNOWN__;
|
||||
UNKNOWN__,
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import ca.gosyer.jui.domain.settings.model.Settings
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface SettingsRepository {
|
||||
|
||||
fun getSettings(): Flow<Settings>
|
||||
|
||||
fun setSettings(input: SetSettingsInput): Flow<Unit>
|
||||
|
||||
@@ -64,6 +64,6 @@ actual class ServerHostPreferences actual constructor(
|
||||
).mapNotNull {
|
||||
it.getProperty()
|
||||
}.plus(
|
||||
"-Dsuwayomi.tachidesk.config.server.initialOpenInBrowserEnabled=false"
|
||||
"-Dsuwayomi.tachidesk.config.server.initialOpenInBrowserEnabled=false",
|
||||
).toTypedArray()
|
||||
}
|
||||
|
||||
@@ -92,19 +92,19 @@ sealed class ServerHostPreference<T : Any> {
|
||||
class BackupPath(
|
||||
preferenceStore: PreferenceStore,
|
||||
) : StringServerHostPreference(
|
||||
preferenceStore,
|
||||
"backupPath",
|
||||
"",
|
||||
)
|
||||
preferenceStore,
|
||||
"backupPath",
|
||||
"",
|
||||
)
|
||||
|
||||
// LocalSource
|
||||
class LocalSourcePath(
|
||||
preferenceStore: PreferenceStore,
|
||||
) : StringServerHostPreference(
|
||||
preferenceStore,
|
||||
"localSourcePath",
|
||||
"",
|
||||
)
|
||||
preferenceStore,
|
||||
"localSourcePath",
|
||||
"",
|
||||
)
|
||||
|
||||
// Authentication
|
||||
class BasicAuthEnabled(
|
||||
|
||||
@@ -16,14 +16,22 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
actual class ServerHostPreferences actual constructor(
|
||||
@Suppress("unused") private val preferenceStore: PreferenceStore,
|
||||
) {
|
||||
actual fun host(): Preference<Boolean> = object : Preference<Boolean> {
|
||||
override fun key(): String = "host"
|
||||
override fun get(): Boolean = false
|
||||
override fun isSet(): Boolean = false
|
||||
override fun delete() {}
|
||||
override fun defaultValue(): Boolean = false
|
||||
override fun changes(): Flow<Boolean> = MutableStateFlow(false)
|
||||
override fun stateIn(scope: CoroutineScope): StateFlow<Boolean> = MutableStateFlow(false)
|
||||
override fun set(value: Boolean) {}
|
||||
}
|
||||
actual fun host(): Preference<Boolean> =
|
||||
object : Preference<Boolean> {
|
||||
override fun key(): String = "host"
|
||||
|
||||
override fun get(): Boolean = false
|
||||
|
||||
override fun isSet(): Boolean = false
|
||||
|
||||
override fun delete() {}
|
||||
|
||||
override fun defaultValue(): Boolean = false
|
||||
|
||||
override fun changes(): Flow<Boolean> = MutableStateFlow(false)
|
||||
|
||||
override fun stateIn(scope: CoroutineScope): StateFlow<Boolean> = MutableStateFlow(false)
|
||||
|
||||
override fun set(value: Boolean) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,6 @@ private class ServerSettingMutableStateFlow<T>(
|
||||
scope: CoroutineScope,
|
||||
private val state: MutableStateFlow<T> = MutableStateFlow(getSetting(parent.value)),
|
||||
) : MutableStateFlow<T> by state {
|
||||
|
||||
init {
|
||||
parent
|
||||
.onEach { state.value = getSetting(it) }
|
||||
@@ -164,184 +163,184 @@ class ServerSettings(
|
||||
private val setSettings: SetSettings,
|
||||
private val scope: CoroutineScope,
|
||||
initial: Settings,
|
||||
private val onError: (String) -> Unit
|
||||
private val onError: (String) -> Unit,
|
||||
) {
|
||||
val settings = MutableStateFlow(initial)
|
||||
|
||||
val autoDownloadNewChapters = getServerFlow(
|
||||
getSetting = { it.autoDownloadNewChapters },
|
||||
getInput = { SetSettingsInput(autoDownloadNewChapters = it) }
|
||||
getInput = { SetSettingsInput(autoDownloadNewChapters = it) },
|
||||
)
|
||||
val autoDownloadNewChaptersLimit = getServerFlow(
|
||||
getSetting = { it.autoDownloadNewChaptersLimit.toString() },
|
||||
getInput = { SetSettingsInput(autoDownloadNewChaptersLimit = it.toIntOrNull()) }
|
||||
getInput = { SetSettingsInput(autoDownloadNewChaptersLimit = it.toIntOrNull()) },
|
||||
)
|
||||
val backupInterval = getServerFlow(
|
||||
getSetting = { it.backupInterval.toString() },
|
||||
getInput = { SetSettingsInput(backupInterval = it.toIntOrNull()) }
|
||||
getInput = { SetSettingsInput(backupInterval = it.toIntOrNull()) },
|
||||
)
|
||||
val backupPath = getServerFlow(
|
||||
getSetting = { it.backupPath },
|
||||
getInput = { SetSettingsInput(backupPath = it) }
|
||||
getInput = { SetSettingsInput(backupPath = it) },
|
||||
)
|
||||
val backupTTL = getServerFlow(
|
||||
getSetting = { it.backupTTL.toString() },
|
||||
getInput = { SetSettingsInput(backupTTL = it.toIntOrNull()) }
|
||||
getInput = { SetSettingsInput(backupTTL = it.toIntOrNull()) },
|
||||
)
|
||||
val backupTime = getServerFlow(
|
||||
getSetting = { it.backupTime },
|
||||
getInput = { SetSettingsInput(backupTime = it) }
|
||||
getInput = { SetSettingsInput(backupTime = it) },
|
||||
)
|
||||
val basicAuthEnabled = getServerFlow(
|
||||
getSetting = { it.basicAuthEnabled },
|
||||
getInput = { SetSettingsInput(basicAuthEnabled = it) }
|
||||
getInput = { SetSettingsInput(basicAuthEnabled = it) },
|
||||
)
|
||||
val basicAuthPassword = getServerFlow(
|
||||
getSetting = { it.basicAuthPassword },
|
||||
getInput = { SetSettingsInput(basicAuthPassword = it) }
|
||||
getInput = { SetSettingsInput(basicAuthPassword = it) },
|
||||
)
|
||||
val basicAuthUsername = getServerFlow(
|
||||
getSetting = { it.basicAuthUsername },
|
||||
getInput = { SetSettingsInput(basicAuthUsername = it) }
|
||||
getInput = { SetSettingsInput(basicAuthUsername = it) },
|
||||
)
|
||||
val debugLogsEnabled = getServerFlow(
|
||||
getSetting = { it.debugLogsEnabled },
|
||||
getInput = { SetSettingsInput(debugLogsEnabled = it) }
|
||||
getInput = { SetSettingsInput(debugLogsEnabled = it) },
|
||||
)
|
||||
val downloadAsCbz = getServerFlow(
|
||||
getSetting = { it.downloadAsCbz },
|
||||
getInput = { SetSettingsInput(downloadAsCbz = it) }
|
||||
getInput = { SetSettingsInput(downloadAsCbz = it) },
|
||||
)
|
||||
val downloadsPath = getServerFlow(
|
||||
getSetting = { it.downloadsPath },
|
||||
getInput = { SetSettingsInput(downloadsPath = it) }
|
||||
getInput = { SetSettingsInput(downloadsPath = it) },
|
||||
)
|
||||
val electronPath = getServerFlow(
|
||||
getSetting = { it.electronPath },
|
||||
getInput = { SetSettingsInput(electronPath = it) }
|
||||
getInput = { SetSettingsInput(electronPath = it) },
|
||||
)
|
||||
val excludeCompleted = getServerFlow(
|
||||
getSetting = { it.excludeCompleted },
|
||||
getInput = { SetSettingsInput(excludeCompleted = it) }
|
||||
getInput = { SetSettingsInput(excludeCompleted = it) },
|
||||
)
|
||||
val excludeEntryWithUnreadChapters = getServerFlow(
|
||||
getSetting = { it.excludeEntryWithUnreadChapters },
|
||||
getInput = { SetSettingsInput(excludeEntryWithUnreadChapters = it) }
|
||||
getInput = { SetSettingsInput(excludeEntryWithUnreadChapters = it) },
|
||||
)
|
||||
val excludeNotStarted = getServerFlow(
|
||||
getSetting = { it.excludeNotStarted },
|
||||
getInput = { SetSettingsInput(excludeNotStarted = it) }
|
||||
getInput = { SetSettingsInput(excludeNotStarted = it) },
|
||||
)
|
||||
val excludeUnreadChapters = getServerFlow(
|
||||
getSetting = { it.excludeUnreadChapters },
|
||||
getInput = { SetSettingsInput(excludeUnreadChapters = it) }
|
||||
getInput = { SetSettingsInput(excludeUnreadChapters = it) },
|
||||
)
|
||||
val extensionRepos = getServerFlow(
|
||||
getSetting = { it.extensionRepos },
|
||||
getInput = { SetSettingsInput(extensionRepos = it) }
|
||||
getInput = { SetSettingsInput(extensionRepos = it) },
|
||||
)
|
||||
val flareSolverrEnabled = getServerFlow(
|
||||
getSetting = { it.flareSolverrEnabled },
|
||||
getInput = { SetSettingsInput(flareSolverrEnabled = it) }
|
||||
getInput = { SetSettingsInput(flareSolverrEnabled = it) },
|
||||
)
|
||||
val flareSolverrSessionName = getServerFlow(
|
||||
getSetting = { it.flareSolverrSessionName },
|
||||
getInput = { SetSettingsInput(flareSolverrSessionName = it) }
|
||||
getInput = { SetSettingsInput(flareSolverrSessionName = it) },
|
||||
)
|
||||
val flareSolverrSessionTtl = getServerFlow(
|
||||
getSetting = { it.flareSolverrSessionTtl.toString() },
|
||||
getInput = { SetSettingsInput(flareSolverrSessionTtl = it.toIntOrNull()) }
|
||||
getInput = { SetSettingsInput(flareSolverrSessionTtl = it.toIntOrNull()) },
|
||||
)
|
||||
val flareSolverrTimeout = getServerFlow(
|
||||
getSetting = { it.flareSolverrTimeout.toString() },
|
||||
getInput = { SetSettingsInput(flareSolverrTimeout = it.toIntOrNull()) }
|
||||
getInput = { SetSettingsInput(flareSolverrTimeout = it.toIntOrNull()) },
|
||||
)
|
||||
val flareSolverrUrl = getServerFlow(
|
||||
getSetting = { it.flareSolverrUrl },
|
||||
getInput = { SetSettingsInput(flareSolverrUrl = it) }
|
||||
getInput = { SetSettingsInput(flareSolverrUrl = it) },
|
||||
)
|
||||
val globalUpdateInterval = getServerFlow(
|
||||
getSetting = { it.globalUpdateInterval.toString() },
|
||||
getInput = { SetSettingsInput(globalUpdateInterval = it.toDoubleOrNull()?.takeIf { it !in 0.01..5.99 }) }
|
||||
getInput = { SetSettingsInput(globalUpdateInterval = it.toDoubleOrNull()?.takeIf { it !in 0.01..5.99 }) },
|
||||
)
|
||||
val gqlDebugLogsEnabled = getServerFlow(
|
||||
getSetting = { it.gqlDebugLogsEnabled },
|
||||
getInput = { SetSettingsInput(gqlDebugLogsEnabled = it) }
|
||||
getInput = { SetSettingsInput(gqlDebugLogsEnabled = it) },
|
||||
)
|
||||
val initialOpenInBrowserEnabled = getServerFlow(
|
||||
getSetting = { it.initialOpenInBrowserEnabled },
|
||||
getInput = { SetSettingsInput(initialOpenInBrowserEnabled = it) }
|
||||
getInput = { SetSettingsInput(initialOpenInBrowserEnabled = it) },
|
||||
)
|
||||
val ip = getServerFlow(
|
||||
getSetting = { it.ip },
|
||||
getInput = { SetSettingsInput(ip = it) }
|
||||
getInput = { SetSettingsInput(ip = it) },
|
||||
)
|
||||
val localSourcePath = getServerFlow(
|
||||
getSetting = { it.localSourcePath },
|
||||
getInput = { SetSettingsInput(localSourcePath = it) }
|
||||
getInput = { SetSettingsInput(localSourcePath = it) },
|
||||
)
|
||||
val maxSourcesInParallel = getServerFlow(
|
||||
getSetting = { it.maxSourcesInParallel.toString() },
|
||||
getInput = { SetSettingsInput(maxSourcesInParallel = it.toIntOrNull()) }
|
||||
getInput = { SetSettingsInput(maxSourcesInParallel = it.toIntOrNull()) },
|
||||
)
|
||||
val port = getServerFlow(
|
||||
getSetting = { it.port.toString() },
|
||||
getInput = { SetSettingsInput(port = it.toIntOrNull()) }
|
||||
getInput = { SetSettingsInput(port = it.toIntOrNull()) },
|
||||
)
|
||||
val socksProxyEnabled = getServerFlow(
|
||||
getSetting = { it.socksProxyEnabled },
|
||||
getInput = { SetSettingsInput(socksProxyEnabled = it) }
|
||||
getInput = { SetSettingsInput(socksProxyEnabled = it) },
|
||||
)
|
||||
val socksProxyHost = getServerFlow(
|
||||
getSetting = { it.socksProxyHost },
|
||||
getInput = { SetSettingsInput(socksProxyHost = it) }
|
||||
getInput = { SetSettingsInput(socksProxyHost = it) },
|
||||
)
|
||||
val socksProxyPassword = getServerFlow(
|
||||
getSetting = { it.socksProxyPassword },
|
||||
getInput = { SetSettingsInput(socksProxyPassword = it) }
|
||||
getInput = { SetSettingsInput(socksProxyPassword = it) },
|
||||
)
|
||||
val socksProxyPort = getServerFlow(
|
||||
getSetting = { it.socksProxyPort },
|
||||
getInput = { SetSettingsInput(socksProxyPort = it) }
|
||||
getInput = { SetSettingsInput(socksProxyPort = it) },
|
||||
)
|
||||
val socksProxyUsername = getServerFlow(
|
||||
getSetting = { it.socksProxyUsername },
|
||||
getInput = { SetSettingsInput(socksProxyUsername = it) }
|
||||
getInput = { SetSettingsInput(socksProxyUsername = it) },
|
||||
)
|
||||
val socksProxyVersion = getServerFlow(
|
||||
getSetting = { it.socksProxyVersion },
|
||||
getInput = { SetSettingsInput(socksProxyVersion = it) }
|
||||
getInput = { SetSettingsInput(socksProxyVersion = it) },
|
||||
)
|
||||
val systemTrayEnabled = getServerFlow(
|
||||
getSetting = { it.systemTrayEnabled },
|
||||
getInput = { SetSettingsInput(systemTrayEnabled = it) }
|
||||
getInput = { SetSettingsInput(systemTrayEnabled = it) },
|
||||
)
|
||||
val updateMangas = getServerFlow(
|
||||
getSetting = { it.updateMangas },
|
||||
getInput = { SetSettingsInput(updateMangas = it) }
|
||||
getInput = { SetSettingsInput(updateMangas = it) },
|
||||
)
|
||||
val webUIChannel = getServerFlow(
|
||||
getSetting = { it.webUIChannel },
|
||||
getInput = { SetSettingsInput(webUIChannel = it) }
|
||||
getInput = { SetSettingsInput(webUIChannel = it) },
|
||||
)
|
||||
val webUIFlavor = getServerFlow(
|
||||
getSetting = { it.webUIFlavor },
|
||||
getInput = { SetSettingsInput(webUIFlavor = it) }
|
||||
getInput = { SetSettingsInput(webUIFlavor = it) },
|
||||
)
|
||||
val webUIInterface = getServerFlow(
|
||||
getSetting = { it.webUIInterface },
|
||||
getInput = { SetSettingsInput(webUIInterface = it) }
|
||||
getInput = { SetSettingsInput(webUIInterface = it) },
|
||||
)
|
||||
val webUIUpdateCheckInterval = getServerFlow(
|
||||
getSetting = { it.webUIUpdateCheckInterval },
|
||||
getInput = { SetSettingsInput(webUIUpdateCheckInterval = it) }
|
||||
getInput = { SetSettingsInput(webUIUpdateCheckInterval = it) },
|
||||
)
|
||||
|
||||
private fun <T> getServerFlow(
|
||||
getSetting: (Settings) -> T,
|
||||
getInput: (T) -> SetSettingsInput,
|
||||
): MutableStateFlow<T> {
|
||||
return ServerSettingMutableStateFlow(
|
||||
): MutableStateFlow<T> =
|
||||
ServerSettingMutableStateFlow(
|
||||
parent = settings,
|
||||
getSetting = getSetting,
|
||||
setSetting = {
|
||||
@@ -349,7 +348,7 @@ class ServerSettings(
|
||||
val input = getInput(it)
|
||||
setSettings.await(
|
||||
input,
|
||||
onError = { onError(it.message.orEmpty()) }
|
||||
onError = { onError(it.message.orEmpty()) },
|
||||
)
|
||||
val response = getSettings.await(onError = { onError(it.message.orEmpty()) })
|
||||
if (response != null) {
|
||||
@@ -359,7 +358,6 @@ class ServerSettings(
|
||||
},
|
||||
scope = scope,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsServerViewModel
|
||||
@@ -598,7 +596,7 @@ fun LazyListScope.ServerSettingsItems(
|
||||
preference = serverSettings.ip,
|
||||
title = stringResource(MR.strings.host_ip),
|
||||
subtitle = stringResource(MR.strings.host_ip_sub, ipValue),
|
||||
enabled = !hosted
|
||||
enabled = !hosted,
|
||||
)
|
||||
}
|
||||
item {
|
||||
@@ -607,7 +605,7 @@ fun LazyListScope.ServerSettingsItems(
|
||||
preference = serverSettings.port,
|
||||
title = stringResource(MR.strings.host_port),
|
||||
subtitle = stringResource(MR.strings.host_port_sub, portValue),
|
||||
enabled = !hosted
|
||||
enabled = !hosted,
|
||||
)
|
||||
}
|
||||
item {
|
||||
@@ -615,7 +613,7 @@ fun LazyListScope.ServerSettingsItems(
|
||||
PreferenceRow(
|
||||
stringResource(MR.strings.extension_repos),
|
||||
subtitle = stringResource(MR.strings.extension_repos_sub),
|
||||
onClick = dialog::show
|
||||
onClick = dialog::show,
|
||||
)
|
||||
val repos by serverSettings.extensionRepos.collectAsState()
|
||||
ExtensionReposDialog(
|
||||
@@ -623,7 +621,7 @@ fun LazyListScope.ServerSettingsItems(
|
||||
repos,
|
||||
onSetRepos = {
|
||||
serverSettings.extensionRepos.value = it
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
item {
|
||||
@@ -675,7 +673,7 @@ fun LazyListScope.ServerSettingsItems(
|
||||
preference = serverSettings.socksProxyVersion,
|
||||
choices = mapOf(
|
||||
4 to "SOCKS4",
|
||||
5 to "SOCKS5"
|
||||
5 to "SOCKS5",
|
||||
).toImmutableMap(),
|
||||
title = stringResource(MR.strings.host_socks_version),
|
||||
enabled = socksProxyEnabled,
|
||||
@@ -685,7 +683,7 @@ fun LazyListScope.ServerSettingsItems(
|
||||
EditTextPreference(
|
||||
preference = serverSettings.globalUpdateInterval,
|
||||
title = stringResource(MR.strings.global_update_interval),
|
||||
subtitle = stringResource(MR.strings.global_update_interval_sub)
|
||||
subtitle = stringResource(MR.strings.global_update_interval_sub),
|
||||
)
|
||||
}
|
||||
item {
|
||||
@@ -720,7 +718,7 @@ fun LazyListScope.ServerSettingsItems(
|
||||
EditTextPreference(
|
||||
preference = serverSettings.maxSourcesInParallel,
|
||||
title = stringResource(MR.strings.max_sources_parallel),
|
||||
subtitle = stringResource(MR.strings.max_sources_parallel_sub)
|
||||
subtitle = stringResource(MR.strings.max_sources_parallel_sub),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -778,7 +776,7 @@ fun LazyListScope.ServerSettingsItems(
|
||||
preference = serverSettings.initialOpenInBrowserEnabled,
|
||||
title = stringResource(MR.strings.host_open_in_browser),
|
||||
subtitle = stringResource(MR.strings.host_open_in_browser_sub),
|
||||
enabled = !hosted, //webUIEnabledValue,
|
||||
enabled = !hosted, // webUIEnabledValue,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -802,14 +800,14 @@ fun LazyListScope.ServerSettingsItems(
|
||||
PreferenceRow(
|
||||
title = stringResource(MR.strings.backup_time),
|
||||
subtitle = stringResource(MR.strings.backup_time_sub),
|
||||
onClick = dialog::show
|
||||
onClick = dialog::show,
|
||||
)
|
||||
BackupTimeDialog(
|
||||
dialog,
|
||||
backupTime,
|
||||
onSetTime = {
|
||||
serverSettings.backupTime.value = it
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -818,7 +816,7 @@ fun LazyListScope.ServerSettingsItems(
|
||||
preference = serverSettings.basicAuthEnabled,
|
||||
title = stringResource(MR.strings.basic_auth),
|
||||
subtitle = stringResource(MR.strings.host_basic_auth_sub),
|
||||
enabled = !hosted
|
||||
enabled = !hosted,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -888,13 +886,13 @@ private val repoRegex =
|
||||
(
|
||||
"https:\\/\\/(?>www\\.|raw\\.)?(github|githubusercontent)\\.com" +
|
||||
"\\/([^\\/]+)\\/([^\\/]+)(?>(?>\\/tree|\\/blob)?\\/([^\\/\\n]*))?(?>\\/([^\\/\\n]*\\.json)?)?"
|
||||
).toRegex()
|
||||
).toRegex()
|
||||
|
||||
@Composable
|
||||
fun ExtensionReposDialog(
|
||||
state: MaterialDialogState,
|
||||
extensionRepos: List<String>,
|
||||
onSetRepos: (List<String>) -> Unit
|
||||
onSetRepos: (List<String>) -> Unit,
|
||||
) {
|
||||
val repos = remember(state.showing) {
|
||||
extensionRepos.toMutableStateList()
|
||||
@@ -928,7 +926,7 @@ fun ExtensionReposDialog(
|
||||
repos.add(newRepo)
|
||||
newRepo = ""
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
isError = newRepo.isNotBlank() && !repoMatches,
|
||||
)
|
||||
@@ -938,11 +936,11 @@ fun ExtensionReposDialog(
|
||||
newRepo = ""
|
||||
},
|
||||
enabled = repoMatches,
|
||||
modifier = Modifier.weight(1f, fill = false)
|
||||
modifier = Modifier.weight(1f, fill = false),
|
||||
) {
|
||||
Icon(
|
||||
Icons.Rounded.Add,
|
||||
contentDescription = stringResource(MR.strings.action_add)
|
||||
contentDescription = stringResource(MR.strings.action_add),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -963,15 +961,15 @@ fun ExtensionReposDialog(
|
||||
style = MaterialTheme.typography.body1,
|
||||
modifier = Modifier
|
||||
.weight(4f)
|
||||
.wrapContentWidth(Alignment.Start)
|
||||
.wrapContentWidth(Alignment.Start),
|
||||
)
|
||||
IconButton(
|
||||
onClick = { repos.remove(item) },
|
||||
modifier = Modifier.weight(1f, fill = false)
|
||||
modifier = Modifier.weight(1f, fill = false),
|
||||
) {
|
||||
Icon(
|
||||
Icons.Rounded.Delete,
|
||||
contentDescription = stringResource(MR.strings.action_delete)
|
||||
contentDescription = stringResource(MR.strings.action_delete),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -984,11 +982,12 @@ val formatter = LocalTime.Format {
|
||||
char(':')
|
||||
minute()
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BackupTimeDialog(
|
||||
state: MaterialDialogState,
|
||||
backupTime: String,
|
||||
onSetTime: (String) -> Unit
|
||||
onSetTime: (String) -> Unit,
|
||||
) {
|
||||
val time = remember(state.showing) {
|
||||
LocalTime.parse(backupTime, formatter)
|
||||
|
||||
@@ -79,8 +79,10 @@ actual class SettingsServerHostViewModel
|
||||
|
||||
// Downloader
|
||||
val downloadPath = serverHostPreferences.downloadPath().asStateIn(scope)
|
||||
|
||||
// Backup
|
||||
val backupPath = serverHostPreferences.backupPath().asStateIn(scope)
|
||||
|
||||
// LocalSource
|
||||
val localSourcePath = serverHostPreferences.localSourcePath().asStateIn(scope)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user