Repository navigation
Description
Context
Follow-up to #26 (PickDirectories on Android/iOS/web, tested on NSGo v0.3.0).
In Wood & Wind Music (a local music player targeting macOS, Windows, and Android), desktop folders picked via PickDirectories return a native Path, so the app scans tags, reads .lrc lyrics, and plays audio directly from the user's folder without duplicating files.
On Android, PickDirectories returns a pathless core.Directory backed by ACTION_OPEN_DOCUMENT_TREE. Today, an app cannot keep using that picked folder directly across restarts or stream its files in-place with core.Video, which forces the app either to copy the entire music library (often gigabytes of FLAC/MP3 files) into app-private storage — doubling storage usage and preventing rescans from seeing later changes — or to maintain a custom Android host bridge.
Specific Gaps in v0.3.0
-
No persistent directory access across restarts
internal/platform/android/java/dev/oneo/nsgo/Services.java(startFolder) launchesnew Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)withoutFLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_PERSISTABLE_URI_PERMISSION, andNsgoView.documentsResultdoes not callContentResolver.takePersistableUriPermission.core.Directoryexposes no opaque/serializable token (or bookmark) and there is no API to reopen a previously granted folder after restart or release the persisted grant when the user removes the folder.- (On iOS, security-scoped bookmarks cover the same persistence lifecycle.)
-
No playable URI / media source for files inside
core.DirectoryVideoNode.java(setMediaSource) callsplayer.setDataSource(context, Uri.parse(uri)), so Android'sMediaPlayeralready supports streamingcontent://document URIs directly with zero copying and working seek/rate controls.- However,
core.Directoryonly exposesfs.FS(byte reads over the Go↔Java pipe) and gives no way to obtain acore.Video-compatible source URI for an entry in the picked tree.
-
Repeated descriptor opens when scanning large trees on Android
Services.readDocumentopens a newParcelFileDescriptor+FileChannelon everyReadRPC, anddocumentininternal/platform/android/folders.godoes not implementio.ReaderAt.- Tag and duration parsers issue many small
Read/Seekcalls per track; keeping an open descriptor perfs.FileuntilClose()(and optionally implementingio.ReaderAtor batch tree listing) would substantially reduce provider IPC overhead when scanning hundreds or thousands of files in-place.
Minimal Reproduction
// On Android (NSGo v0.3.0):
cx.PickDirectories(core.PickDirectoriesOptions{}, func(dirs []core.Directory, err error) {
if err != nil || len(dirs) == 0 {
return
}
dir := dirs[0]
// 1. dir.Path is "" on Android, and core.Directory has no persistable token
// to save to disk and reopen after an app restart.
// 2. Opening a track via dir.Open("song.flac") only provides an fs.File;
// there is no URI/handle to pass to core.Video{Source: ...} without
// copying the audio file into cx.DataDir().
})Request
Could NSGo support persistent, in-place access for picked directories? For example:
- An option on
PickDirectoriesOptions(e.g.,Persist: true) that takes a persistable grant (AndroidtakePersistableUriPermission; iOS security-scoped bookmark) and populates a serializable handle/token oncore.Directory, along withScopemethods to reopen a persisted directory by token and release the grant. - A way to obtain a read-only playable media source/URI for a file inside a
core.Directorythatcore.Videocan stream directly (e.g.,content://on Android,file://on desktop/iOS). - Keeping the Android
ParcelFileDescriptoropen for the lifetime of an openedfs.File(and/or supportingio.ReaderAt) so metadata scanning does not reopen the provider descriptor on every chunk read.
Activity