Share a card's image from the preview

A share button beside the preview's close button sends the face being
shown at Scryfall's large size: on desktop the image is decoded and put on
the clipboard (tauri-plugin-clipboard-manager); on Android it's saved to
the cache and handed to the system share sheet by a small in-repo plugin
(SharePlugin.kt) through the app's FileProvider. The preview's corner
buttons are also a little larger.
This commit is contained in:
2026-10-24 15:20:27 -05:00
parent 7415289257
commit 226878fdd7
10 changed files with 597 additions and 5 deletions

View File

@@ -0,0 +1,51 @@
package com.garrettmills.mtgc
import android.app.Activity
import android.content.ClipData
import android.content.Intent
import androidx.core.content.FileProvider
import app.tauri.annotation.Command
import app.tauri.annotation.InvokeArg
import app.tauri.annotation.TauriPlugin
import app.tauri.plugin.Invoke
import app.tauri.plugin.Plugin
import java.io.File
@InvokeArg
class ShareImageArgs {
/** A JPEG under the app's cache dir, which the FileProvider exposes. */
lateinit var path: String
var title: String? = null
}
/**
* The Android half of the app's `share` plugin (src-tauri/src/share.rs):
* opens the system share sheet for a card image the Rust side has saved.
*/
@TauriPlugin
class SharePlugin(private val activity: Activity) : Plugin(activity) {
@Command
fun shareImage(invoke: Invoke) {
try {
val args = invoke.parseArgs(ShareImageArgs::class.java)
val uri = FileProvider.getUriForFile(
activity,
"${activity.packageName}.fileprovider",
File(args.path),
)
val send = Intent(Intent.ACTION_SEND).apply {
type = "image/jpeg"
putExtra(Intent.EXTRA_STREAM, uri)
args.title?.let { putExtra(Intent.EXTRA_TITLE, it) }
// ClipData lets the chooser show a preview of the image, and carries
// the read grant along with it.
clipData = ClipData.newRawUri(args.title, uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
activity.startActivity(Intent.createChooser(send, args.title))
invoke.resolve()
} catch (ex: Exception) {
invoke.reject(ex.message)
}
}
}