2023-12-16 19:58:54 +00:00
|
|
|
//
|
2024-11-21 15:03:57 +00:00
|
|
|
// InAppProcessor.swift
|
2023-12-16 19:58:54 +00:00
|
|
|
// Passepartout
|
|
|
|
//
|
2024-10-06 17:19:16 +00:00
|
|
|
// Created by Davide De Rosa on 10/6/24.
|
2024-01-14 13:34:21 +00:00
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
2023-12-16 19:58:54 +00:00
|
|
|
//
|
|
|
|
// 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 Foundation
|
2024-09-23 13:02:26 +00:00
|
|
|
import PassepartoutKit
|
2023-12-16 19:58:54 +00:00
|
|
|
|
2024-11-21 15:03:57 +00:00
|
|
|
public final class InAppProcessor: ObservableObject, Sendable {
|
2024-11-04 22:34:22 +00:00
|
|
|
private let iapManager: IAPManager
|
|
|
|
|
2024-11-21 15:03:57 +00:00
|
|
|
public nonisolated let _title: (Profile) -> String
|
2024-10-10 22:24:06 +00:00
|
|
|
|
2024-11-13 11:07:30 +00:00
|
|
|
private nonisolated let _isIncluded: (IAPManager, Profile) -> Bool
|
2024-11-04 22:34:22 +00:00
|
|
|
|
2024-11-22 11:52:51 +00:00
|
|
|
private nonisolated let _preview: (Profile) -> ProfilePreview
|
|
|
|
|
2024-11-28 16:31:17 +00:00
|
|
|
private nonisolated let _requiredFeatures: (IAPManager, Profile) -> Set<AppFeature>?
|
2024-11-25 18:17:18 +00:00
|
|
|
|
2024-11-21 15:03:57 +00:00
|
|
|
private nonisolated let _willRebuild: (IAPManager, Profile.Builder) throws -> Profile.Builder
|
2024-11-04 22:34:22 +00:00
|
|
|
|
2024-11-21 15:48:12 +00:00
|
|
|
private nonisolated let _willInstall: (IAPManager, Profile) throws -> Profile
|
2024-10-10 22:31:32 +00:00
|
|
|
|
|
|
|
public init(
|
2024-11-04 22:34:22 +00:00
|
|
|
iapManager: IAPManager,
|
2024-10-10 22:31:32 +00:00
|
|
|
title: @escaping (Profile) -> String,
|
2024-11-04 22:34:22 +00:00
|
|
|
isIncluded: @escaping (IAPManager, Profile) -> Bool,
|
2024-11-22 11:52:51 +00:00
|
|
|
preview: @escaping (Profile) -> ProfilePreview,
|
2024-11-28 16:31:17 +00:00
|
|
|
requiredFeatures: @escaping (IAPManager, Profile) -> Set<AppFeature>?,
|
2024-11-21 15:03:57 +00:00
|
|
|
willRebuild: @escaping (IAPManager, Profile.Builder) throws -> Profile.Builder,
|
2024-11-25 18:17:18 +00:00
|
|
|
willInstall: @escaping (IAPManager, Profile) throws -> Profile
|
2024-10-10 22:31:32 +00:00
|
|
|
) {
|
2024-11-04 22:34:22 +00:00
|
|
|
self.iapManager = iapManager
|
2024-11-21 15:03:57 +00:00
|
|
|
_title = title
|
2024-11-04 22:34:22 +00:00
|
|
|
_isIncluded = isIncluded
|
2024-11-22 11:52:51 +00:00
|
|
|
_preview = preview
|
2024-11-28 16:31:17 +00:00
|
|
|
_requiredFeatures = requiredFeatures
|
2024-11-21 15:03:57 +00:00
|
|
|
_willRebuild = willRebuild
|
2024-11-21 15:48:12 +00:00
|
|
|
_willInstall = willInstall
|
2024-11-04 22:34:22 +00:00
|
|
|
}
|
2024-11-21 15:03:57 +00:00
|
|
|
}
|
2024-11-04 22:34:22 +00:00
|
|
|
|
2024-11-21 15:03:57 +00:00
|
|
|
// MARK: - ProfileProcessor
|
|
|
|
|
|
|
|
extension InAppProcessor: ProfileProcessor {
|
|
|
|
public func title(for profile: Profile) -> String {
|
|
|
|
_title(profile)
|
2024-11-04 22:34:22 +00:00
|
|
|
}
|
|
|
|
|
2024-11-21 15:03:57 +00:00
|
|
|
public func isIncluded(_ profile: Profile) -> Bool {
|
|
|
|
_isIncluded(iapManager, profile)
|
2024-11-04 22:34:22 +00:00
|
|
|
}
|
|
|
|
|
2024-11-22 11:52:51 +00:00
|
|
|
public func preview(from profile: Profile) -> ProfilePreview {
|
|
|
|
_preview(profile)
|
|
|
|
}
|
|
|
|
|
2024-11-28 16:31:17 +00:00
|
|
|
public func requiredFeatures(_ profile: Profile) -> Set<AppFeature>? {
|
|
|
|
_requiredFeatures(iapManager, profile)
|
2024-11-19 07:55:41 +00:00
|
|
|
}
|
2024-11-25 18:17:18 +00:00
|
|
|
|
|
|
|
public func willRebuild(_ builder: Profile.Builder) throws -> Profile.Builder {
|
|
|
|
try _willRebuild(iapManager, builder)
|
|
|
|
}
|
2023-12-16 19:58:54 +00:00
|
|
|
}
|
2024-11-21 15:03:57 +00:00
|
|
|
|
|
|
|
// MARK: - TunnelProcessor
|
|
|
|
|
|
|
|
extension InAppProcessor: TunnelProcessor {
|
2024-11-21 15:48:12 +00:00
|
|
|
public func willInstall(_ profile: Profile) throws -> Profile {
|
|
|
|
try _willInstall(iapManager, profile)
|
2024-11-21 15:03:57 +00:00
|
|
|
}
|
|
|
|
}
|