Skip to content

Commit

Permalink
FlareSolverr support
Browse files Browse the repository at this point in the history
  • Loading branch information
Syer10 committed Jan 23, 2024
1 parent 979a5ec commit f84de40
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class LauncherViewModel {
// Local Source
val localSourcePath = config.asStateFlow { it.localSourcePath }

// Cloudflare bypass
val flareSolverrEnabled = config.asStateFlow { it.flareSolverrEnabled }
val flareSolverrUrl = config.asStateFlow { it.flareSolverrUrl }
val flareSolverrTimeout = config.asStateFlow { it.flareSolverrTimeout }

val theme = settings.theme().asStateFlow(scope)

fun launch(forceElectron: Boolean = false) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/suwayomi/tachidesk/launcher/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import net.miginfocom.layout.LC
import net.miginfocom.swing.MigLayout
import suwayomi.tachidesk.launcher.ui.Backup
import suwayomi.tachidesk.launcher.ui.BasicAuth
import suwayomi.tachidesk.launcher.ui.Cloudflare
import suwayomi.tachidesk.launcher.ui.Downloader
import suwayomi.tachidesk.launcher.ui.Extension
import suwayomi.tachidesk.launcher.ui.LocalSource
Expand Down Expand Up @@ -110,6 +111,7 @@ suspend fun main() {
addTab("Local Source", LocalSource(vm, scope))
addTab("Requests", Requests(vm, scope))
addTab("Extension", Extension(vm, scope))
addTab("Cloudflare", Cloudflare(vm, scope))
}.bind(CC().grow())
jpanel {
jbutton("Launch") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ class ServerConfig(

// local source
val localSourcePath: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)

// cloudflare bypass
val flareSolverrEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
val flareSolverrUrl: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
val flareSolverrTimeout: MutableStateFlow<Int> by OverrideConfigValue(IntConfigAdapter)
}
81 changes: 81 additions & 0 deletions src/main/kotlin/suwayomi/tachidesk/launcher/ui/Cloudflare.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package suwayomi.tachidesk.launcher.ui

/*
* 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 kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import net.miginfocom.layout.CC
import net.miginfocom.layout.LC
import net.miginfocom.swing.MigLayout
import suwayomi.tachidesk.launcher.KeyListenerEvent
import suwayomi.tachidesk.launcher.LauncherViewModel
import suwayomi.tachidesk.launcher.actions
import suwayomi.tachidesk.launcher.bind
import suwayomi.tachidesk.launcher.changes
import suwayomi.tachidesk.launcher.jCheckBox
import suwayomi.tachidesk.launcher.jSpinner
import suwayomi.tachidesk.launcher.jTextArea
import suwayomi.tachidesk.launcher.jTextField
import suwayomi.tachidesk.launcher.jpanel
import suwayomi.tachidesk.launcher.keyListener
import java.net.URL
import javax.swing.SpinnerNumberModel

fun Cloudflare(vm: LauncherViewModel, scope: CoroutineScope) = jpanel(
MigLayout(
LC().alignX("center").alignY("center")
)
) {
jCheckBox("Use FlareSolverr", selected = vm.flareSolverrEnabled.value) {
toolTipText = "Use FlareSolverr instance to bypass Cloudflare." // todo improve
actions()
.onEach {
vm.flareSolverrEnabled.value = isSelected
}
.flowOn(Dispatchers.Default)
.launchIn(scope)
}.bind(CC().wrap())
jTextArea("FlareSolverr URL") {
isEditable = false
}.bind()
jTextField(vm.flareSolverrUrl.value) {
// todo toolTipText = ""
keyListener()
.filterIsInstance<KeyListenerEvent.Released>()
.map {
text?.trim()
}
.onEach {
if (!it.isNullOrBlank() && runCatching { URL(it).toURI() }.isSuccess) {
vm.flareSolverrUrl.value = it
}
}
.flowOn(Dispatchers.Default)
.launchIn(scope)
columns = 10
}.bind(CC().grow().spanX().wrap())

jTextArea("FlareSolverr timeout") {
isEditable = false
}.bind()
jSpinner(SpinnerNumberModel(vm.flareSolverrTimeout.value.coerceAtLeast(10), 10, Int.MAX_VALUE, 1)) {
toolTipText = "Time limit in seconds for FlareSolverr to run, will fail if it goes over"
changes()
.onEach {
vm.flareSolverrTimeout.value = (value as Int)
}
.flowOn(Dispatchers.Default)
.launchIn(scope)
}.bind(CC().grow().spanX().wrap())
}

0 comments on commit f84de40

Please sign in to comment.