mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 19:57:04 +05:30
common: add UrlLauncher
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
a5473af699
commit
b166755afa
5 changed files with 40 additions and 1 deletions
|
@ -26,7 +26,7 @@ kotlin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val commonTest by getting { dependencies { implementation(kotlin("test")) } }
|
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 androidTest by getting
|
||||||
val desktopMain by getting
|
val desktopMain by getting
|
||||||
val desktopTest by getting
|
val desktopTest by getting
|
||||||
|
|
|
@ -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))
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package dev.msfjarvis.claw.common.urllauncher
|
||||||
|
|
||||||
|
expect class UrlLauncher {
|
||||||
|
fun launch(url: String)
|
||||||
|
}
|
|
@ -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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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-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" }
|
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-moshi-lib = "com.squareup.moshi:moshi:1.12.0"
|
||||||
thirdparty-moshix-ksp = { module = "dev.zacsweers.moshix:moshi-ksp", version.ref = "moshix" }
|
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" }
|
thirdparty-moshix-metadatareflect = { module = "dev.zacsweers.moshix:moshi-metadata-reflect", version.ref = "moshix" }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue