Skip to content

Commit

Permalink
Fix opening authorization URL on native
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Jun 13, 2023
1 parent 6098160 commit ba36658
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 2 additions & 3 deletions app/desktop/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import dev.schlaubi.tonbrett.client.href
import dev.schlaubi.tonbrett.common.Route
import io.ktor.http.*
import mu.KotlinLogging
import java.awt.Desktop
import java.net.URI
import java.awt.Window as AWTWindow

Expand All @@ -43,7 +42,7 @@ fun main() = main(reAuthorize = false) { startApplication() }
fun main(reAuthorize: Boolean, onAuth: () -> Unit) {
val config = getConfig()
if (reAuthorize || config.sessionToken == null) {
Desktop.getDesktop().browse(href(Route.Auth(Route.Auth.Type.APP), URLBuilder(getUrl())).build().toURI())
browseUrl(href(Route.Auth(Route.Auth.Type.APP), URLBuilder(getUrl())).build().toURI())
startAuthorizationServer(reAuthorize, onAuth)
} else {
startApplication()
Expand All @@ -68,7 +67,7 @@ fun startApplication() = application {
) {
Text(strings.needsUpdate, color = ColorScheme.textColor)
Button({
Desktop.getDesktop().browse(URI("https://github.com/DRSchlaubi/tonbrett/releases/latest"))
browseUrl(URI("https://github.com/DRSchlaubi/tonbrett/releases/latest"))
exitApplication()
}) {
Icon(Icons.Default.Refresh, null)
Expand Down
13 changes: 13 additions & 0 deletions app/desktop/src/main/kotlin/URIUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.schlaubi.tonbrett.app.desktop

import java.awt.Desktop
import java.net.URI

fun browseUrl(url: URI) {
val desktop = Desktop.getDesktop()
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(url)
} else {
Runtime.getRuntime().exec(arrayOf("xdg-open", url.toString()))
}
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {

allprojects {
group = "dev.schlaubi.tonbrett"
version = "1.9.6"
version = "1.9.7"

repositories {
mavenCentral()
Expand Down

0 comments on commit ba36658

Please sign in to comment.