From be73f44321c560a415c35e45cd1c5f0d5eeef310 Mon Sep 17 00:00:00 2001 From: Fernando Bunn Date: Wed, 20 Dec 2023 13:04:35 +0000 Subject: [PATCH] Do not reload DBP tab when switching to it (#1942) Task/Issue URL: https://app.asana.com/0/1203581873609357/1206115814306009/f **Description**: Do not reload the DBP tab when switching to it --- .../Tab/View/BrowserTabViewController.swift | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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()