Skip to content

Commit

Permalink
Fixes for multiple issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Syer10 committed Jun 14, 2024
1 parent cb32643 commit d4d907a
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
kotlin = "1.9.21"
coroutines = "1.7.2"
settings = "1.0.0-RC"
coroutines = "1.8.0"
settings = "1.1.1"
okhttp = "5.0.0-alpha.11"

[libraries]
Expand Down
18 changes: 13 additions & 5 deletions src/main/kotlin/suwayomi/tachidesk/launcher/LauncherViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ package suwayomi.tachidesk.launcher
*/

import ca.gosyer.appdirs.AppDirs
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -119,7 +121,7 @@ class LauncherViewModel {
val theme = settings.theme().asStateFlow(scope)

fun launch(forceElectron: Boolean = false) {
scope.launch(Dispatchers.Main.immediate) {
scope.launch(Dispatchers.Main.immediate) launchMain@{
if (checkIfPortInUse(ip.value, port.value)) {
val option = JOptionPane.showOptionDialog(
null,
Expand All @@ -139,7 +141,7 @@ class LauncherViewModel {
)
when (option) {
0 -> {
return@launch
return@launchMain
}
1 -> Unit
}
Expand All @@ -164,16 +166,18 @@ class LauncherViewModel {
}
}
val java = if (!javaPath.exists()) {
println("Java executable was not found! Defaulting to 'java'")
logger.info { "Java executable was not found! Defaulting to 'java'" }
"java"
} else {
javaPath.absolutePathString()
}

logger.info { "Java path: $java" }

val jarFile = tachideskServer.absolutePathString()
val properties = settings.getProperties().toMutableList()
if (
forceElectron || webUIInterface.value.equals("electron", true) &&
(forceElectron || webUIInterface.value.equals("electron", true)) &&
(electronPath.value.isBlank() || Path(electronPath.value).notExists())
) {
val electronPath = if (os.startsWith("mac os x")) {
Expand All @@ -189,10 +193,11 @@ class LauncherViewModel {
Path("/usr/bin/electron")
}
}
logger.info { "Electron path: ${electronPath.absolutePathString()}" }
if (electronPath.exists()) {
this@LauncherViewModel.electronPath.value = electronPath.absolutePathString()
} else {
println("Electron executable was not found! Disabling Electron")
logger.info { "Electron executable was not found! Disabling Electron" }
this@LauncherViewModel.webUIInterface.value = LauncherSettings.WebUIInterface.Browser.name.lowercase()
}
}
Expand All @@ -201,6 +206,8 @@ class LauncherViewModel {
properties.add(LauncherPreference.argPrefix + "webUIInterface=electron")
}

logger.debug { "Properties:\n" + properties.joinToString(separator = "\n") }
delay(100)
ProcessBuilder(java, *properties.toTypedArray(), "-jar", jarFile).start()
exitProcess(0)
}
Expand Down Expand Up @@ -250,5 +257,6 @@ class LauncherViewModel {
}
}
}
private val logger = KotlinLogging.logger {}
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/suwayomi/tachidesk/launcher/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ suspend fun main() {
}.bind("north")*/

jTabbedPane {
addTab("Root Directory", RootDir(vm, scope))
addTab("Extension", Extension(vm, scope))
addTab("Server bindings", ServerIpAndPortBindings(vm, scope))
addTab("SOCKS Proxy", Socks5(vm, scope))
addTab("Authentication", BasicAuth(vm, scope))
Expand All @@ -110,8 +110,8 @@ suspend fun main() {
addTab("Backup", Backup(vm, scope))
addTab("Local Source", LocalSource(vm, scope))
addTab("Requests", Requests(vm, scope))
addTab("Extension", Extension(vm, scope))
addTab("Cloudflare", Cloudflare(vm, scope))
addTab("Root Directory", RootDir(vm, scope))
}.bind(CC().grow())
jpanel {
jbutton("Launch") {
Expand Down
23 changes: 23 additions & 0 deletions src/main/kotlin/suwayomi/tachidesk/launcher/SwingDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import java.awt.GraphicsConfiguration
import java.awt.LayoutManager
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.awt.event.FocusEvent
import java.awt.event.FocusListener
import java.awt.event.KeyEvent
import java.awt.event.KeyListener
import java.text.Format
Expand Down Expand Up @@ -204,6 +206,27 @@ fun Component.keyListener(): Flow<KeyListenerEvent> = callbackFlow {
awaitClose { removeKeyListener(keyListener) }
}.flowOn(Dispatchers.Swing)

sealed class FocusListenerEvent {
data object Gained : FocusListenerEvent()
data object Lost : FocusListenerEvent()
}

/** Default [FocusListenerEvent] for [Component] */
@SwingDsl
fun Component.focusListener(): Flow<FocusListenerEvent> = callbackFlow {
val focusListener = object : FocusListener {
override fun focusGained(e: FocusEvent?) {
trySend(FocusListenerEvent.Gained)
}

override fun focusLost(e: FocusEvent?) {
trySend(FocusListenerEvent.Lost)
}
}
addFocusListener(focusListener)
awaitClose { removeFocusListener(focusListener) }
}.flowOn(Dispatchers.Swing)

/** Default [ActionEvent] for [AbstractButton] */
@SwingDsl
fun AbstractButton.actions(): Flow<ActionEvent> = callbackFlow {
Expand Down
13 changes: 11 additions & 2 deletions src/main/kotlin/suwayomi/tachidesk/launcher/ui/Backup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package suwayomi.tachidesk.launcher.ui

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.flowOn
Expand All @@ -19,17 +20,20 @@ import kotlinx.coroutines.flow.onEach
import net.miginfocom.layout.CC
import net.miginfocom.layout.LC
import net.miginfocom.swing.MigLayout
import suwayomi.tachidesk.launcher.FocusListenerEvent
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.focusListener
import suwayomi.tachidesk.launcher.jSpinner
import suwayomi.tachidesk.launcher.jTextArea
import suwayomi.tachidesk.launcher.jTextField
import suwayomi.tachidesk.launcher.jbutton
import suwayomi.tachidesk.launcher.jpanel
import suwayomi.tachidesk.launcher.keyListener
import java.awt.event.KeyEvent
import javax.swing.JFileChooser
import javax.swing.SpinnerNumberModel
import javax.swing.UIManager
Expand All @@ -47,8 +51,13 @@ fun Backup(vm: LauncherViewModel, scope: CoroutineScope) = jpanel(
}.bind()
val downloadsPathField = jTextField(vm.backupPath.value) {
// todo toolTipText = ""
keyListener()
.filterIsInstance<KeyListenerEvent.Released>()
focusListener()
.filterIsInstance<FocusListenerEvent.Lost>()
.combine(
keyListener()
.filterIsInstance<KeyListenerEvent.Released>()
.filter { it.event?.keyCode == KeyEvent.VK_ENTER }
) { _, _ -> }
.map {
text?.trim()
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/suwayomi/tachidesk/launcher/ui/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package suwayomi.tachidesk.launcher.ui

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.launchIn
Expand All @@ -18,18 +20,21 @@ import kotlinx.coroutines.flow.onEach
import net.miginfocom.layout.CC
import net.miginfocom.layout.LC
import net.miginfocom.swing.MigLayout
import suwayomi.tachidesk.launcher.FocusListenerEvent
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.focusListener
import suwayomi.tachidesk.launcher.jCheckBox
import suwayomi.tachidesk.launcher.jSpinner
import suwayomi.tachidesk.launcher.jTextArea
import suwayomi.tachidesk.launcher.jTextField
import suwayomi.tachidesk.launcher.jbutton
import suwayomi.tachidesk.launcher.jpanel
import suwayomi.tachidesk.launcher.keyListener
import java.awt.event.KeyEvent
import javax.swing.JFileChooser
import javax.swing.SpinnerNumberModel
import javax.swing.UIManager
Expand All @@ -56,8 +61,13 @@ fun Downloader(vm: LauncherViewModel, scope: CoroutineScope) = jpanel(
}.bind()
val downloadsPathField = jTextField(vm.downloadsPath.value) {
// todo toolTipText = ""
keyListener()
.filterIsInstance<KeyListenerEvent.Released>()
focusListener()
.filterIsInstance<FocusListenerEvent.Lost>()
.combine(
keyListener()
.filterIsInstance<KeyListenerEvent.Released>()
.filter { it.event?.keyCode == KeyEvent.VK_ENTER }
) { _, _ -> }
.map {
text?.trim()
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/suwayomi/tachidesk/launcher/ui/LocalSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package suwayomi.tachidesk.launcher.ui

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.launchIn
Expand All @@ -18,15 +20,18 @@ import kotlinx.coroutines.flow.onEach
import net.miginfocom.layout.CC
import net.miginfocom.layout.LC
import net.miginfocom.swing.MigLayout
import suwayomi.tachidesk.launcher.FocusListenerEvent
import suwayomi.tachidesk.launcher.KeyListenerEvent
import suwayomi.tachidesk.launcher.LauncherViewModel
import suwayomi.tachidesk.launcher.actions
import suwayomi.tachidesk.launcher.bind
import suwayomi.tachidesk.launcher.focusListener
import suwayomi.tachidesk.launcher.jTextArea
import suwayomi.tachidesk.launcher.jTextField
import suwayomi.tachidesk.launcher.jbutton
import suwayomi.tachidesk.launcher.jpanel
import suwayomi.tachidesk.launcher.keyListener
import java.awt.event.KeyEvent
import javax.swing.JFileChooser
import javax.swing.UIManager
import kotlin.io.path.Path
Expand All @@ -43,8 +48,13 @@ fun LocalSource(vm: LauncherViewModel, scope: CoroutineScope) = jpanel(
}.bind()
val localSourcePathField = jTextField(vm.localSourcePath.value) {
// todo toolTipText = ""
keyListener()
.filterIsInstance<KeyListenerEvent.Released>()
focusListener()
.filterIsInstance<FocusListenerEvent.Lost>()
.combine(
keyListener()
.filterIsInstance<KeyListenerEvent.Released>()
.filter { it.event?.keyCode == KeyEvent.VK_ENTER }
) { _, _ -> }
.map {
text?.trim()
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/suwayomi/tachidesk/launcher/ui/RootDir.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package suwayomi.tachidesk.launcher.ui

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.launchIn
Expand All @@ -18,15 +20,18 @@ import kotlinx.coroutines.flow.onEach
import net.miginfocom.layout.CC
import net.miginfocom.layout.LC
import net.miginfocom.swing.MigLayout
import suwayomi.tachidesk.launcher.FocusListenerEvent
import suwayomi.tachidesk.launcher.KeyListenerEvent
import suwayomi.tachidesk.launcher.LauncherViewModel
import suwayomi.tachidesk.launcher.actions
import suwayomi.tachidesk.launcher.bind
import suwayomi.tachidesk.launcher.focusListener
import suwayomi.tachidesk.launcher.jTextArea
import suwayomi.tachidesk.launcher.jTextField
import suwayomi.tachidesk.launcher.jbutton
import suwayomi.tachidesk.launcher.jpanel
import suwayomi.tachidesk.launcher.keyListener
import java.awt.event.KeyEvent
import javax.swing.JFileChooser
import javax.swing.UIManager
import kotlin.io.path.Path
Expand All @@ -43,8 +48,13 @@ fun RootDir(vm: LauncherViewModel, scope: CoroutineScope) = jpanel(
}.bind()
val rootDirField = jTextField(vm.rootDir.value.orEmpty()) {
// todo toolTipText = ""
keyListener()
.filterIsInstance<KeyListenerEvent.Released>()
focusListener()
.filterIsInstance<FocusListenerEvent.Lost>()
.combine(
keyListener()
.filterIsInstance<KeyListenerEvent.Released>()
.filter { it.event?.keyCode == KeyEvent.VK_ENTER }
) { _, _ -> }
.map {
text?.trim()
}
Expand Down

0 comments on commit d4d907a

Please sign in to comment.