diff --git a/common/build.gradle.kts b/common/build.gradle.kts index edeafca6..32b5b2be 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -26,7 +26,7 @@ kotlin { } } val commonTest by getting { dependencies { implementation(kotlin("test")) } } - val androidMain by getting + val androidMain by getting { dependencies { implementation(libs.androidx.browser) } } val androidTest by getting val desktopMain by getting val desktopTest by getting diff --git a/common/src/androidMain/kotlin/dev/msfjarvis/claw/common/urllauncher/UrlLauncher.kt b/common/src/androidMain/kotlin/dev/msfjarvis/claw/common/urllauncher/UrlLauncher.kt new file mode 100644 index 00000000..48f1f7ab --- /dev/null +++ b/common/src/androidMain/kotlin/dev/msfjarvis/claw/common/urllauncher/UrlLauncher.kt @@ -0,0 +1,17 @@ +package dev.msfjarvis.claw.common.urllauncher + +import android.content.Context +import android.net.Uri +import androidx.browser.customtabs.CustomTabsIntent + +actual class UrlLauncher(private val context: Context) { + actual fun launch(url: String) { + val customTabsIntent = + CustomTabsIntent.Builder() + .setShareState(CustomTabsIntent.SHARE_STATE_ON) + .setShowTitle(true) + .setColorScheme(CustomTabsIntent.COLOR_SCHEME_DARK) + .build() + customTabsIntent.launchUrl(context, Uri.parse(url)) + } +} diff --git a/common/src/commonMain/kotlin/dev/msfjarvis/claw/common/urllauncher/UrlLauncher.kt b/common/src/commonMain/kotlin/dev/msfjarvis/claw/common/urllauncher/UrlLauncher.kt new file mode 100644 index 00000000..44b8772d --- /dev/null +++ b/common/src/commonMain/kotlin/dev/msfjarvis/claw/common/urllauncher/UrlLauncher.kt @@ -0,0 +1,5 @@ +package dev.msfjarvis.claw.common.urllauncher + +expect class UrlLauncher { + fun launch(url: String) +} diff --git a/common/src/desktopMain/kotlin/dev/msfjarvis/claw/common/urllauncher/UrlLauncher.kt b/common/src/desktopMain/kotlin/dev/msfjarvis/claw/common/urllauncher/UrlLauncher.kt new file mode 100644 index 00000000..646d2f1c --- /dev/null +++ b/common/src/desktopMain/kotlin/dev/msfjarvis/claw/common/urllauncher/UrlLauncher.kt @@ -0,0 +1,15 @@ +package dev.msfjarvis.claw.common.urllauncher + +import java.awt.Desktop +import java.net.URI + +actual class UrlLauncher { + actual fun launch(url: String) { + if (Desktop.isDesktopSupported()) { + val desktop = Desktop.getDesktop() + if (desktop.isSupported(Desktop.Action.BROWSE)) { + desktop.browse(URI(url)) + } + } + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1d86de8c..8907e2a6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,6 +11,8 @@ kotlin-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines kotlin-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } kotlin-coroutines-jvm = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version.ref = "coroutines" } +androidx-browser = "androidx.browser:browser:1.3.0" + thirdparty-moshi-lib = "com.squareup.moshi:moshi:1.12.0" thirdparty-moshix-ksp = { module = "dev.zacsweers.moshix:moshi-ksp", version.ref = "moshix" } thirdparty-moshix-metadatareflect = { module = "dev.zacsweers.moshix:moshi-metadata-reflect", version.ref = "moshix" }