Skip to content
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

feat(fs): cross platform approach to get file name from filepath #2421

Open
wants to merge 7 commits into
base: v2
Choose a base branch
from

Conversation

VulnX
Copy link

@VulnX VulnX commented Feb 14, 2025

Closes #1775

Reason

On desktop platforms, obtaining the file name from a file path is straightforward, as it is directly embedded in the path's last part. However, on Android, the situation differs. When a file is opened via the dialog plugin (see note here), a content URI is returned instead of a file path. To extract the actual file name from this URI, Android-specific APIs must be accessed via Kotlin.

Changes

A new fileName() function has been added to the guest JS API. This function internally calls the file_name() command, which acts as a thin wrapper around platform-specific implementations of the Fs struct defined in mobile.rs and desktop.rs.

For Android, the file name is resolved by querying the content URI with contentResolver.query, specifically retrieving the OpenableColumns.DISPLAY_NAME column to extract the file name.

This change enables Tauri's file system plugin to correctly retrieve file names from any path.

@VulnX VulnX requested a review from a team as a code owner February 14, 2025 18:56
Copy link
Contributor

github-actions bot commented Feb 14, 2025

Package Changes Through 3da78ca

There are 2 changes which include log with patch, log-js with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
api-example 2.0.17 2.0.18
api-example-js 2.0.13 2.0.14
log 2.2.1 2.2.2
log-js 2.2.1 2.2.2

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@VulnX VulnX force-pushed the feat/fs/get-filename-android branch from fb11213 to d0ac2a1 Compare February 16, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[fs] On Android I cannot extract filename returned by open / pick_file(s)
1 participant