properly warn if update checking failed

This commit is contained in:
Moritz Zwerger 2023-12-22 23:15:38 +01:00
parent f61a6a5981
commit d77bb34162
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 9 additions and 8 deletions

View File

@ -68,7 +68,7 @@ class AboutController : EmbeddedJavaFXController<HBox>() {
checkUpdatesFX.isDisable = true
DefaultThreadPool += {
try {
val update = MinosoftUpdater.check()
val update = MinosoftUpdater.check(error = true)
if (update == null) {
InfoDialog(i18n("updater.none.title"), i18n("updater.none.header")).show()
}

View File

@ -54,13 +54,13 @@ object MinosoftUpdater {
}
}
fun check(): MinosoftUpdate? {
fun check(error: Boolean = false): MinosoftUpdate? {
val profile = OtherProfileManager.selected.updater
return check(profile.url, profile.channel)
return check(profile.url, profile.channel, error)
}
fun check(url: String, channel: String): MinosoftUpdate? {
fun check(url: String, channel: String, error: Boolean): MinosoftUpdate? {
val commit = MinosoftProperties.git?.commit ?: ""
val version = MinosoftProperties.general.name
val stable = MinosoftProperties.general.stable
@ -77,17 +77,18 @@ object MinosoftUpdater {
)
validateURL(request.toURL())
val update = request(request)
val update = request(request, error)
this.update = update
return update
}
private fun request(url: String): MinosoftUpdate? {
private fun request(url: String, error: Boolean): MinosoftUpdate? {
val response: HTTPResponse<String>
try {
response = url.get({ it })
} catch (error: Throwable) {
Log.log(LogMessageType.OTHER, LogLevels.WARN) { "Could not check for updates: $error" }
} catch (exception: Throwable) {
Log.log(LogMessageType.OTHER, LogLevels.WARN) { "Could not check for updates: $exception" }
if (error) throw exception
return null
}