Skip to content

Commit

Permalink
App: More robust way of checking if we can make donations
Browse files Browse the repository at this point in the history
Disabling it for non Mac App Store builds
  • Loading branch information
vashpan committed Mar 9, 2024
1 parent ca13aaa commit 7559f8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions DevCleaner/Managers/Donations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ public final class Donations: NSObject {

public weak var delegate: DonationsDelegate? = nil

public var canMakeDonations: Bool {
#if DEBUG
return SKPaymentQueue.canMakePayments()
#else
// we can make payments and we're on Mac App Store build
let canMakePayments = SKPaymentQueue.canMakePayments()
let receiptPresent: Bool
if let receiptURL = Bundle.main.appStoreReceiptURL, FileManager.default.fileExists(atPath: receiptURL.path) {
receiptPresent = true
} else {
receiptPresent = false
}

return canMakePayments && receiptPresent

#endif
}

public static let shared = Donations()

// MARK: Initialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ final class MainViewController: NSViewController {

// all time size / donate button
self.benefitsTextField.attributedStringValue = self.benefitsLabelAttributedString(totalBytesCleaned: Preferences.shared.totalBytesCleaned)
self.tipMeButton.isEnabled = SKPaymentQueue.canMakePayments()
self.tipMeButton.isEnabled = Donations.shared.canMakeDonations
}

private func startScan() {
Expand Down

0 comments on commit 7559f8a

Please sign in to comment.