Skip to content
This repository has been archived by the owner on Feb 12, 2021. It is now read-only.

Commit

Permalink
[Fix] 修复线程问题所造成的第二次下载控件状态信息不会更改
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonLake committed Aug 1, 2017
1 parent 3fa7d18 commit b952c07
Showing 1 changed file with 4 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,33 +158,15 @@ class OptifineCrawlerGui: Application() {
task.stateProperty().addListener { _, _, newValue -> run {
when(newValue) {
Worker.State.SCHEDULED -> disableBtnGroupButton(disableBtnGroup)
Worker.State.CANCELLED, Worker.State.FAILED, Worker.State.SUCCEEDED -> releaseDownloadGroup()
Worker.State.CANCELLED, Worker.State.FAILED, Worker.State.SUCCEEDED -> disableBtnGroupButton(false)
else -> { }
}
}}
downloadProgress.progressProperty().bind(task.progressProperty())
downloadLabel.textProperty().bind(task.messageProperty())
Thread(task).start()
}

private fun releaseDownloadGroup() {
val service = object: ScheduledService<Unit>() {
override fun createTask(): Task<Unit> {
return object: Task<Unit>() {
override fun call() {
Platform.runLater {
disableBtnGroupButton(false)
downloadProgress.progressProperty().unbind()
downloadProgress.progress = -1.0
downloadLabel.textProperty().unbind()
downloadLabel.text = "No Download"
}
}
}
}
}
service.delay = Duration.seconds(3.0)
service.start()
val thread = Thread(task, "OptifineCrawler Download Task")
thread.isDaemon = true
thread.start()
}

private fun disableBtnGroupButton(state: Boolean) {
Expand Down

0 comments on commit b952c07

Please sign in to comment.