|
|
|
@ -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)
|
|
|
|
|