From f5e01f976871362a5187f7b8eb4a464ced41a769 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Mon, 16 May 2022 11:18:49 +0200 Subject: [PATCH] Wrap/refine a few OS conditionals --- Passepartout/App/InApp/ProductManager.swift | 40 ++++++++++++--------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/Passepartout/App/InApp/ProductManager.swift b/Passepartout/App/InApp/ProductManager.swift index b5f8d044..bc20354f 100644 --- a/Passepartout/App/InApp/ProductManager.swift +++ b/Passepartout/App/InApp/ProductManager.swift @@ -173,11 +173,7 @@ class ProductManager: NSObject, ObservableObject { // MARK: In-app eligibility private func isCurrentPlatformVersion() -> Bool { - #if targetEnvironment(macCatalyst) - return purchasedFeatures.contains(.fullVersion_macOS) - #else - return purchasedFeatures.contains(.fullVersion_iOS) - #endif + purchasedFeatures.contains(isMac ? .fullVersion_macOS : .fullVersion_iOS) } private func isFullVersion() -> Bool { @@ -196,11 +192,11 @@ class ProductManager: NSObject, ObservableObject { return true } } - #if targetEnvironment(macCatalyst) - return isFullVersion() - #else - return isFullVersion() || purchasedFeatures.contains(feature) - #endif + if isMac { + return isFullVersion() + } else { + return isFullVersion() || purchasedFeatures.contains(feature) + } } func isEligible(forProvider providerName: ProviderName) -> Bool { @@ -289,15 +285,25 @@ extension ProductManager { let hasCancelledFullVersion: Bool let hasCancelledTrustedNetworks: Bool - #if targetEnvironment(macCatalyst) - hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_macOS)) - hasCancelledTrustedNetworks = false - #else - hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_iOS)) - hasCancelledTrustedNetworks = !isEligibleForFullVersion && isCancelledPurchase(.trustedNetworks) - #endif + if isMac { + hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_macOS)) + hasCancelledTrustedNetworks = false + } else { + hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_iOS)) + hasCancelledTrustedNetworks = !isEligibleForFullVersion && isCancelledPurchase(.trustedNetworks) + } // review features and potentially revert them if they were used (Siri is handled in AppDelegate) return hasCancelledFullVersion || hasCancelledTrustedNetworks } } + +extension ProductManager { + private var isMac: Bool { + #if targetEnvironment(macCatalyst) + true + #else + false + #endif + } +}