From ceb60e5520e24832a73961f5e73540749c1fc058 Mon Sep 17 00:00:00 2001 From: Alberto Sendra Date: Tue, 30 Jul 2024 14:27:23 +0200 Subject: [PATCH 1/3] Bumping SDK version to 0.3.27 --- CHANGELOG.md | 4 ++++ version.txt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 706cc8d4..b4ce9ca9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ 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 +### 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/version.txt b/version.txt index e23fb32d..e01fa856 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.3.26 +0.3.27 From 18638ec3d89d153b511dfdfc72dfc605fb201d78 Mon Sep 17 00:00:00 2001 From: Evgenii Kononenko Date: Tue, 30 Jul 2024 16:58:08 +0200 Subject: [PATCH 2/3] updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4ce9ca9..5e7c1b56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ 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) From a43eff21bd644afd44b6b8574303cb3bbf09efab Mon Sep 17 00:00:00 2001 From: Evgenii Kononenko Date: Wed, 31 Jul 2024 19:20:39 +0200 Subject: [PATCH 3/3] tokens store - made thread safe --- Sources/Auth/Storage/DefaultTokensStore.swift | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) 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() - } }