From e6240557d422234843c428cf8c5bf342c6d60674 Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Tue, 5 Jul 2022 18:30:29 -0500 Subject: [PATCH] Added progress bar to active downloads --- .../launcher/resources/gui/ServerListView.kt | 10 ++++++++++ .../launcher/resources/gui/style/LauncherStyle.kt | 3 +++ .../launcher/services/data/DownloadService.kt | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/projectswg/launcher/resources/gui/ServerListView.kt b/src/main/java/com/projectswg/launcher/resources/gui/ServerListView.kt index 7318323..d6f76f5 100644 --- a/src/main/java/com/projectswg/launcher/resources/gui/ServerListView.kt +++ b/src/main/java/com/projectswg/launcher/resources/gui/ServerListView.kt @@ -144,6 +144,16 @@ class ServerListView : View() { } } } + progressbar { + val updateStatus = LauncherData.INSTANCE.login.activeServerProperty.select { it.updateServerProperty } + visibleWhen { updateStatus.select { it.statusProperty }.select { ReadOnlyBooleanWrapper(it == UpdateServer.UpdateServerStatus.DOWNLOADING) } } + prefHeight = 12.0 + maxHeight = 12.0 + maxWidth = Double.POSITIVE_INFINITY + + progressProperty().bind(updateStatus.select { it.downloadProgressProperty }) + isFillWidth = true + } } button("Play") { // TODO: Get proper string for this isFillWidth = true diff --git a/src/main/java/com/projectswg/launcher/resources/gui/style/LauncherStyle.kt b/src/main/java/com/projectswg/launcher/resources/gui/style/LauncherStyle.kt index fecfe54..40a49b1 100644 --- a/src/main/java/com/projectswg/launcher/resources/gui/style/LauncherStyle.kt +++ b/src/main/java/com/projectswg/launcher/resources/gui/style/LauncherStyle.kt @@ -110,6 +110,9 @@ class Style : Stylesheet() { highlightFill = additionalColorPrimary textFill = textColorPrimary } + s(progressBar child bar) { + backgroundColor += additionalColorSecondary + } // ComboBox, Button, and ScrollBar button styling s( comboBox, diff --git a/src/main/java/com/projectswg/launcher/services/data/DownloadService.kt b/src/main/java/com/projectswg/launcher/services/data/DownloadService.kt index 283ed0e..61e4234 100644 --- a/src/main/java/com/projectswg/launcher/services/data/DownloadService.kt +++ b/src/main/java/com/projectswg/launcher/services/data/DownloadService.kt @@ -89,7 +89,8 @@ class DownloadService : Service() { dataTransferredBinding = dataTransferredBinding.add(downloadAmount) threadPool.execute { download(file, fileLockPool, downloadAmount, running) } } - dpi.server.downloadProgressProperty.bind(dataTransferredBinding.divide(files.stream().mapToLong { it.length }.sum().toDouble())) + val totalDownloadSize = files.stream().mapToLong { it.length }.sum().toDouble() + Platform.runLater { dpi.server.downloadProgressProperty.bind(dataTransferredBinding.divide(totalDownloadSize)) } // Waits for all files to complete, then is able to grab the one remaining lock try {