Verify sharing/TV features only on profile save (#1023)

Do not verify sharing/TV on connect iOS/macOS.
This commit is contained in:
Davide 2024-12-18 09:16:58 +01:00 committed by GitHub
parent 47b0b79fd7
commit 2eca757dc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 13 deletions

View File

@ -136,7 +136,7 @@ private extension ProfileCoordinator {
func onCommitEditingStandard() async throws {
let savedProfile = try await profileEditor.save(to: profileManager, preferencesManager: preferencesManager)
do {
try iapManager.verify(savedProfile, isShared: profileEditor.isShared)
try iapManager.verify(savedProfile, extra: profileEditor.extraFeatures)
} catch AppError.ineligibleProfile(let requiredFeatures) {
paywallReason = .init(requiredFeatures, needsConfirmation: true)
return
@ -147,7 +147,7 @@ private extension ProfileCoordinator {
// restricted: verify before saving
func onCommitEditingRestricted() async throws {
do {
try iapManager.verify(profileEditor.activeModules, isShared: profileEditor.isShared)
try iapManager.verify(profileEditor.activeModules, extra: profileEditor.extraFeatures)
} catch AppError.ineligibleProfile(let requiredFeatures) {
paywallReason = .init(requiredFeatures)
return
@ -162,6 +162,19 @@ private extension ProfileCoordinator {
}
}
private extension ProfileEditor {
var extraFeatures: Set<AppFeature> {
var list: Set<AppFeature> = []
if isShared {
list.insert(.sharing)
}
if isAvailableForTV {
list.insert(.appleTV)
}
return list
}
}
// MARK: - Previews
#Preview {

View File

@ -34,11 +34,7 @@ extension Profile: AppFeatureRequiring {
}
return builder
}
var requirements = builders.features
if attributes.isAvailableForTV == true {
requirements.insert(.appleTV)
}
return requirements
return builders.features
}
}

View File

@ -27,18 +27,18 @@ import Foundation
import PassepartoutKit
extension IAPManager {
public func verify(_ profile: Profile, isShared: Bool = false) throws {
public func verify(_ profile: Profile, extra: Set<AppFeature>? = nil) throws {
var features = profile.features
if isShared {
features.insert(.sharing)
extra?.forEach {
features.insert($0)
}
try verify(features)
}
public func verify(_ modulesBuilders: [any ModuleBuilder], isShared: Bool = false) throws {
public func verify(_ modulesBuilders: [any ModuleBuilder], extra: Set<AppFeature>? = nil) throws {
var features = modulesBuilders.features
if isShared {
features.insert(.sharing)
extra?.forEach {
features.insert($0)
}
try verify(features)
}