iOS 1.0 RC 2: Update Download and Update All Downloads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-11-06 08:55:26 -08:00
1 parent abb157d140
commit ee6ca41fd3
4 files changed
+57 -18

No files matched your search

+22 -8
View File
@@ -141,17 +141,31 @@ final class Downloads: @unchecked Sendable {
/// Brings every group in line with the server: playlists gain and lose songs, artists gain albums.
@MainActor func refresh() async {
for gr in groups.values {
let tracks: [Track]?
switch gr.kind {
case .playlist: tracks = try? await plex.playlistTracks(gr.key)
case .album: tracks = try? await plex.albumTracks(gr.key)
case .artist: tracks = try? await plex.artistTracks(gr.key)
case .stemPlaylist: tracks = AppGraph.shared.stemPlaylists.lists.first { $0.id == gr.key }?.tracks
}
if let tracks, !tracks.isEmpty, let cur = groups[gr.id], cur.trackKeys != tracks.map(\.ratingKey) { download(cur, tracks) }
if let tracks = await serverTracks(gr), let cur = groups[gr.id], cur.trackKeys != tracks.map(\.ratingKey) { download(cur, tracks) }
}
}
/// Update Download: brings [id] in line with the server now and retries its failed songs.
/// False when the server couldn't be reached.
@MainActor func update(_ id: String) async -> Bool {
guard let gr = groups[id], let tracks = await serverTracks(gr), let cur = groups[id] else { return false }
download(cur, tracks)
return true
}
/// The songs [gr] holds on the server right now, or nil when they can't be loaded.
@MainActor private func serverTracks(_ gr: DownloadGroup) async -> [Track]? {
let tracks: [Track]?
switch gr.kind {
case .playlist: tracks = try? await plex.playlistTracks(gr.key)
case .album: tracks = try? await plex.albumTracks(gr.key)
case .artist: tracks = try? await plex.artistTracks(gr.key)
case .stemPlaylist: tracks = AppGraph.shared.stemPlaylists.lists.first { $0.id == gr.key }?.tracks
}
guard let tracks, !tracks.isEmpty else { return nil }
return tracks
}
private func saveGroups() {
let list = groups.values.sorted { $0.added < $1.added }
writeQueue.async { [groupFile] in