Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBP: Implement sign-out flow for DBP #2009

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DuckDuckGo/DBP/DataBrokerProtectionFeatureDisabler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import Foundation
import DataBrokerProtection

public extension Notification.Name {
static let dbpWasDisabled = Notification.Name("com.duckduckgo.DBP.DBPWasDisabled")
}

protocol DataBrokerProtectionFeatureDisabling {
func disableAndDelete()
}
Expand All @@ -40,6 +44,8 @@ struct DataBrokerProtectionFeatureDisabler: DataBrokerProtectionFeatureDisabling
scheduler.disableLoginItem()

dataManager.removeAllData()

NotificationCenter.default.post(name: .dbpWasDisabled, object: nil)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ final class DataBrokerProtectionSubscriptionEventHandler {

private let accountManager: Subscription.AccountManaging
private let authRepository: AuthenticationRepository
private let featureDisabler: DataBrokerProtectionFeatureDisabling

init(accountManager: Subscription.AccountManaging = Subscription.AccountManager(),
authRepository: AuthenticationRepository = KeychainAuthenticationData()) {
init(accountManager: Subscription.AccountManaging = AccountManager(),
authRepository: AuthenticationRepository = KeychainAuthenticationData(),
featureDisabler: DataBrokerProtectionFeatureDisabling = DataBrokerProtectionFeatureDisabler()) {
self.accountManager = accountManager
self.authRepository = authRepository
self.featureDisabler = featureDisabler
}

func registerForSubscriptionAccountManagerEvents() {
Expand All @@ -48,7 +51,7 @@ final class DataBrokerProtectionSubscriptionEventHandler {
}

@objc private func handleAccountDidSignOut() {
// Going to be defined here: https://app.asana.com/0/1204006570077678/1206206961074916/f
featureDisabler.disableAndDelete()
}
}

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/Tab/View/BrowserTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ final class BrowserTabViewController: NSViewController {
object: nil)

#if DBP
NotificationCenter.default.addObserver(self,
selector: #selector(onDBPFeatureDisabled),
name: .dbpWasDisabled,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(onCloseDataBrokerProtection),
name: .dbpDidClose,
Expand Down Expand Up @@ -165,6 +169,11 @@ final class BrowserTabViewController: NSViewController {
}

#if DBP
@objc
private func onDBPFeatureDisabled(_ notification: Notification) {
tabCollectionViewModel.removeAll(with: .dataBrokerProtection)
}

@objc
private func onCloseDataBrokerProtection(_ notification: Notification) {
guard let activeTab = tabCollectionViewModel.selectedTabViewModel?.tab,
Expand Down
10 changes: 10 additions & 0 deletions DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}

@MainActor
final class TabCollectionViewModel: NSObject {

Check failure on line 40 in DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Type body should span 500 lines or less excluding comments and whitespace: currently spans 503 lines (type_body_length)

weak var delegate: TabCollectionViewModelDelegate?

Expand Down Expand Up @@ -361,6 +361,16 @@

// MARK: - Removal

func removeAll(with content: Tab.TabContent) {
let tabs = tabCollection.tabs.filter { $0.content == content }

for tab in tabs {
if let index = indexInAllTabs(of: tab) {
remove(at: index)
}
}
}

func remove(at index: TabIndex, published: Bool = true, forceChange: Bool = false) {
switch index {
case .unpinned(let i):
Expand Down
Loading