Add Android ContentResolver support for content:// URI access#30
Merged
Merged
Conversation
Tauri's plugin-fs uses Rust's std::fs, which cannot open or write content:// URIs on Android. All file reads and writes that previously went through readFile/writeFile from @tauri-apps/plugin-fs now route through a native Android ContentResolver path for content:// URIs. Changes: - UriPermissionPlugin.kt: add readUri and writeUri @command methods that use ContentResolver.openInputStream / openOutputStream("wt") to reliably read/write SAF URIs from the Kotlin layer. - commands.ts: add readContentUri and writeContentUri TypeScript wrappers for the new plugin commands. - useFileOperations.ts: loadDocument now uses readContentUri for content:// paths instead of readFile; handleSave (non-session path) uses writeContentUri; handleSaveAs uses writeContentUri and also moves state updates (setPath, startSession, addDocument, markClean) outside the `if (bytes)` guard so they execute on desktop saves too. - SessionManager.saveToOriginal: uses writeContentUri for content:// URIs instead of writeFile, fixing Ctrl+S on Android. https://claude.ai/code/session_01J39pMh3ZymXAf9W5K3Ziyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds native Android ContentResolver support to handle
content://URIs, which cannot be accessed via Tauri'splugin-fs(which uses Rust'sstd::fs). The changes introduce two new Kotlin plugin commands and update the frontend to use them when working with Storage Access Framework (SAF) URIs on Android.Key Changes
UriPermissionPlugin.kt: Extended the plugin with two new commands:
readUri: reads all bytes from acontent://URI viaContentResolver.openInputStreamwriteUri: writes bytes to acontent://URI viaContentResolver.openOutputStreamin write-truncate modecommands.ts: Added two new TypeScript command wrappers:
readContentUri(uri): invokes the nativereadUricommand and converts the result toUint8ArraywriteContentUri(uri, bytes): invokes the nativewriteUricommand with byte array conversionuseFileOperations.ts: Updated file I/O logic to route
content://URIs through the new ContentResolver commands:openFile: usesreadContentUriforcontent://paths instead ofreadFilesaveDocument: useswriteContentUriforcontent://paths instead ofwriteFilesaveAsDocument: useswriteContentUriforcontent://paths and improved control flow to handle both write paths uniformlySessionManager.ts: Updated
saveToOriginalto detect and routecontent://URIs throughwriteContentUriImplementation Details
writeUriuses write-truncate mode ("wt") to replace existing contentplugin-fshttps://claude.ai/code/session_01J39pMh3ZymXAf9W5K3Ziyi