feat(*): subsonic client with avfoundation playback and apple music ui

This commit is contained in:
hh committed 2026-09-22 06:44:44 +02:00
commit e5bb559d7f
93 files changed
+7517

No files matched your search

@@ -0,0 +1,39 @@
import Domain
import Store
public actor SyncEngine {
private let library: any Library
private let batchSize = 500
public init(library: any Library) {
self.library = library
}
public func sync(_ source: any LibrarySource) async throws {
do {
try await pull(source, since: library.cursor(for: source.id))
} catch SourceError.cannotCalculateChanges {
try await pull(source, since: nil)
}
}
private func pull(_ source: any LibrarySource, since cursor: Cursor?) async throws {
var batch: [Change] = []
for try await change in source.changes(since: cursor) {
if case let .checkpoint(next) = change {
await library.apply(batch)
batch.removeAll(keepingCapacity: true)
await library.setCursor(next, for: source.id)
} else {
batch.append(change)
if batch.count >= batchSize {
await library.apply(batch)
batch.removeAll(keepingCapacity: true)
}
}
}
if !batch.isEmpty {
await library.apply(batch)
}
}
}