Skip to content

Download persistence system revamp #225

Merged
cranci1 merged 5 commits intocranci1:devfrom
realdoomsboygaming:Updated
Jul 15, 2025
Merged

Download persistence system revamp #225
cranci1 merged 5 commits intocranci1:devfrom
realdoomsboygaming:Updated

Conversation

@realdoomsboygaming
Copy link
Contributor

Key Changes

1. Persistence Layer Migration

Replaced all usages of:

  • UserDefaults.standard.data(forKey: "downloadedAssets")
  • UserDefaults.standard.set(data, forKey: "downloadedAssets")
  • Manual array mutation:
    • savedAssets.append(...)
    • savedAssets.removeAll { $0.id == id }

Now uses:

  • DownloadPersistence.load()
  • DownloadPersistence.save(assets)
  • DownloadPersistence.upsert(newAsset)
  • DownloadPersistence.delete(id: id)

2. Reactive Downloaded View

  • After any download change (add, delete, or update), savedAssets is reloaded from disk.
  • objectWillChange.send() is called on the main thread.
  • Ensures the Downloaded view and all SwiftUI consumers update immediately.

3. Download Completion Handling

  • When a file finishes downloading:
    • The asset is persisted.
    • The UI reflects the new download immediately.

4. Subtitle File Deletion

  • Subtitle deletion is now robust:
    • If localSubtitleURL is nil or missing:
      • Searches for files matching the asset’s ID and common subtitle extensions (.vtt, .srt, .webvtt) in the persistent directory.
  • Prevents orphaned files and keeps storage clean.

5. General Cleanup

  • All legacy persistence logic removed.
  • No direct UserDefaults usage remains for downloads.

New DownloadPersistence utility to handle the loading, saving, and deleting of downloaded assets using a JSON file and UserDefaults. Updated JSController to utilize this new persistence layer and migration from the previous UserDefaults implementation.
@cranci1
Copy link
Owner

cranci1 commented Jul 15, 2025

You didn't need to send the entire AI resume 😭😭😭

@cranci1 cranci1 merged commit 5de3923 into cranci1:dev Jul 15, 2025
2 checks passed
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.

2 participants