Merge branch 'fix-unified-iaps'

This commit is contained in:
Davide De Rosa 2021-02-05 17:22:49 +01:00
commit 5d83f84adb
4 changed files with 28 additions and 16 deletions

View File

@ -84,7 +84,7 @@ class PurchaseViewController: NSViewController {
rows.append(.feature) rows.append(.feature)
} }
let platformBulletsList: [String] = ProductManager.shared.featureProducts(excluding: [.fullVersion, .fullVersion_iOS, .fullVersion_macOS]).map { let platformBulletsList: [String] = ProductManager.shared.featureProducts(excluding: [.siriShortcuts, .fullVersion, .fullVersion_iOS, .fullVersion_macOS]).map {
return $0.localizedTitle return $0.localizedTitle
}.sortedCaseInsensitive() }.sortedCaseInsensitive()
let platformBullets = platformBulletsList.joined(separator: "\n") let platformBullets = platformBulletsList.joined(separator: "\n")

View File

@ -111,7 +111,7 @@ class TrustedNetworksViewController: NSViewController, ProfileCustomization {
try ProductManager.shared.verifyEligibleForTrustedNetworks() try ProductManager.shared.verifyEligibleForTrustedNetworks()
} catch { } catch {
checkTrustEthernet.state = .off checkTrustEthernet.state = .off
presentPurchaseScreen(forProduct: .fullVersion_macOS) presentPurchaseScreen(forProduct: .trustedNetworks)
return return
} }
trustedNetworks.includesEthernet = (checkTrustEthernet.state == .on) trustedNetworks.includesEthernet = (checkTrustEthernet.state == .on)
@ -134,7 +134,7 @@ class TrustedNetworksViewController: NSViewController, ProfileCustomization {
do { do {
try ProductManager.shared.verifyEligibleForTrustedNetworks() try ProductManager.shared.verifyEligibleForTrustedNetworks()
} catch { } catch {
presentPurchaseScreen(forProduct: .fullVersion_macOS) presentPurchaseScreen(forProduct: .trustedNetworks)
return false return false
} }
} }

View File

@ -350,6 +350,8 @@ public class AppConstants {
} }
struct InApp { struct InApp {
static let locksBetaFeatures = true
#if os(iOS) #if os(iOS)
static var isBetaFullVersion: Bool { static var isBetaFullVersion: Bool {
return ProcessInfo.processInfo.environment["FULL_VERSION"] != nil return ProcessInfo.processInfo.environment["FULL_VERSION"] != nil

View File

@ -40,14 +40,18 @@ public enum ProductError: Error {
public class ProductManager: NSObject { public class ProductManager: NSObject {
public struct Configuration { public struct Configuration {
public let locksBetaFeatures: Bool
public let isBetaFullVersion: Bool public let isBetaFullVersion: Bool
public let lastFullVersionBuild: Int public let lastFullVersionBuild: Int
public init( public init(
locksBetaFeatures: Bool,
isBetaFullVersion: Bool, isBetaFullVersion: Bool,
lastFullVersionBuild: Int lastFullVersionBuild: Int
) { ) {
self.locksBetaFeatures = locksBetaFeatures
self.isBetaFullVersion = isBetaFullVersion self.isBetaFullVersion = isBetaFullVersion
self.lastFullVersionBuild = lastFullVersionBuild self.lastFullVersionBuild = lastFullVersionBuild
} }
@ -92,11 +96,15 @@ public class ProductManager: NSObject {
} }
public var isBeta: Bool { public var isBeta: Bool {
#if os(iOS)
#if targetEnvironment(simulator) #if targetEnvironment(simulator)
return true return true
#else #else
return Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt" return Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
#endif #endif
#else
return false
#endif
} }
public func listProducts(completionHandler: (([SKProduct]?, Error?) -> Void)?) { public func listProducts(completionHandler: (([SKProduct]?, Error?) -> Void)?) {
@ -157,7 +165,7 @@ public class ProductManager: NSObject {
return true return true
} }
#else #else
if cfg.isBetaFullVersion || purchasedFeatures.contains(.fullVersion_macOS) { if (isBeta && cfg.isBetaFullVersion) || purchasedFeatures.contains(.fullVersion_macOS) {
return true return true
} }
#endif #endif
@ -173,24 +181,19 @@ public class ProductManager: NSObject {
} }
private func isEligibleForTrustedNetworks() -> Bool { private func isEligibleForTrustedNetworks() -> Bool {
#if os(iOS)
return isFullVersion() || purchasedFeatures.contains(.trustedNetworks) return isFullVersion() || purchasedFeatures.contains(.trustedNetworks)
#else
return isFullVersion()
#endif
} }
public func isEligibleForFeedback() -> Bool { public func isEligibleForFeedback() -> Bool {
#if os(iOS)
return isBeta || !purchasedFeatures.isEmpty return isBeta || !purchasedFeatures.isEmpty
#else
return isFullVersion()
#endif
} }
public func verifyEligible(forFeature feature: Product) throws { public func verifyEligible(forFeature feature: Product) throws {
if isBeta { if isBeta {
guard cfg.isBetaFullVersion else { if cfg.isBetaFullVersion {
return
}
guard !cfg.locksBetaFeatures else {
throw ProductError.beta throw ProductError.beta
} }
} }
@ -201,7 +204,10 @@ public class ProductManager: NSObject {
public func verifyEligible(forProvider metadata: Infrastructure.Metadata) throws { public func verifyEligible(forProvider metadata: Infrastructure.Metadata) throws {
if isBeta { if isBeta {
guard cfg.isBetaFullVersion else { if cfg.isBetaFullVersion {
return
}
guard !cfg.locksBetaFeatures else {
throw ProductError.beta throw ProductError.beta
} }
} }
@ -212,7 +218,10 @@ public class ProductManager: NSObject {
public func verifyEligibleForTrustedNetworks() throws { public func verifyEligibleForTrustedNetworks() throws {
if isBeta { if isBeta {
guard cfg.isBetaFullVersion else { if cfg.isBetaFullVersion {
return
}
guard !cfg.locksBetaFeatures else {
throw ProductError.beta throw ProductError.beta
} }
} }
@ -250,7 +259,7 @@ public class ProductManager: NSObject {
// treat former purchases as full versions // treat former purchases as full versions
if buildNumber <= cfg.lastFullVersionBuild { if buildNumber <= cfg.lastFullVersionBuild {
purchasedFeatures.insert(.fullVersion) purchasedFeatures.insert(.fullVersion_iOS)
} }
} }
if let iapReceipts = receipt.inAppPurchaseReceipts { if let iapReceipts = receipt.inAppPurchaseReceipts {
@ -312,6 +321,7 @@ extension ProductManager: SKRequestDelegate {
extension ProductManager { extension ProductManager {
public static let shared = ProductManager( public static let shared = ProductManager(
Configuration( Configuration(
locksBetaFeatures: AppConstants.InApp.locksBetaFeatures,
isBetaFullVersion: AppConstants.InApp.isBetaFullVersion, isBetaFullVersion: AppConstants.InApp.isBetaFullVersion,
lastFullVersionBuild: AppConstants.InApp.lastFullVersionBuild lastFullVersionBuild: AppConstants.InApp.lastFullVersionBuild
) )