-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(mobile): add file association support #14486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/mobile-multi-window
Are you sure you want to change the base?
feat(mobile): add file association support #14486
Conversation
Package Changes Through 8c28838There are 10 changes which include @tauri-apps/api with patch, tauri with minor, tauri-build with minor, tauri-plugin with minor, tauri-cli with minor, tauri-bundler with minor, @tauri-apps/cli with patch, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
| filters | ||
| } | ||
|
|
||
| fn extension_to_mime_type(ext: &str) -> Option<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this covers ~25 file types it is important to include support for custom file extensions/MIME types.
We need to be able to define these in tauri.conf.json for desktop/mobile so they are available to the builder in order to generate correct platform-specific metadata e.g. info.plist, AndroidManifest.xml.
| let path_patterns: Vec<String> = association | ||
| .ext | ||
| .iter() | ||
| .map(|ext| format!(".*\\\\.{}", ext.0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Android's pathPattern has known limitations e.g. Doesn't match paths with multiple dots (e.g., file.backup.png).
Workarounds:
- Use multiple patterns
<data android:pathPattern=".*\\.png" />
<data android:pathPattern=".*\\..*\\.png" />
<data android:pathPattern=".*\\..*\\..*\\.png" />- Use MIME type only
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/png" />
<!-- No pathPattern - rely on MIME type -->
</intent-filter>- Scheme + MIME Type
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="image/png" />
</intent-filterIf filters are not generated properly, the only way forward is then to use a wildcard (*) filter which associates the app with all file/MIME types - this is not an ideal UX experience.
| filters.push_str(" <action android:name=\"android.intent.action.SEND\" />\n"); | ||
| filters.push_str(" <action android:name=\"android.intent.action.SEND_MULTIPLE\" />\n"); | ||
| filters.push_str(" <category android:name=\"android.intent.category.DEFAULT\" />\n"); | ||
| filters.push_str(" <category android:name=\"android.intent.category.BROWSABLE\" />\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are missing ACTION_VIEW e.g. user taps in file manager. Ideally, if would be good if we could define which actions we which to listen to.
| filters.push_str(" <action android:name=\"android.intent.action.SEND\" />\n"); | ||
| filters.push_str(" <action android:name=\"android.intent.action.SEND_MULTIPLE\" />\n"); | ||
| filters.push_str(" <category android:name=\"android.intent.category.DEFAULT\" />\n"); | ||
| filters.push_str(" <category android:name=\"android.intent.category.BROWSABLE\" />\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From Android Docs:
BROWSABLE - The target activity allows itself to be started by a web browser to display data referenced by a link, such as an image or an e-mail message.
This is related to deep-linking not file association. Does this need to be handled differently? How will this interact with the deep-link plugin?
| // If we have mime types, create intent filters | ||
| if !mime_types.is_empty() { | ||
| for mime_type in &mime_types { | ||
| filters.push_str("<intent-filter>\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tauri config has rank but this is not being used on Android.
{
"ext": ["png"],
"mimeType": "image/png",
"rank": "Owner" // ← This exists in config
}Android can specify a priority on intent filters which is a signed integer between -1000 to 1000.
<intent-filter android:priority="1000">
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="image/png" />
</intent-filter>| } | ||
|
|
||
| /// Maps file extensions to their standard UTIs for macOS/iOS share sheet support | ||
| fn extension_to_uti(ext: &str) -> Option<&'static str> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same content RE: file extensions and standard UTIs. While this covers ~30 file types it is important to include support for custom file extensions/MIME types in tauri.conf.json.
needs tauri-apps/tao#1155
needs tauri-apps/wry#1634
needs #14484 to be merged first