From 13d3c97d4f6a4f92c81d898239d397396d04a712 Mon Sep 17 00:00:00 2001 From: dnutiu Date: Sat, 27 Apr 2024 14:54:07 +0300 Subject: [PATCH] synchronize updateProgressBar --- .../imagetagger/ui/MainPageController.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPageController.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPageController.kt index 502d86d..32eecef 100644 --- a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPageController.kt +++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/MainPageController.kt @@ -191,13 +191,15 @@ class MainPageController { * Updates the progress bar of the UI. */ fun updateProgressBar() { - logger.info("Progress ${processedImageFilesCount.get()}/${imageFilesTotal} ${progressBar.progress}") - progressBar.progress = - ((processedImageFilesCount.incrementAndGet() * 100) / imageFilesTotal).toDouble() / 100.0 - if (processedImageFilesCount.get() == imageFilesTotal) { - progressBar.isVisible = false - cancelButton.isVisible = false - logger.info("Finished processing images.") + synchronized(this) { + logger.info("Progress ${processedImageFilesCount.get()}/${imageFilesTotal} ${progressBar.progress}") + val processedImages = processedImageFilesCount.incrementAndGet() + progressBar.progress = ((processedImages * 100) / imageFilesTotal).toDouble() / 100.0 + if (processedImageFilesCount.get() == imageFilesTotal) { + progressBar.isVisible = false + cancelButton.isVisible = false + logger.info("Finished processing images.") + } } }