Skip to content

Commit

Permalink
Dismiss banner after purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
tobihagemann committed Nov 29, 2024
1 parent 8601108 commit ff49b0f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cryptomator/MainCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ extension MainCoordinator: StoreObserverDelegate {
switch transaction {
case .fullVersion, .yearlySubscription:
showFullVersionAlert()
// Temporarily added for December 2024 Sale
NotificationCenter.default.post(name: .dismissBannerNotification, object: nil)
case let .freeTrial(expiresOn):
showTrialAlert(expirationDate: expiresOn)
case .unknown:
Expand Down
2 changes: 2 additions & 0 deletions Cryptomator/Purchase/PurchaseCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class PurchaseCoordinator: Coordinator {
PurchaseAlert.showForFullVersion(title: LocalizedString.getValue("purchase.unlockedFullVersion.title"), on: navigationController).then {
self.unlockedPro()
}
// Temporarily added for December 2024 Sale
NotificationCenter.default.post(name: .dismissBannerNotification, object: nil)
}

func handleRestoreResult(_ result: RestoreTransactionsResult) {
Expand Down
12 changes: 10 additions & 2 deletions Cryptomator/VaultList/VaultListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ class VaultListViewController: ListViewController<VaultCellViewModel> {
weak var coordinator: MainCoordinator?

private let viewModel: VaultListViewModelProtocol
private var observer: NSObjectProtocol?
private var willEnterForegroundObserver: NSObjectProtocol?
@Dependency(\.fullVersionChecker) private var fullVersionChecker
@Dependency(\.cryptomatorSettings) private var cryptomatorSettings

#if !ALWAYS_PREMIUM
private var bannerView: UIView?
private var fullVersionPurchasedObserver: NSObjectProtocol?
#endif

init(with viewModel: VaultListViewModelProtocol) {
Expand All @@ -49,13 +50,16 @@ class VaultListViewController: ListViewController<VaultCellViewModel> {
let addNewVaulButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addNewVault))
navigationItem.rightBarButtonItem = addNewVaulButton

observer = NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: .main) { [weak self] _ in
willEnterForegroundObserver = NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: .main) { [weak self] _ in
self?.viewModel.refreshVaultLockStates().catch { error in
DDLogError("Refresh vault lock states failed with error: \(error)")
}
}

#if !ALWAYS_PREMIUM
fullVersionPurchasedObserver = NotificationCenter.default.addObserver(forName: .dismissBannerNotification, object: nil, queue: .main) { [weak self] _ in
self?.dismissBanner()
}
checkAndShowBanner()
#endif
}
Expand Down Expand Up @@ -204,3 +208,7 @@ class VaultListViewController: ListViewController<VaultCellViewModel> {
}
#endif
}

extension Notification.Name {
static let dismissBannerNotification = Notification.Name("DismissBannerNotification")
}

0 comments on commit ff49b0f

Please sign in to comment.