Skip to content

Commit

Permalink
add error handling when attempting to fetch caches from runestats
Browse files Browse the repository at this point in the history
  • Loading branch information
tpetrychyn committed Jun 23, 2020
1 parent 5d2e589 commit a3fecd5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "org.example"
version = "0.0.1-SNAPSHOT"
version = "0.1.1-SNAPSHOT"

repositories {
mavenCentral()
Expand Down
31 changes: 25 additions & 6 deletions src/main/kotlin/controllers/CacheChooserController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import javafx.collections.ObservableList
import javafx.collections.transformation.FilteredList
import javafx.fxml.FXML
import javafx.fxml.FXMLLoader
import javafx.geometry.Pos
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.scene.control.Button
import javafx.scene.control.Label
import javafx.scene.control.ListView
import javafx.scene.control.TextField
import javafx.scene.text.TextAlignment
import javafx.stage.DirectoryChooser
import javafx.stage.Stage
import javafx.util.Callback
Expand All @@ -31,6 +33,8 @@ import java.io.*
import java.lang.Exception
import java.net.URL
import java.util.*
import javax.net.ssl.SSLEngine
import javax.net.ssl.SSLHandshakeException


class CacheChooserController @Inject constructor(
Expand Down Expand Up @@ -67,13 +71,28 @@ class CacheChooserController @Inject constructor(

@FXML
private fun initialize() {
val doc = Jsoup.connect(RUNESTATS_URL).get()
entries.addAll(doc.select("a")
.map { col -> col.attr("href") }
.filter { it.length > 10 } // get rid of ../ and ./types
.reversed()
)
val listCachesPlaceholder = Label("No downloadable caches found.")
listCachesPlaceholder.isWrapText = true
listCachesPlaceholder.textAlignment = TextAlignment.CENTER
listCaches.placeholder = listCachesPlaceholder

try {
val doc = Jsoup.connect(RUNESTATS_URL).get()
entries.addAll(doc.select("a")
.map { col -> col.attr("href") }
.filter { it.length > 10 } // get rid of ../ and ./types
.reversed()
)
} catch (e: Exception) {
e.printStackTrace()
listCachesPlaceholder.text += "\n\n${e.message}"
if (e is SSLHandshakeException) {
listCachesPlaceholder.text += "\n\nSSLHandshakeException is a known bug with certain Java versions, try updating."
}
}

val filterableEntries = FilteredList(entries)

listCaches.items = filterableEntries

listCaches.selectionModel.selectedItemProperty().addListener { _, _, newValue ->
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/views/about.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Font size="18.0" />
</font>
</Label>
<Label fx:id="lblVersion" alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" text="v0.0.1">
<Label fx:id="lblVersion" alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" text="v0.1.0">
<font>
<Font size="14.0" />
</font>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/views/cache-chooser.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<children>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" text="Caches available from Runestats" textAlignment="CENTER" />
<HBox prefHeight="18.0" prefWidth="200.0">
<children>
<Label alignment="CENTER" text="Filter:">
Expand Down

0 comments on commit a3fecd5

Please sign in to comment.