mirror of
https://github.com/dev-claw/vripper-project.git
synced 2026-08-19 08:35:41 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46ddb66dc7 |
@@ -15,8 +15,8 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<revision>6.6.1</revision>
|
||||
<app-version>6.6.1-alpha</app-version>
|
||||
<revision>6.6.2</revision>
|
||||
<app-version>6.6.2-alpha</app-version>
|
||||
<kotlin.version>2.2.20</kotlin.version>
|
||||
<slf4j.version>2.0.16</slf4j.version>
|
||||
<logback.version>1.5.12</logback.version>
|
||||
|
||||
@@ -13,6 +13,7 @@ import me.vripper.gui.components.fragments.SettingsFragment
|
||||
import me.vripper.gui.controller.ActionBarController
|
||||
import me.vripper.gui.controller.PostController
|
||||
import me.vripper.gui.controller.SettingsController
|
||||
import me.vripper.gui.event.GuiEventBus
|
||||
import org.kordamp.ikonli.feather.Feather
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
import tornadofx.*
|
||||
@@ -120,9 +121,27 @@ class ActionBarView : View() {
|
||||
downloadActiveProperty.bind(running.greaterThan(0))
|
||||
|
||||
coroutineScope.launch {
|
||||
actionBarController.onQueueStateUpdate.collect {
|
||||
runLater {
|
||||
running.set(it.running)
|
||||
var job: Job? = null
|
||||
GuiEventBus.events.collect { event ->
|
||||
when (event) {
|
||||
GuiEventBus.LocalSession, GuiEventBus.RemoteSession -> {
|
||||
job = launch {
|
||||
actionBarController.onQueueStateUpdate.collect {
|
||||
runLater {
|
||||
running.set(it.running)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GuiEventBus.ChangingSession -> {
|
||||
job?.cancelAndJoin()
|
||||
runLater {
|
||||
running.set(0)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,13 +50,11 @@ class LoadingView : View("VRipper") {
|
||||
message.set("Unable to connect to ${widgetsController.currentSettings.remoteSessionModel.host}:${widgetsController.currentSettings.remoteSessionModel.port}")
|
||||
return@collect
|
||||
} else if (!check) {
|
||||
println("Version Mismatch")
|
||||
message.set("Version Mismatch, client must be >= 6.6.0")
|
||||
return@collect
|
||||
}
|
||||
}
|
||||
runLater {
|
||||
replaceWith(find<AppView>())
|
||||
val sessionType = if (widgetsController.currentSettings.localSession) {
|
||||
AppManager.start()
|
||||
GuiEventBus.LocalSession
|
||||
@@ -64,8 +62,8 @@ class LoadingView : View("VRipper") {
|
||||
GuiEventBus.RemoteSession
|
||||
}
|
||||
AppEndpointManager.set(sessionType)
|
||||
replaceWith(find<AppView>())
|
||||
runBlocking {
|
||||
println("Publishing $sessionType")
|
||||
GuiEventBus.publishEvent(sessionType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,56 +155,55 @@ class LogTableView : View() {
|
||||
|
||||
|
||||
coroutineScope.launch {
|
||||
launch {
|
||||
GuiEventBus.events.collect {
|
||||
when (it) {
|
||||
GuiEventBus.LocalSession, GuiEventBus.RemoteSession -> {
|
||||
println("Collecting $it from LogTableView")
|
||||
while (isActive) {
|
||||
val result = runCatching { logController.getMaxEventLog() }
|
||||
if (result.isSuccess) {
|
||||
maxLogEvent = result.getOrNull()!!
|
||||
break
|
||||
}
|
||||
}
|
||||
while (isActive) {
|
||||
val result = runCatching { logController.initLogger() }
|
||||
if (result.isSuccess) {
|
||||
break
|
||||
}
|
||||
val jobs = mutableListOf<Job>()
|
||||
GuiEventBus.events.collect { event ->
|
||||
when (event) {
|
||||
GuiEventBus.LocalSession, GuiEventBus.RemoteSession -> {
|
||||
println("Collecting $event from LogTableView")
|
||||
while (isActive) {
|
||||
val result = runCatching { logController.getMaxEventLog() }
|
||||
if (result.isSuccess) {
|
||||
maxLogEvent = result.getOrNull()!!
|
||||
break
|
||||
}
|
||||
}
|
||||
while (isActive) {
|
||||
val result = runCatching { logController.initLogger() }
|
||||
if (result.isSuccess) {
|
||||
break
|
||||
}
|
||||
}
|
||||
launch {
|
||||
logController.newLogs.collect {
|
||||
runLater {
|
||||
items.sortWith(Comparator.comparing { it.sequence })
|
||||
while (items.isNotEmpty() && (items.size >= maxLogEvent)) {
|
||||
items.removeFirst()
|
||||
}
|
||||
items.add(it)
|
||||
tableView.sort()
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
logController.updateSettings.collect {
|
||||
maxLogEvent = it.systemSettings.maxEventLog
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
}
|
||||
|
||||
GuiEventBus.ChangingSession -> runLater {
|
||||
GuiEventBus.ChangingSession -> {
|
||||
jobs.forEach { it.cancelAndJoin() }
|
||||
runLater {
|
||||
items.clear()
|
||||
tableView.placeholder = Label("Loading")
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
logController.newLogs.collect {
|
||||
runLater {
|
||||
items.sortWith(Comparator.comparing { it.sequence })
|
||||
while (items.isNotEmpty() && (items.size >= maxLogEvent)) {
|
||||
items.removeFirst()
|
||||
}
|
||||
items.add(it)
|
||||
tableView.sort()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
logController.updateSettings.collect {
|
||||
maxLogEvent = it.systemSettings.maxEventLog
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
println("${this.javaClass.name} init")
|
||||
}
|
||||
|
||||
private fun openLog(item: LogModel) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import me.vripper.gui.controller.ActionBarController
|
||||
import me.vripper.gui.controller.PostController
|
||||
import me.vripper.gui.controller.SettingsController
|
||||
import me.vripper.gui.controller.WidgetsController
|
||||
import me.vripper.gui.event.GuiEventBus
|
||||
import me.vripper.gui.utils.openLink
|
||||
import me.vripper.services.IAppEndpointService
|
||||
import me.vripper.utilities.ApplicationProperties
|
||||
@@ -271,9 +272,27 @@ class MenuBarView : View() {
|
||||
downloadActiveProperty.bind(running.greaterThan(0))
|
||||
|
||||
coroutineScope.launch {
|
||||
actionBarController.onQueueStateUpdate.collect {
|
||||
runLater {
|
||||
running.set(it.running)
|
||||
var job: Job? = null
|
||||
GuiEventBus.events.collect { event ->
|
||||
when (event) {
|
||||
GuiEventBus.LocalSession, GuiEventBus.RemoteSession -> {
|
||||
job = launch {
|
||||
actionBarController.onQueueStateUpdate.collect {
|
||||
runLater {
|
||||
running.set(it.running)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GuiEventBus.ChangingSession -> {
|
||||
job?.cancelAndJoin()
|
||||
runLater {
|
||||
running.set(0)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,8 @@ package me.vripper.gui.components.views
|
||||
|
||||
import javafx.collections.FXCollections
|
||||
import javafx.scene.control.TabPane
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.launch
|
||||
import me.vripper.gui.controller.PostController
|
||||
import me.vripper.gui.model.PostModel
|
||||
import org.kordamp.ikonli.feather.Feather
|
||||
@@ -20,6 +17,8 @@ class PostInfoView : View() {
|
||||
private val postModel: PostModel = PostModel(
|
||||
-1, -1, "", 0.0, "", "", 0, 0, "", "", "*", "", "", "", emptyList(), emptyList(), "", 0
|
||||
)
|
||||
private var updatePostJob: Job? = null
|
||||
private var updateMetadataJob: Job? = null
|
||||
|
||||
override val root = tabpane()
|
||||
|
||||
@@ -78,6 +77,10 @@ class PostInfoView : View() {
|
||||
}
|
||||
|
||||
fun setPostId(id: Long?) {
|
||||
runBlocking {
|
||||
updatePostJob?.cancelAndJoin()
|
||||
updateMetadataJob?.cancelAndJoin()
|
||||
}
|
||||
imagesTableView.setPostId(id)
|
||||
if (id == null) {
|
||||
postModel.apply {
|
||||
@@ -127,7 +130,7 @@ class PostInfoView : View() {
|
||||
}
|
||||
}
|
||||
}
|
||||
coroutineScope.launch {
|
||||
updatePostJob = coroutineScope.launch {
|
||||
postController.updatePostsFlow.filter {
|
||||
it.id == postModel.id
|
||||
}.collect { post ->
|
||||
@@ -146,7 +149,7 @@ class PostInfoView : View() {
|
||||
}
|
||||
}
|
||||
|
||||
coroutineScope.launch {
|
||||
updateMetadataJob = coroutineScope.launch {
|
||||
postController.updateMetadataFlow.filter {
|
||||
it.postIdRef == postModel.id
|
||||
}.collect {
|
||||
|
||||
@@ -64,6 +64,5 @@ class PostsTabView : View() {
|
||||
delay(1_000)
|
||||
}
|
||||
}
|
||||
println("${this.javaClass.name} init")
|
||||
}
|
||||
}
|
||||
@@ -407,86 +407,83 @@ class PostsTableView : View() {
|
||||
tableView.placeholder = Label("Loading")
|
||||
|
||||
coroutineScope.launch {
|
||||
launch {
|
||||
GuiEventBus.events.collect {
|
||||
when (it) {
|
||||
GuiEventBus.LocalSession, GuiEventBus.RemoteSession -> {
|
||||
println("Collecting $it from PostsTableView")
|
||||
val postModelList = postController.findAllPosts().toList()
|
||||
val queueState = postController.getQueueState()
|
||||
runLater {
|
||||
items.addAll(postModelList)
|
||||
tableView.sort()
|
||||
tableView.placeholder = Label("No content in table")
|
||||
val jobs = mutableListOf<Job>()
|
||||
GuiEventBus.events.collect { event ->
|
||||
when (event) {
|
||||
GuiEventBus.LocalSession, GuiEventBus.RemoteSession -> {
|
||||
println("Collecting $event from PostsTableView")
|
||||
val postModelList = postController.findAllPosts().toList()
|
||||
val queueState = postController.getQueueState()
|
||||
runLater {
|
||||
items.addAll(postModelList)
|
||||
tableView.sort()
|
||||
tableView.placeholder = Label("No content in table")
|
||||
updateQueueState(queueState)
|
||||
}
|
||||
launch {
|
||||
postController.updateMetadataFlow.collect { metadataEntity ->
|
||||
runLater {
|
||||
val postModel = items.find { it.id == metadataEntity.postIdRef } ?: return@runLater
|
||||
|
||||
postModel.altTitles =
|
||||
FXCollections.observableArrayList(metadataEntity.data.resolvedNames)
|
||||
postModel.postedBy = metadataEntity.data.postedBy
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
postController.deletedPostsFlow.collect {
|
||||
runLater {
|
||||
items.items.removeIf { p -> p.id == it }
|
||||
tableView.sort()
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
postController.updatePostsFlow.collect { post ->
|
||||
runLater {
|
||||
val postModel = items.find { it.id == post.id } ?: return@runLater
|
||||
|
||||
postModel.status = post.status.name
|
||||
postModel.progressCount = postController.progressCount(
|
||||
post.total, post.done, post.downloaded
|
||||
)
|
||||
postModel.done = post.done
|
||||
postModel.progress = postController.progress(
|
||||
post.total, post.done
|
||||
)
|
||||
postModel.path = post.getDownloadFolder()
|
||||
postModel.folderName = post.folderName
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
postController.queueStateUpdate.collect { queueState ->
|
||||
updateQueueState(queueState)
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
postController.newPostsFlow.collect {
|
||||
runLater {
|
||||
items.addAll(it)
|
||||
tableView.sort()
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
}
|
||||
|
||||
GuiEventBus.ChangingSession -> runLater {
|
||||
GuiEventBus.ChangingSession -> {
|
||||
jobs.forEach { it.cancelAndJoin() }
|
||||
runLater {
|
||||
tableView.placeholder = Label("Loading")
|
||||
items.clear()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
postController.updateMetadataFlow.collect { metadataEntity ->
|
||||
runLater {
|
||||
val postModel = items.find { it.id == metadataEntity.postIdRef } ?: return@runLater
|
||||
|
||||
postModel.altTitles = FXCollections.observableArrayList(metadataEntity.data.resolvedNames)
|
||||
postModel.postedBy = metadataEntity.data.postedBy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
postController.deletedPostsFlow.collect {
|
||||
runLater {
|
||||
items.items.removeIf { p -> p.id == it }
|
||||
tableView.sort()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
postController.updatePostsFlow.collect { post ->
|
||||
runLater {
|
||||
val postModel = items.find { it.id == post.id } ?: return@runLater
|
||||
|
||||
postModel.status = post.status.name
|
||||
postModel.progressCount = postController.progressCount(
|
||||
post.total, post.done, post.downloaded
|
||||
)
|
||||
postModel.done = post.done
|
||||
postModel.progress = postController.progress(
|
||||
post.total, post.done
|
||||
)
|
||||
postModel.path = post.getDownloadFolder()
|
||||
postModel.folderName = post.folderName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
postController.queueStateUpdate.collect { queueState ->
|
||||
updateQueueState(queueState)
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
postController.newPostsFlow.collect {
|
||||
runLater {
|
||||
items.addAll(it)
|
||||
tableView.sort()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
println("${this.javaClass.name} init")
|
||||
}
|
||||
|
||||
private fun updateQueueState(queueState: QueueState) {
|
||||
|
||||
@@ -26,10 +26,10 @@ class StatusBarView : View("Status bar") {
|
||||
|
||||
init {
|
||||
coroutineScope.launch {
|
||||
GuiEventBus.events.collect {
|
||||
when (it) {
|
||||
val jobs = mutableListOf<Job>()
|
||||
GuiEventBus.events.collect { event ->
|
||||
when (event) {
|
||||
GuiEventBus.LocalSession, GuiEventBus.RemoteSession -> {
|
||||
println("Collecting $it from StatusBarView")
|
||||
while (isActive) {
|
||||
val result = runCatching { statusBarController.loggedInUser() }
|
||||
if (result.isSuccess) {
|
||||
@@ -40,6 +40,54 @@ class StatusBarView : View("Status bar") {
|
||||
}
|
||||
delay(1000)
|
||||
}
|
||||
launch {
|
||||
statusBarController.vgUserUpdate.collect {
|
||||
runLater {
|
||||
loggedUser.set(it)
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
statusBarController.tasksRunning.collect {
|
||||
runLater {
|
||||
tasksRunning.set(it)
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
statusBarController.downloadSpeed.collect {
|
||||
runLater {
|
||||
downloadSpeed.set(it.speed.formatSI())
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
statusBarController.queueStateUpdate.collect {
|
||||
runLater {
|
||||
running.set(it.running)
|
||||
pending.set(it.remaining)
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
statusBarController.errorCountUpdate.collect {
|
||||
runLater {
|
||||
error.set(it.count)
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
}
|
||||
|
||||
GuiEventBus.ChangingSession -> {
|
||||
jobs.forEach { it.cancelAndJoin() }
|
||||
runLater {
|
||||
loggedUser.set("")
|
||||
tasksRunning.set(false)
|
||||
downloadSpeed.set(0L.formatSI())
|
||||
running.set(0)
|
||||
pending.set(0)
|
||||
error.set(0)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
@@ -47,47 +95,6 @@ class StatusBarView : View("Status bar") {
|
||||
}
|
||||
}
|
||||
|
||||
coroutineScope.launch {
|
||||
statusBarController.vgUserUpdate.collect {
|
||||
runLater {
|
||||
loggedUser.set(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coroutineScope.launch {
|
||||
statusBarController.tasksRunning.collect {
|
||||
runLater {
|
||||
tasksRunning.set(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coroutineScope.launch {
|
||||
statusBarController.downloadSpeed.collect {
|
||||
runLater {
|
||||
downloadSpeed.set(it.speed.formatSI())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coroutineScope.launch {
|
||||
statusBarController.queueStateUpdate.collect {
|
||||
runLater {
|
||||
running.set(it.running)
|
||||
pending.set(it.remaining)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coroutineScope.launch {
|
||||
statusBarController.errorCountUpdate.collect {
|
||||
runLater {
|
||||
error.set(it.count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coroutineScope.launch {
|
||||
while (isActive) {
|
||||
val text = when (statusBarController.connectionState()) {
|
||||
|
||||
@@ -7,13 +7,10 @@ import javafx.collections.ObservableList
|
||||
import javafx.scene.control.*
|
||||
import javafx.scene.input.KeyCode
|
||||
import javafx.scene.input.KeyEvent
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.toList
|
||||
import kotlinx.coroutines.javafx.asFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import me.vripper.gui.components.fragments.ThreadSelectionTableFragment
|
||||
import me.vripper.gui.controller.ThreadController
|
||||
import me.vripper.gui.controller.WidgetsController
|
||||
@@ -158,64 +155,61 @@ class ThreadTableView : View() {
|
||||
|
||||
|
||||
coroutineScope.launch {
|
||||
launch {
|
||||
GuiEventBus.events.collect {
|
||||
when (it) {
|
||||
GuiEventBus.LocalSession, GuiEventBus.RemoteSession -> {
|
||||
println("Collecting $it from ThreadTableView")
|
||||
val list = threadController.findAll().toList()
|
||||
runLater {
|
||||
items.clear()
|
||||
items.addAll(list)
|
||||
tableView.placeholder = Label("No content in table")
|
||||
}
|
||||
val jobs = mutableListOf<Job>()
|
||||
GuiEventBus.events.collect { event ->
|
||||
when (event) {
|
||||
GuiEventBus.LocalSession, GuiEventBus.RemoteSession -> {
|
||||
println("Collecting $event from ThreadTableView")
|
||||
val list = threadController.findAll().toList()
|
||||
runLater {
|
||||
items.clear()
|
||||
items.addAll(list)
|
||||
tableView.placeholder = Label("No content in table")
|
||||
}
|
||||
launch {
|
||||
threadController.newThread.collect {
|
||||
runLater {
|
||||
items.add(it)
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
threadController.updateThread.collect { thread ->
|
||||
runLater {
|
||||
val threadModel = items.find { it.threadId == thread.threadId } ?: return@runLater
|
||||
threadModel.total = thread.total
|
||||
threadModel.title = thread.title
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
threadController.deleteThread.collect { threadId ->
|
||||
runLater {
|
||||
tableView.items.removeIf { it.threadId == threadId }
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
launch {
|
||||
threadController.clearThreads.collect {
|
||||
runLater {
|
||||
tableView.items.clear()
|
||||
}
|
||||
}
|
||||
}.also { jobs.add(it) }
|
||||
}
|
||||
|
||||
GuiEventBus.ChangingSession -> runLater {
|
||||
GuiEventBus.ChangingSession -> {
|
||||
jobs.forEach { it.cancelAndJoin() }
|
||||
runLater {
|
||||
tableView.placeholder = Label("Loading")
|
||||
items.clear()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
threadController.newThread.collect {
|
||||
runLater {
|
||||
items.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
threadController.updateThread.collect { thread ->
|
||||
runLater {
|
||||
val threadModel = items.find { it.threadId == thread.threadId } ?: return@runLater
|
||||
threadModel.total = thread.total
|
||||
threadModel.title = thread.title
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
threadController.deleteThread.collect { threadId ->
|
||||
runLater {
|
||||
tableView.items.removeIf { it.threadId == threadId }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
threadController.clearThreads.collect {
|
||||
runLater {
|
||||
tableView.items.clear()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
println("${this.javaClass.name} init")
|
||||
}
|
||||
|
||||
private fun isCurrentTab(): Boolean = mainView.root.selectionModel.selectedItem.id == "thread-tab"
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package me.vripper.gui.controller
|
||||
|
||||
import me.vripper.gui.utils.AppEndpointManager.localAppEndpointService
|
||||
import me.vripper.gui.utils.AppEndpointManager.remoteAppEndpointService
|
||||
import me.vripper.gui.utils.ChannelFlowBuilder
|
||||
import kotlinx.coroutines.flow.cancellable
|
||||
import me.vripper.gui.utils.AppEndpointManager.currentAppEndpointService
|
||||
import tornadofx.Controller
|
||||
|
||||
class ActionBarController : Controller() {
|
||||
|
||||
val onQueueStateUpdate = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onQueueStateUpdate,
|
||||
remoteAppEndpointService::onQueueStateUpdate
|
||||
)
|
||||
val onQueueStateUpdate =
|
||||
currentAppEndpointService().onQueueStateUpdate().cancellable()
|
||||
}
|
||||
@@ -1,26 +1,17 @@
|
||||
package me.vripper.gui.controller
|
||||
|
||||
import kotlinx.coroutines.flow.cancellable
|
||||
import kotlinx.coroutines.flow.map
|
||||
import me.vripper.gui.model.LogModel
|
||||
import me.vripper.gui.utils.AppEndpointManager.currentAppEndpointService
|
||||
import me.vripper.gui.utils.AppEndpointManager.localAppEndpointService
|
||||
import me.vripper.gui.utils.AppEndpointManager.remoteAppEndpointService
|
||||
import me.vripper.gui.utils.ChannelFlowBuilder
|
||||
import me.vripper.model.LogEntry
|
||||
import tornadofx.Controller
|
||||
|
||||
class LogController : Controller() {
|
||||
|
||||
val newLogs = ChannelFlowBuilder.build(
|
||||
{ localAppEndpointService.onNewLog().map(::mapper) },
|
||||
{ remoteAppEndpointService.onNewLog().map(::mapper) }
|
||||
)
|
||||
val newLogs = currentAppEndpointService().onNewLog().map(::mapper).cancellable()
|
||||
|
||||
val updateSettings =
|
||||
ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onUpdateSettings,
|
||||
remoteAppEndpointService::onUpdateSettings
|
||||
)
|
||||
val updateSettings = currentAppEndpointService().onUpdateSettings().cancellable()
|
||||
|
||||
private fun mapper(it: LogEntry): LogModel {
|
||||
return LogModel(
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package me.vripper.gui.controller
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.cancellable
|
||||
import kotlinx.coroutines.flow.map
|
||||
import me.vripper.gui.model.PostModel
|
||||
import me.vripper.gui.utils.AppEndpointManager.currentAppEndpointService
|
||||
import me.vripper.gui.utils.AppEndpointManager.localAppEndpointService
|
||||
import me.vripper.gui.utils.AppEndpointManager.remoteAppEndpointService
|
||||
import me.vripper.gui.utils.ChannelFlowBuilder
|
||||
import me.vripper.gui.utils.ChannelFlowBuilder.toFlow
|
||||
import me.vripper.model.Post
|
||||
import me.vripper.model.QueueState
|
||||
@@ -19,39 +17,15 @@ class PostController : Controller() {
|
||||
|
||||
private val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
|
||||
val updatePostsFlow =
|
||||
ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onUpdatePosts,
|
||||
remoteAppEndpointService::onUpdatePosts
|
||||
)
|
||||
val updatePostsFlow = currentAppEndpointService().onUpdatePosts().cancellable()
|
||||
|
||||
val newPostsFlow = ChannelFlowBuilder.build(
|
||||
{
|
||||
localAppEndpointService.onNewPosts().map { post ->
|
||||
mapper(post)
|
||||
}
|
||||
}, {
|
||||
remoteAppEndpointService.onNewPosts().map { post ->
|
||||
mapper(post)
|
||||
}
|
||||
}
|
||||
)
|
||||
val newPostsFlow = currentAppEndpointService().onNewPosts().map(::mapper).cancellable()
|
||||
|
||||
val deletedPostsFlow =
|
||||
ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onDeletePosts,
|
||||
remoteAppEndpointService::onDeletePosts
|
||||
)
|
||||
val deletedPostsFlow = currentAppEndpointService().onDeletePosts().cancellable()
|
||||
|
||||
val updateMetadataFlow = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onUpdateMetadata,
|
||||
remoteAppEndpointService::onUpdateMetadata,
|
||||
)
|
||||
val updateMetadataFlow = currentAppEndpointService().onUpdateMetadata().cancellable()
|
||||
|
||||
val queueStateUpdate = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onQueueStateUpdate,
|
||||
remoteAppEndpointService::onQueueStateUpdate,
|
||||
)
|
||||
val queueStateUpdate = currentAppEndpointService().onQueueStateUpdate().cancellable()
|
||||
|
||||
suspend fun scan(postLinks: String) {
|
||||
runCatching { currentAppEndpointService().scanLinks(postLinks) }
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package me.vripper.gui.controller
|
||||
|
||||
import kotlinx.coroutines.flow.cancellable
|
||||
import me.vripper.gui.utils.AppEndpointManager.currentAppEndpointService
|
||||
import me.vripper.gui.utils.AppEndpointManager.localAppEndpointService
|
||||
import me.vripper.gui.utils.AppEndpointManager.remoteAppEndpointService
|
||||
import me.vripper.gui.utils.ChannelFlowBuilder
|
||||
import tornadofx.Controller
|
||||
|
||||
class StatusBarController : Controller() {
|
||||
@@ -19,28 +17,13 @@ class StatusBarController : Controller() {
|
||||
return currentAppEndpointService().getVersion()
|
||||
}
|
||||
|
||||
val vgUserUpdate = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onVGUserUpdate,
|
||||
remoteAppEndpointService::onVGUserUpdate,
|
||||
)
|
||||
val vgUserUpdate = currentAppEndpointService().onVGUserUpdate().cancellable()
|
||||
|
||||
val tasksRunning = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onTasksRunning,
|
||||
remoteAppEndpointService::onTasksRunning,
|
||||
)
|
||||
val tasksRunning = currentAppEndpointService().onTasksRunning().cancellable()
|
||||
|
||||
val downloadSpeed = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onDownloadSpeed,
|
||||
remoteAppEndpointService::onDownloadSpeed,
|
||||
)
|
||||
val downloadSpeed = currentAppEndpointService().onDownloadSpeed().cancellable()
|
||||
|
||||
val queueStateUpdate = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onQueueStateUpdate,
|
||||
remoteAppEndpointService::onQueueStateUpdate,
|
||||
)
|
||||
val queueStateUpdate = currentAppEndpointService().onQueueStateUpdate().cancellable()
|
||||
|
||||
val errorCountUpdate = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onErrorCountUpdate,
|
||||
remoteAppEndpointService::onErrorCountUpdate
|
||||
)
|
||||
val errorCountUpdate = currentAppEndpointService().onErrorCountUpdate().cancellable()
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
package me.vripper.gui.controller
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.cancellable
|
||||
import kotlinx.coroutines.flow.map
|
||||
import me.vripper.entities.ThreadEntity
|
||||
import me.vripper.gui.model.ThreadModel
|
||||
import me.vripper.gui.model.ThreadSelectionModel
|
||||
import me.vripper.gui.utils.AppEndpointManager.currentAppEndpointService
|
||||
import me.vripper.gui.utils.AppEndpointManager.localAppEndpointService
|
||||
import me.vripper.gui.utils.AppEndpointManager.remoteAppEndpointService
|
||||
import me.vripper.gui.utils.ChannelFlowBuilder
|
||||
import me.vripper.gui.utils.ChannelFlowBuilder.toFlow
|
||||
import me.vripper.model.ThreadPostId
|
||||
import org.koin.core.component.KoinComponent
|
||||
@@ -16,29 +14,13 @@ import tornadofx.Controller
|
||||
|
||||
class ThreadController : KoinComponent, Controller() {
|
||||
|
||||
val newThread = ChannelFlowBuilder.build(
|
||||
{
|
||||
localAppEndpointService.onNewThread().map(::threadModelMapper)
|
||||
},
|
||||
{
|
||||
remoteAppEndpointService.onNewThread().map(::threadModelMapper)
|
||||
},
|
||||
)
|
||||
val newThread = currentAppEndpointService().onNewThread().map(::threadModelMapper).cancellable()
|
||||
|
||||
val updateThread = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onUpdateThread,
|
||||
remoteAppEndpointService::onUpdateThread,
|
||||
)
|
||||
val updateThread = currentAppEndpointService().onUpdateThread().cancellable()
|
||||
|
||||
val deleteThread = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onDeleteThread,
|
||||
remoteAppEndpointService::onDeleteThread,
|
||||
)
|
||||
val deleteThread = currentAppEndpointService().onDeleteThread().cancellable()
|
||||
|
||||
val clearThreads = ChannelFlowBuilder.build(
|
||||
localAppEndpointService::onClearThreads,
|
||||
remoteAppEndpointService::onClearThreads,
|
||||
)
|
||||
val clearThreads = currentAppEndpointService().onClearThreads().cancellable()
|
||||
|
||||
fun findAll(): Flow<ThreadModel> {
|
||||
return toFlow { currentAppEndpointService().findAllThreads().map(::threadModelMapper) }
|
||||
|
||||
@@ -1,50 +1,13 @@
|
||||
package me.vripper.gui.utils
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.cancellable
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.flow.retryWhen
|
||||
import me.vripper.gui.event.GuiEventBus
|
||||
import kotlinx.coroutines.isActive
|
||||
|
||||
object ChannelFlowBuilder {
|
||||
|
||||
fun <T> build(localFlow: () -> Flow<T>, remoteFlow: () -> Flow<T>): Flow<T> {
|
||||
return channelFlow {
|
||||
var job: Job? = null
|
||||
|
||||
fun collect(localSession: Boolean) {
|
||||
job = if (localSession) {
|
||||
launch {
|
||||
localFlow().cancellable().collect { if (isActive) send(it) }
|
||||
}
|
||||
} else {
|
||||
launch {
|
||||
remoteFlow().cancellable().retryWhen { _, _ ->
|
||||
delay(1000)
|
||||
true
|
||||
}.collect { if (isActive) send(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
GuiEventBus
|
||||
.events
|
||||
.collect {
|
||||
if (job != null && job.isActive) {
|
||||
job.cancelAndJoin()
|
||||
}
|
||||
when (it) {
|
||||
GuiEventBus.LocalSession -> collect(true)
|
||||
GuiEventBus.RemoteSession -> collect(false)
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> toFlow(source: suspend () -> List<T>): Flow<T> {
|
||||
return channelFlow {
|
||||
source().forEach { if (isActive) send(it) }
|
||||
|
||||
@@ -18,8 +18,8 @@ object ClipboardManager : KoinComponent {
|
||||
|
||||
fun init() {
|
||||
coroutineScope.launch {
|
||||
GuiEventBus.events.collect {
|
||||
when (it) {
|
||||
GuiEventBus.events.collect { event ->
|
||||
when (event) {
|
||||
GuiEventBus.LocalSession, GuiEventBus.RemoteSession -> {
|
||||
logger.info("Clipboard manager initialized")
|
||||
while (isActive) {
|
||||
@@ -30,7 +30,6 @@ object ClipboardManager : KoinComponent {
|
||||
}
|
||||
delay(1000)
|
||||
}
|
||||
settingsUpdateJob?.cancelAndJoin()
|
||||
settingsUpdateJob = launch {
|
||||
AppEndpointManager.currentAppEndpointService().onUpdateSettings()
|
||||
.retryWhen { _, _ -> delay(1000); true }.collect {
|
||||
@@ -38,7 +37,9 @@ object ClipboardManager : KoinComponent {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GuiEventBus.ChangingSession -> {
|
||||
settingsUpdateJob?.cancelAndJoin()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,12 +56,6 @@ object PreviewCacheManager : KoinComponent {
|
||||
init {
|
||||
coroutineScope.launch {
|
||||
while (isActive) {
|
||||
// println("Cache state check")
|
||||
// println("Cache entries = ${entries.size}")
|
||||
// println("Cache entries limit = $MAX_ENTRIES")
|
||||
// println("Cache size = ${cacheSize.get().formatSI()}")
|
||||
// println("Cache size LIMIT = ${THRESHOLD.formatSI()}")
|
||||
|
||||
val entriesDelta = entries.size - MAX_ENTRIES
|
||||
if (entriesDelta > 0) {
|
||||
val deleted = mutableListOf<Entry>()
|
||||
@@ -85,8 +79,6 @@ object PreviewCacheManager : KoinComponent {
|
||||
cacheSize.addAndGet(element.size * -1L)
|
||||
} while (cacheSize.get() - THRESHOLD > 0)
|
||||
}
|
||||
|
||||
// println("Cache state check completed")
|
||||
delay(30_000)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user