mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-23 11:36:13 +02:00
feat(shell): support opening URLs on mobile (#1319)
* feat(shell): support opening URLs on mobile closes #595 * Update and rename StorePlugin.swift to ShellPlugin.swift * unwrap * fix func name (ios) * use undeprecated func if avail --------- Co-authored-by: fabianlars <fabianlars@fabianlars.de>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package app.tauri.shell
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import app.tauri.annotation.Command
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
import app.tauri.plugin.Invoke
|
||||
import app.tauri.plugin.Plugin
|
||||
import java.io.File
|
||||
|
||||
@TauriPlugin
|
||||
class ShellPlugin(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)
|
||||
invoke.resolve()
|
||||
} catch (ex: Exception) {
|
||||
invoke.reject(ex.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user