2024-11-14 18:12:51 +00:00
|
|
|
//
|
|
|
|
// Shared+App.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 11/14/24.
|
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CommonLibrary
|
|
|
|
import CommonUtils
|
|
|
|
import Foundation
|
|
|
|
import PassepartoutKit
|
2024-11-28 00:30:26 +00:00
|
|
|
import UITesting
|
2024-11-14 18:12:51 +00:00
|
|
|
|
|
|
|
extension IAPManager {
|
|
|
|
static let sharedForApp = IAPManager(
|
2024-11-28 00:30:26 +00:00
|
|
|
customUserLevel: AppEnvironment.userLevel,
|
|
|
|
inAppHelper: Configuration.IAPManager.simulatedInAppHelper,
|
|
|
|
receiptReader: Configuration.IAPManager.simulatedAppReceiptReader,
|
2024-11-21 18:10:36 +00:00
|
|
|
betaChecker: Configuration.IAPManager.betaChecker,
|
2024-11-14 18:12:51 +00:00
|
|
|
productsAtBuild: Configuration.IAPManager.productsAtBuild
|
|
|
|
)
|
|
|
|
|
2024-11-21 15:03:57 +00:00
|
|
|
static let sharedProcessor = InAppProcessor(
|
2024-11-14 18:12:51 +00:00
|
|
|
iapManager: sharedForApp,
|
|
|
|
title: {
|
|
|
|
Configuration.ProfileManager.sharedTitle($0)
|
|
|
|
},
|
|
|
|
isIncluded: {
|
|
|
|
Configuration.ProfileManager.isIncluded($0, $1)
|
|
|
|
},
|
2024-11-22 11:52:51 +00:00
|
|
|
preview: {
|
|
|
|
ProfilePreview(
|
|
|
|
id: $0.id,
|
|
|
|
name: $0.name,
|
|
|
|
subtitle: $0.localizedDescription(optionalStyle: .moduleTypes)
|
|
|
|
)
|
|
|
|
},
|
2024-11-25 18:17:18 +00:00
|
|
|
verify: { iap, profile in
|
|
|
|
do {
|
|
|
|
try iap.verify(profile)
|
|
|
|
return nil
|
|
|
|
} catch AppError.ineligibleProfile(let requiredFeatures) {
|
|
|
|
return requiredFeatures
|
|
|
|
} catch {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
},
|
2024-11-21 15:03:57 +00:00
|
|
|
willRebuild: { _, builder in
|
2024-11-18 16:43:01 +00:00
|
|
|
builder
|
2024-11-14 18:12:51 +00:00
|
|
|
},
|
2024-11-21 15:48:12 +00:00
|
|
|
willInstall: { iap, profile in
|
2024-11-19 07:55:41 +00:00
|
|
|
try iap.verify(profile)
|
2024-11-14 18:12:51 +00:00
|
|
|
|
|
|
|
// validate provider modules
|
|
|
|
do {
|
|
|
|
_ = try profile.withProviderModules()
|
|
|
|
return profile
|
|
|
|
} catch {
|
|
|
|
pp_log(.app, .error, "Unable to inject provider modules: \(error)")
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Configuration
|
|
|
|
|
2024-11-28 00:30:26 +00:00
|
|
|
private extension Configuration.IAPManager {
|
2024-11-14 18:12:51 +00:00
|
|
|
|
2024-11-28 00:30:26 +00:00
|
|
|
@MainActor
|
|
|
|
static let simulatedInAppHelper: any AppProductHelper = {
|
|
|
|
guard !AppCommandLine.contains(.fakeIAP) else {
|
|
|
|
return FakeAppProductHelper()
|
2024-11-14 18:12:51 +00:00
|
|
|
}
|
2024-11-28 00:30:26 +00:00
|
|
|
return inAppHelper
|
|
|
|
}()
|
2024-11-14 18:12:51 +00:00
|
|
|
|
|
|
|
@MainActor
|
2024-11-28 00:30:26 +00:00
|
|
|
static var simulatedAppReceiptReader: AppReceiptReader {
|
|
|
|
guard !AppCommandLine.contains(.fakeIAP) else {
|
2024-11-21 09:47:46 +00:00
|
|
|
guard let mockHelper = inAppHelper as? FakeAppProductHelper else {
|
2024-11-14 18:12:51 +00:00
|
|
|
fatalError("When .isFakeIAP, productHelper is expected to be MockAppProductHelper")
|
|
|
|
}
|
|
|
|
return mockHelper.receiptReader
|
|
|
|
}
|
|
|
|
return FallbackReceiptReader(
|
|
|
|
main: StoreKitReceiptReader(),
|
2024-11-14 21:21:56 +00:00
|
|
|
beta: betaReceiptURL.map {
|
2024-11-14 18:12:51 +00:00
|
|
|
KvittoReceiptReader(url: $0)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-11-14 21:21:56 +00:00
|
|
|
static var betaReceiptURL: URL? {
|
|
|
|
Bundle.main.appStoreProductionReceiptURL
|
2024-11-14 18:12:51 +00:00
|
|
|
}
|
|
|
|
}
|