common: catch errors when opening URLs

This commit is contained in:
Harsh Shandilya 2022-04-07 17:49:34 +05:30
parent 944b220905
commit 7604b776b3
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 16 additions and 2 deletions

View file

@ -2,6 +2,7 @@ package dev.msfjarvis.claw.common.urllauncher
import androidx.compose.ui.platform.UriHandler
import java.awt.Desktop
import java.io.IOException
import java.net.URI
class UrlLauncher : UriHandler {
@ -9,7 +10,11 @@ class UrlLauncher : UriHandler {
if (Desktop.isDesktopSupported()) {
val desktop = Desktop.getDesktop()
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(URI(uri))
try {
desktop.browse(URI(uri))
} catch (e: IOException) {
println("Failed to open URL: $uri")
}
}
}
}