diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b097153..a7cc547b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Passepartout/App/InApp/ProductManager.swift b/Passepartout/App/InApp/ProductManager.swift index af4aab22..fc34cb6e 100644 --- a/Passepartout/App/InApp/ProductManager.swift +++ b/Passepartout/App/InApp/ProductManager.swift @@ -63,6 +63,8 @@ class ProductManager: NSObject, ObservableObject { private var cancelledPurchases: Set + private var cancelledPurchasesSnapshot: Set + 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 diff --git a/Passepartout/App/Views/OrganizerView+Scene.swift b/Passepartout/App/Views/OrganizerView+Scene.swift index 4215df2b..87b4cb2d 100644 --- a/Passepartout/App/Views/OrganizerView+Scene.swift +++ b/Passepartout/App/Views/OrganizerView+Scene.swift @@ -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() }