mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 17:37:05 +05:30
common: change UrlLauncher to be backed by UriHandler
This commit is contained in:
parent
d285afed0b
commit
67893552e7
5 changed files with 13 additions and 16 deletions
|
@ -3,15 +3,16 @@ package dev.msfjarvis.claw.common.urllauncher
|
|||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.compose.ui.platform.UriHandler
|
||||
|
||||
actual class UrlLauncher(private val context: Context) {
|
||||
actual fun launch(url: String) {
|
||||
class UrlLauncher(private val context: Context) : UriHandler {
|
||||
override fun openUri(uri: String) {
|
||||
val customTabsIntent =
|
||||
CustomTabsIntent.Builder()
|
||||
.setShareState(CustomTabsIntent.SHARE_STATE_ON)
|
||||
.setShowTitle(true)
|
||||
.setColorScheme(CustomTabsIntent.COLOR_SCHEME_DARK)
|
||||
.build()
|
||||
customTabsIntent.launchUrl(context, Uri.parse(url))
|
||||
customTabsIntent.launchUrl(context, Uri.parse(uri))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package dev.msfjarvis.claw.common.urllauncher
|
||||
|
||||
expect class UrlLauncher {
|
||||
fun launch(url: String)
|
||||
}
|
|
@ -1,14 +1,15 @@
|
|||
package dev.msfjarvis.claw.common.urllauncher
|
||||
|
||||
import androidx.compose.ui.platform.UriHandler
|
||||
import java.awt.Desktop
|
||||
import java.net.URI
|
||||
|
||||
actual class UrlLauncher {
|
||||
actual fun launch(url: String) {
|
||||
class UrlLauncher : UriHandler {
|
||||
override fun openUri(uri: String) {
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
val desktop = Desktop.getDesktop()
|
||||
if (desktop.isSupported(Desktop.Action.BROWSE)) {
|
||||
desktop.browse(URI(url))
|
||||
desktop.browse(URI(uri))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue