mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-23 11:36:13 +02:00
feat(opener): add inAppBrowser option for iOS and Android (#2803)
This commit is contained in:
committed by
GitHub
parent
9799f0dbab
commit
2aec8ff4c4
@@ -6,22 +6,36 @@ package app.tauri.opener
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import app.tauri.annotation.Command
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
import app.tauri.plugin.Invoke
|
||||
import app.tauri.plugin.Plugin
|
||||
import java.io.File
|
||||
import androidx.core.net.toUri
|
||||
import app.tauri.annotation.InvokeArg
|
||||
|
||||
@InvokeArg
|
||||
class OpenArgs {
|
||||
lateinit var url: String
|
||||
var with: String? = null
|
||||
}
|
||||
|
||||
@TauriPlugin
|
||||
class OpenerPlugin(private val activity: Activity) : Plugin(activity) {
|
||||
@Command
|
||||
fun open(invoke: Invoke) {
|
||||
try {
|
||||
val url = invoke.parseArgs(String::class.java)
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
activity.applicationContext?.startActivity(intent)
|
||||
val args = invoke.parseArgs(OpenArgs::class.java)
|
||||
|
||||
if (args.with == "inAppBrowser") {
|
||||
val builder = CustomTabsIntent.Builder()
|
||||
val intent = builder.build()
|
||||
intent.launchUrl(activity, args.url.toUri())
|
||||
} else {
|
||||
val intent = Intent(Intent.ACTION_VIEW, args.url.toUri())
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
activity.applicationContext?.startActivity(intent)
|
||||
}
|
||||
invoke.resolve()
|
||||
} catch (ex: Exception) {
|
||||
invoke.reject(ex.message)
|
||||
|
||||
Reference in New Issue
Block a user