Android: write and read picked files through content URIs
On Android the file dialogs return content:// URIs, not paths. Exports wrote them with std::fs, which failed after the system had already created the document, leaving a 0 B file; deck, library-card and library backup exports now write through tauri-plugin-fs, and a failed deck export shows an error instead of failing silently. Library-file and card-database imports read the pick through the fs plugin too. A library file is told apart by its SQLite header rather than its extension, and SQLite opens a local copy. The library-import picker drops its filters on Android, where they hid .db and backup files. Deck import suggests the file's display name rather than the URI's opaque id, and the backup's "Saved to" message shows the file name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
//!
|
||||
//! Android has no official Tauri share plugin, so this registers a small one
|
||||
//! of our own whose Kotlin half (`SharePlugin.kt`, in the Android app module)
|
||||
//! hands the image to `ACTION_SEND` via the app's FileProvider.
|
||||
//! hands the image to `ACTION_SEND` via the app's FileProvider. The same
|
||||
//! plugin looks up the display names of documents the file picker returns.
|
||||
|
||||
use tauri::AppHandle;
|
||||
|
||||
@@ -72,6 +73,26 @@ fn deliver(_app: &AppHandle, _bytes: &[u8], _name: &str) -> Res<&'static str> {
|
||||
Err("Sharing isn't available on iOS yet.".into())
|
||||
}
|
||||
|
||||
/// The name the system file picker showed for a content:// URI, if the
|
||||
/// document's provider reports one.
|
||||
#[cfg(target_os = "android")]
|
||||
pub fn display_name(app: &AppHandle, uri: &str) -> Option<String> {
|
||||
use tauri::Manager;
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct Named {
|
||||
name: Option<String>,
|
||||
}
|
||||
|
||||
let plugin = app.state::<SharePlugin>();
|
||||
let named: Named = plugin
|
||||
.0
|
||||
.run_mobile_plugin("displayName", serde_json::json!({ "uri": uri }))
|
||||
.map_err(|e| crate::mlog!("display name for {uri}: {e}"))
|
||||
.ok()?;
|
||||
named.name
|
||||
}
|
||||
|
||||
/// The Kotlin half's handle, for `run_mobile_plugin`.
|
||||
#[cfg(target_os = "android")]
|
||||
struct SharePlugin(tauri::plugin::PluginHandle<tauri::Wry>);
|
||||
|
||||
Reference in New Issue
Block a user