Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SystemInfo.finishTransactions: made thread-safe #1807

Merged
merged 1 commit into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Sources/Misc/SystemInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ class SystemInfo {
static var forceUniversalAppStore: Bool = false

let storeKit2Setting: StoreKit2Setting
var finishTransactions: Bool
let operationDispatcher: OperationDispatcher
let platformFlavor: String
let platformFlavorVersion: String?
let bundle: Bundle
let dangerousSettings: DangerousSettings

var finishTransactions: Bool {
get { return self._finishTransactions.value }
set { self._finishTransactions.value = newValue }
}

private let sandboxEnvironmentDetector: SandboxEnvironmentDetector
private let _finishTransactions: Atomic<Bool>

var isSandbox: Bool {
return self.sandboxEnvironmentDetector.isSandbox
Expand Down Expand Up @@ -106,7 +111,7 @@ class SystemInfo {
self.platformFlavorVersion = platformInfo?.version
self.bundle = bundle

self.finishTransactions = finishTransactions
self._finishTransactions = .init(finishTransactions)
self.operationDispatcher = operationDispatcher
self.storeKit2Setting = storeKit2Setting
self.dangerousSettings = dangerousSettings ?? DangerousSettings()
Expand Down
4 changes: 2 additions & 2 deletions Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void
* More information on finishing transactions manually [is available here](https://rev.cat/finish-transactions).
*/
@objc public var finishTransactions: Bool {
get { systemInfo.finishTransactions }
set { systemInfo.finishTransactions = newValue }
get { self.systemInfo.finishTransactions }
set { self.systemInfo.finishTransactions = newValue }
}

private let attributionFetcher: AttributionFetcher
Expand Down
4 changes: 2 additions & 2 deletions Sources/Purchasing/Purchases/PurchasesOrchestrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import StoreKit
// swiftlint:disable file_length type_body_length
class PurchasesOrchestrator {

var finishTransactions: Bool { systemInfo.finishTransactions }
var finishTransactions: Bool { self.systemInfo.finishTransactions }
var allowSharingAppStoreAccount: Bool {
get {
return _allowSharingAppStoreAccount ?? self.currentUserProvider.currentUserIsAnonymous
Expand Down Expand Up @@ -619,7 +619,7 @@ extension PurchasesOrchestrator: StoreKit2TransactionListenerDelegate {

func transactionsUpdated() async throws {
// Need to restore if using observer mode (which is inverse of finishTransactions)
let isRestore = !systemInfo.finishTransactions
let isRestore = !self.systemInfo.finishTransactions

_ = try await syncPurchases(receiptRefreshPolicy: .always, isRestore: isRestore)
}
Expand Down