Skip to content

Detect new a-Shell downloads automatically instead of manual per-file imports #38

Description

@EnesYilmazcode

Problem

Every track downloaded by the a-Shell pipeline has to be manually imported through the file picker (src/components/ImportButton.jsx). The app can't watch the a-Shell library folder because iOS Safari has no File System Access API — a PWA cannot save a folder path and re-read it later. The sandbox constraint is real, but the experience of "I downloaded 3 songs, why aren't they in the app?" is fixable.

Constraint (so nobody fights it)

  • No persistent folder handles on iOS Safari. Zero-setup true folder-watching is impossible from the PWA alone.
  • What we do control: the picker allows multi-select, dedup already exists (addLocalTrack() in src/lib/db.js skips existing tracks by YouTube id or title+artist+duration), and the a-Shell engine writes index.json (context.md §2).

Phased plan

Phase 1 — "Sync" flow (MVP, no new infra)

Turn the existing dedup into a one-gesture sync:

  • Rename/augment Import → Sync: instruct "Select All in your library folder"; the picker returns everything, dedup skips known tracks, only new ones are stored
  • After the pick, report a diff summary: "3 new tracks added · 41 already in library" (counts already computed in ImportButton.onPick; today skipped is only shown when nonzero — invert the emphasis)
  • If the pick includes index.json, parse it and list catalog entries that were not among the picked/imported audio files ("2 tracks in your download folder weren't selected") so missed files are visible

Phase 2 — localhost bridge (auto-detect for real, one Shortcut tap)

a-Shell can run Python: serve the library folder on http://127.0.0.1:<port> (e.g. via a small script wrapping http.server). The PWA polls http://127.0.0.1:<port>/index.json; when reachable, it diffs against the local catalog and offers "3 new downloads found — add all?" (or auto-adds behind a setting), fetching the .m4a bytes straight into audioBlobs.

  • Validate on-device that fetch from an HTTPS PWA to http://127.0.0.1 is permitted by current iOS/WebKit (localhost is spec'd as potentially trustworthy; must be confirmed in Safari standalone mode — this is the go/no-go)
  • Add http://127.0.0.1:* to connect-src in the CSP (vite.config.js)
  • a-Shell script + "Open Melody sync server" Shortcut; PWA detects the server with a short-timeout probe on foreground, stays silent when absent
  • Setting: "ask before adding" vs "add automatically"

Phase 3 (fallback if Phase 2 is blocked) — Shortcut hand-off

iOS Shortcut base64-encodes a downloaded file + metadata to the clipboard; a "Paste import" affordance in the PWA reads it via navigator.clipboard.readText() and stores the track. Clunkier, but zero picker interaction.

Acceptance criteria

After downloading N tracks in a-Shell, getting them into Melody takes at most one gesture, never per-file selection, and duplicates are never created.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions