diff --git a/DuckDuckGo/Tab/View/BrowserTabViewController.swift b/DuckDuckGo/Tab/View/BrowserTabViewController.swift index fc216e21c3..872b4fb27e 100644 --- a/DuckDuckGo/Tab/View/BrowserTabViewController.swift +++ b/DuckDuckGo/Tab/View/BrowserTabViewController.swift @@ -219,6 +219,10 @@ final class BrowserTabViewController: NSViewController { tabCollectionViewModel.tabCollection.$tabs .sink(receiveValue: setDelegate()) .store(in: &cancellables) + + tabCollectionViewModel.tabCollection.$tabs + .sink(receiveValue: removeDataBrokerViewIfNecessary()) + .store(in: &cancellables) } private func subscribeToPinnedTabs() { @@ -226,6 +230,19 @@ final class BrowserTabViewController: NSViewController { .sink(receiveValue: setDelegate()) } + private func removeDataBrokerViewIfNecessary() -> ([Tab]) -> Void { + { [weak self] (tabs: [Tab]) in + guard let self else { return } +#if DBP + if let dataBrokerProtectionHomeViewController, + !tabs.contains(where: { $0.content == .dataBrokerProtection }) { + dataBrokerProtectionHomeViewController.removeCompletely() + self.dataBrokerProtectionHomeViewController = nil + } +#endif + } + } + private func setDelegate() -> ([Tab]) -> Void { { [weak self] (tabs: [Tab]) in guard let self else { return } @@ -431,7 +448,6 @@ final class BrowserTabViewController: NSViewController { bookmarksViewController?.removeCompletely() #if DBP dataBrokerProtectionHomeViewController?.removeCompletely() - dataBrokerProtectionHomeViewController = nil #endif if includingWebView { self.removeWebViewFromHierarchy()