Simplify feature eligibility
This commit is contained in:
parent
a84eea5694
commit
5c1dd22b96
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue