diff --git a/CHANGELOG.md b/CHANGELOG.md index 706cc8d4..5e7c1b56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.27] - 2024-07-30 +### New +- Use [swift-log](https://github.com/apple/swift-log) library for logging different events (Auth) + +### Fixed +- Fixed crash for the new cache implementation in AVQueuePlayerWrapper (Player) + ## [0.3.26] - 2024-07-23 ### Fixed - Made access to the database queue thread-safe (EventProducer) diff --git a/Sources/Auth/Storage/DefaultTokensStore.swift b/Sources/Auth/Storage/DefaultTokensStore.swift index 6823d7c3..4b0fb740 100644 --- a/Sources/Auth/Storage/DefaultTokensStore.swift +++ b/Sources/Auth/Storage/DefaultTokensStore.swift @@ -9,6 +9,8 @@ final class DefaultTokensStore: TokensStore { private var latestTokens: Tokens? + private let credentialsQueue = DispatchQueue(label: "com.tidal.auth.credentialsQueue") + init(credentialsKey: String, credentialsAccessGroup: String?) { storageKey = "\(credentialsKey)_\(PREFS_FILE_NAME)" self.credentialsKey = credentialsKey @@ -20,8 +22,12 @@ final class DefaultTokensStore: TokensStore { } func getLatestTokens() throws -> Tokens? { - latestTokens = try latestTokens ?? loadTokens() - return latestTokens + try credentialsQueue.sync { + if latestTokens == nil { + latestTokens = try loadTokens() + } + return latestTokens + } } private func loadTokens() throws -> Tokens? { @@ -38,7 +44,7 @@ final class DefaultTokensStore: TokensStore { // try to decode legacy tokens, convert them to tokens and save tokens print("Failed to decode tokens. Attempting to decode legacy tokens") if let convertedLegacyTokens = try? decoder.decode(LegacyTokens.self, from: data).toTokens() { - try saveTokens(tokens: convertedLegacyTokens) + try saveTokensUnsafe(tokens: convertedLegacyTokens) return convertedLegacyTokens } else { throw error @@ -48,14 +54,22 @@ final class DefaultTokensStore: TokensStore { } func saveTokens(tokens: Tokens) throws { + try credentialsQueue.sync { + try saveTokensUnsafe(tokens: tokens) + } + } + + func eraseTokens() throws { + try credentialsQueue.sync { + latestTokens = nil + try encryptedStorage.removeAll() + } + } + + private func saveTokensUnsafe(tokens: Tokens) throws { let data = try JSONEncoder().encode(tokens) encryptedStorage[credentialsKey] = String(data: data, encoding: .utf8) latestTokens = tokens // TODO: emit credentails update: `bus.emit(CredentialsUpdatedMessage)` } - - func eraseTokens() throws { - latestTokens = nil - try encryptedStorage.removeAll() - } } diff --git a/version.txt b/version.txt index e23fb32d..e01fa856 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.3.26 +0.3.27