mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-02-23 08:12:37 +00:00
#1070 is very tricky. When the device boots, StoreKit operations seem to be severely affected by on-demand VPN profiles. Slowdowns are huge and unpredictable, as per my [report on the Apple forums](https://developer.apple.com/forums/thread/773723). I found no easy way to work around the chicken-and-egg situation where the VPN requires StoreKit validation to start, but StoreKit requires network access. On the other hand, without StoreKit validations, the on-demand tunnel starts on boot just fine, and so does the app. No eternal activity indicators. StoreKit is clearly the culprit here. Therefore, below is the strategy that this PR implements for a decent trade-off: - Configure a graceful period for the VPN to start without limitations. This is initially set to 2 minutes in production, and 10 minutes in TestFlight. Postpone StoreKit validation until then. - After the graceful period, StoreKit validation is more likely to complete fast - At this point, paying users have their receipts validated and the connection will silently keep going - Non-paying users, instead, will see their connection hit the "Purchase required" message On the UI side, adjust the app accordingly: - Drop the "Purchase required" icon from the list/grid of profiles - The paywall informs that the connection will start, but it will disconnect after the graceful period if the receipt is not valid - Add a note that receipt validation may take a while if the device has just started This PR also introduces changes in TestFlight behavior: - Profiles can be saved without limitations - Profiles using free features work as usual - Profiles using paid features work for 10 minutes - Eligibility based on local receipt is ignored (deprecated in iOS 18) Beta users may therefore test all paid features on iOS/macOS/tvOS for 10 minutes. Until now, paid features were only available to paying iOS users and unavailable on macOS/tvOS. The tvOS beta was, in fact, completely useless. The downside is that paying iOS users will see beta builds restricted like anybody else. I'll see if I can find a better solution later.
101 lines
3.2 KiB
Swift
101 lines
3.2 KiB
Swift
//
|
|
// BundleConfiguration+AppGroup.swift
|
|
// Passepartout
|
|
//
|
|
// Created by Davide De Rosa on 10/4/24.
|
|
// Copyright (c) 2025 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 Foundation
|
|
import PassepartoutKit
|
|
|
|
// WARNING: beware of Constants.shared dependency
|
|
|
|
extension BundleConfiguration {
|
|
public static var urlForAppLog: URL {
|
|
urlForCaches.appending(path: Constants.shared.log.appPath)
|
|
}
|
|
|
|
public static var urlForTunnelLog: URL {
|
|
urlForCaches.appending(path: Constants.shared.log.tunnelPath)
|
|
}
|
|
}
|
|
|
|
// App Group container is not available on tvOS (#1007)
|
|
|
|
#if !os(tvOS)
|
|
|
|
extension BundleConfiguration {
|
|
public static var urlForCaches: URL {
|
|
let url = appGroupURL.appending(components: "Library", "Caches")
|
|
do {
|
|
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
|
|
} catch {
|
|
pp_log(.app, .fault, "Unable to create group caches directory: \(error)")
|
|
}
|
|
return url
|
|
}
|
|
|
|
public static var urlForDocuments: URL {
|
|
let url = appGroupURL.appending(components: "Library", "Documents")
|
|
do {
|
|
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
|
|
} catch {
|
|
pp_log(.app, .fault, "Unable to create group documents directory: \(error)")
|
|
}
|
|
return url
|
|
}
|
|
}
|
|
|
|
private extension BundleConfiguration {
|
|
static var appGroupURL: URL {
|
|
let groupId = mainString(for: .groupId)
|
|
guard let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupId) else {
|
|
pp_log(.app, .error, "Unable to access App Group container")
|
|
return FileManager.default.temporaryDirectory
|
|
}
|
|
return url
|
|
}
|
|
}
|
|
|
|
#else
|
|
|
|
extension BundleConfiguration {
|
|
public static var urlForCaches: URL {
|
|
do {
|
|
return try FileManager.default.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
|
|
} catch {
|
|
pp_log(.app, .fault, "Unable to create user documents directory: \(error)")
|
|
return URL(fileURLWithPath: NSTemporaryDirectory())
|
|
}
|
|
}
|
|
|
|
public static var urlForDocuments: URL {
|
|
do {
|
|
return try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
|
|
} catch {
|
|
pp_log(.app, .fault, "Unable to create user documents directory: \(error)")
|
|
return URL(fileURLWithPath: NSTemporaryDirectory())
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|