Ack new refunds only if refunds list was altered

Fixes #238
This commit is contained in:
Davide De Rosa 2022-10-25 12:48:45 +02:00
parent e1d8ec6066
commit e28bb3db9a
3 changed files with 18 additions and 2 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- OpenVPN: Tunnel dying prematurely. [tunnelkit#289](https://github.com/passepartoutvpn/tunnelkit/issues/289), [#237](https://github.com/passepartoutvpn/passepartout-apple/issues/237)
- OpenVPN: Local network settings being ignored. [tunnelkit#290](https://github.com/passepartoutvpn/tunnelkit/issues/290)
- Restore "Reconnect" action in profiles. [#232](https://github.com/passepartoutvpn/passepartout-apple/pull/232)
- Systematic uninstallation of VPN profile if any IAP was refunded. [#238](https://github.com/passepartoutvpn/passepartout-apple/issues/238)
## 2.0.1 (2022-10-17)

View File

@ -63,6 +63,8 @@ class ProductManager: NSObject, ObservableObject {
private var cancelledPurchases: Set<LocalProduct>
private var cancelledPurchasesSnapshot: Set<LocalProduct>
private var refreshRequest: SKReceiptRefreshRequest?
init(appType: AppType, buildProducts: BuildProducts) {
@ -75,6 +77,7 @@ class ProductManager: NSObject, ObservableObject {
purchasedFeatures = []
purchaseDates = [:]
cancelledPurchases = []
cancelledPurchasesSnapshot = []
super.init()
@ -281,8 +284,17 @@ extension ProductManager: SKPaymentTransactionObserver {
}
extension ProductManager {
func hasRefunded() -> Bool {
func snapshotRefunds() {
cancelledPurchasesSnapshot = cancelledPurchases
}
func hasNewRefunds() -> Bool {
reloadReceipt(andNotify: false)
guard cancelledPurchases != cancelledPurchasesSnapshot else {
pp_log.debug("No purchase was refunded")
return false
}
let isEligibleForFullVersion = isFullVersion()
let hasCancelledFullVersion: Bool
let hasCancelledTrustedNetworks: Bool

View File

@ -85,8 +85,11 @@ extension OrganizerView {
private func onScenePhase(_ phase: ScenePhase) {
switch phase {
case .inactive:
productManager.snapshotRefunds()
case .active:
if productManager.hasRefunded() {
if productManager.hasNewRefunds() {
Task { @MainActor in
await vpnManager.uninstall()
}