Skip to content

Commit

Permalink
Do not close tabs on subscription change due to issues during restore…
Browse files Browse the repository at this point in the history
… when expired subscription is found (#2522)

Task/Issue URL: https://app.asana.com/0/0/1206950879085056/f

**Description**:
Basically revert of
#2492 as it may lead to
crash.

**Steps to test this PR**:
Crash repro steps
1. Have Apple ID with expired or cancelled subscription
2. Try restore flow from the purchase page OR normal purchase
3. While the restoration is done we fetch the expired subscription,
insert it into cache, and this event causes all subscription tabs to
close
4. Closing tabs mid-purchase followed by interaction with alerts from
these tabs can lead to crash.


---
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)

Co-authored-by: Sam Symons <[email protected]>
  • Loading branch information
miasma13 and samsymons authored Apr 2, 2024
1 parent 6ee57a4 commit a9a6f0a
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions DuckDuckGo/Tab/View/BrowserTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ final class BrowserTabViewController: NSViewController {
selector: #selector(onSubscriptionAccountDidSignOut),
name: .accountDidSignOut,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(onSubscriptionDidChange),
name: .subscriptionDidChange,
object: nil)
#endif
}

Expand Down Expand Up @@ -258,25 +254,6 @@ final class BrowserTabViewController: NSViewController {
}
}

@objc
private func onSubscriptionDidChange(_ notification: Notification) {
guard let subscription = (notification.userInfo?[UserDefaultsCacheKey.subscription] as? DDGSubscription), !subscription.isActive else { return }

Task { @MainActor in
tabCollectionViewModel.removeAll { tabContent in
if case .subscription = tabContent {
return true
} else if case .identityTheftRestoration = tabContent {
return true
} else if case .dataBrokerProtection = tabContent {
return true
} else {
return false
}
}
}
}

#endif

private func subscribeToSelectedTabViewModel() {
Expand Down

0 comments on commit a9a6f0a

Please sign in to comment.