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 01:11:57 +00:00
|
|
|
customUserLevel: Configuration.IAPManager.customUserLevel,
|
2024-11-28 00:30:26 +00:00
|
|
|
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
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Configuration
|
|
|
|
|
2024-11-28 00:30:26 +00:00
|
|
|
private extension Configuration.IAPManager {
|
2024-11-28 01:11:57 +00:00
|
|
|
static var customUserLevel: AppUserLevel? {
|
|
|
|
guard let userLevelString = BundleConfiguration.mainIntegerIfPresent(for: .userLevel),
|
|
|
|
let userLevel = AppUserLevel(rawValue: userLevelString) else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return userLevel
|
|
|
|
}
|
2024-11-14 18:12:51 +00:00
|
|
|
|
2024-11-28 00:30:26 +00:00
|
|
|
@MainActor
|
|
|
|
static let simulatedInAppHelper: any AppProductHelper = {
|
2024-11-28 16:31:17 +00:00
|
|
|
if AppCommandLine.contains(.fakeIAP) {
|
2024-11-28 00:30:26 +00:00
|
|
|
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 {
|
2024-11-28 16:31:17 +00:00
|
|
|
if AppCommandLine.contains(.fakeIAP) {
|
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
|
|
|
}
|
|
|
|
}
|