From 5c1dd22b96b1cd7b72f7f8bc6053d09215f9e210 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 7 Feb 2021 10:43:54 +0100 Subject: [PATCH] Simplify feature eligibility --- .../TrustedNetworksViewController.swift | 4 +- .../Sources/Model/ConnectionService.swift | 2 +- .../Core/Sources/Model/ProductManager.swift | 41 ++++++------------- 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/Passepartout/App/macOS/Scenes/Service/Customization/TrustedNetworksViewController.swift b/Passepartout/App/macOS/Scenes/Service/Customization/TrustedNetworksViewController.swift index cf5faf08..c7be314c 100644 --- a/Passepartout/App/macOS/Scenes/Service/Customization/TrustedNetworksViewController.swift +++ b/Passepartout/App/macOS/Scenes/Service/Customization/TrustedNetworksViewController.swift @@ -108,7 +108,7 @@ class TrustedNetworksViewController: NSViewController, ProfileCustomization { @IBAction private func toggleTrustEthernet(_ sender: Any?) { do { - try ProductManager.shared.verifyEligibleForTrustedNetworks() + try ProductManager.shared.verifyEligible(forFeature: .trustedNetworks) } catch { checkTrustEthernet.state = .off presentPurchaseScreen(forProduct: .trustedNetworks) @@ -132,7 +132,7 @@ class TrustedNetworksViewController: NSViewController, ProfileCustomization { override func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool { if identifier == StoryboardSegue.Service.trustedNetworkAddSegueIdentifier.rawValue { do { - try ProductManager.shared.verifyEligibleForTrustedNetworks() + try ProductManager.shared.verifyEligible(forFeature: .trustedNetworks) } catch { presentPurchaseScreen(forProduct: .trustedNetworks) return false diff --git a/Passepartout/Core/Sources/Model/ConnectionService.swift b/Passepartout/Core/Sources/Model/ConnectionService.swift index 4813f70a..38cb2081 100644 --- a/Passepartout/Core/Sources/Model/ConnectionService.swift +++ b/Passepartout/Core/Sources/Model/ConnectionService.swift @@ -554,7 +554,7 @@ public class ConnectionService: Codable { var rules: [NEOnDemandRule] = [] do { - try ProductManager.shared.verifyEligibleForTrustedNetworks() + try ProductManager.shared.verifyEligible(forFeature: .trustedNetworks) #if os(iOS) if profile.trustedNetworks.includesMobile { let rule = policyRule(for: profile) diff --git a/Passepartout/Core/Sources/Model/ProductManager.swift b/Passepartout/Core/Sources/Model/ProductManager.swift index 62b9dc14..de9e692d 100644 --- a/Passepartout/Core/Sources/Model/ProductManager.swift +++ b/Passepartout/Core/Sources/Model/ProductManager.swift @@ -159,16 +159,21 @@ public class ProductManager: NSObject { // MARK: In-app eligibility - public func isFullVersion() -> Bool { + private func isCurrentPlatformVersion() -> Bool { #if os(iOS) - if (isBeta && cfg.isBetaFullVersion) || purchasedFeatures.contains(.fullVersion_iOS) { - return true - } + return purchasedFeatures.contains(.fullVersion_iOS) #else - if (isBeta && cfg.isBetaFullVersion) || purchasedFeatures.contains(.fullVersion_macOS) { + return purchasedFeatures.contains(.fullVersion_macOS) + #endif + } + + private func isFullVersion() -> Bool { + if isBeta && cfg.isBetaFullVersion { + return true + } + if isCurrentPlatformVersion() { return true } - #endif return purchasedFeatures.contains(.fullVersion) } @@ -176,14 +181,6 @@ public class ProductManager: NSObject { return isFullVersion() || purchasedFeatures.contains(feature) } - private func isEligible(forProvider metadata: Infrastructure.Metadata) -> Bool { - return isFullVersion() || purchasedFeatures.contains(metadata.product) - } - - private func isEligibleForTrustedNetworks() -> Bool { - return isFullVersion() || purchasedFeatures.contains(.trustedNetworks) - } - public func isEligibleForFeedback() -> Bool { return isBeta || !purchasedFeatures.isEmpty } @@ -211,21 +208,7 @@ public class ProductManager: NSObject { throw ProductError.beta } } - guard isFullVersion() || purchasedFeatures.contains(metadata.product) else { - throw ProductError.uneligible - } - } - - public func verifyEligibleForTrustedNetworks() throws { - if isBeta { - if cfg.isBetaFullVersion { - return - } - guard !cfg.locksBetaFeatures else { - throw ProductError.beta - } - } - guard isEligibleForTrustedNetworks() else { + guard isEligible(forFeature: metadata.product) else { throw ProductError.uneligible } }