Skip to content

Commit

Permalink
don't allow source changes while updating
Browse files Browse the repository at this point in the history
  • Loading branch information
DeDiamondPro committed Dec 10, 2024
1 parent 2b1c30f commit e642c74
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of Resourcify
* Copyright (C) 2023 DeDiamondPro
* Copyright (C) 2023-2024 DeDiamondPro
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -35,7 +35,7 @@ class DropDown(
private val placeHolder: String = "",
private val canDeSelect: Boolean = !onlyOneOption
) : UIContainer() {
private val selectionUpdateListeners = mutableListOf<(List<String>) -> Unit>()
private val selectionUpdateListeners = mutableListOf<DropDown.(List<String>) -> Unit>()
private var canOpen = false

private val box = UIBlock(color = Color(0, 0, 0, 200)).constrain {
Expand Down Expand Up @@ -126,11 +126,11 @@ class DropDown(
}
}

private fun updateText() {
fun updateText() {
text.setText(selectedOptions.joinToString().ifBlank { placeHolder })
}

fun onSelectionUpdate(listener: (List<String>) -> Unit): DropDown {
fun onSelectionUpdate(listener: DropDown.(List<String>) -> Unit): DropDown {
selectionUpdateListeners.add(listener)
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ class UpdateCard(
data.keys.map { it.getName() }, onlyOneOption = true,
selectedOptions = mutableListOf(selectedService.getName())
).onSelectionUpdate { newService ->
val downloadUrl = selectedData?.version?.getDownloadUrl()
if (downloadUrl != null && DownloadManager.getProgress(downloadUrl) != null) {
// We are currently downloading an update, don't allow changes
this.selectedOptions.clear()
this.selectedOptions.add(selectedService.getName())
this.updateText()
return@onSelectionUpdate
}

selectedService = data.keys.firstOrNull { it.getName() == newService.first() } ?: return@onSelectionUpdate
selectedData = data[selectedService]

Expand Down

0 comments on commit e642c74

Please sign in to comment.