Skip to content

Commit

Permalink
cherry pick fix for clearing data (#2400)
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy authored Jan 29, 2024
1 parent 75e98e4 commit 6fb5136
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
{
"identity" : "trackerradarkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/TrackerRadarKit.git",
"location" : "https://github.com/duckduckgo/TrackerRadarKit",
"state" : {
"revision" : "a6b7ba151d9dc6684484f3785293875ec01cc1ff",
"version" : "1.2.2"
Expand Down
48 changes: 34 additions & 14 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class MainViewController: UIViewController {
private var skipSERPFlow = true

private var keyboardHeight: CGFloat = 0.0

var postClear: (() -> Void)?
var clearInProgress = false

required init?(coder: NSCoder) {
fatalError("Use init?(code:")
Expand Down Expand Up @@ -773,22 +776,30 @@ class MainViewController: UIViewController {
}

func loadUrlInNewTab(_ url: URL, reuseExisting: Bool = false, inheritedAttribution: AdClickAttributionLogic.State?) {
allowContentUnderflow = false
viewCoordinator.navigationBarContainer.alpha = 1
loadViewIfNeeded()
if reuseExisting, let existing = tabManager.first(withUrl: url) {
selectTab(existing)
return
} else if reuseExisting, let existing = tabManager.firstHomeTab() {
tabManager.selectTab(existing)
loadUrl(url)
func worker() {
allowContentUnderflow = false
viewCoordinator.navigationBarContainer.alpha = 1
loadViewIfNeeded()
if reuseExisting, let existing = tabManager.first(withUrl: url) {
selectTab(existing)
return
} else if reuseExisting, let existing = tabManager.firstHomeTab() {
tabManager.selectTab(existing)
loadUrl(url)
} else {
addTab(url: url, inheritedAttribution: inheritedAttribution)
}
refreshOmniBar()
refreshTabIcon()
refreshControls()
tabsBarController?.refresh(tabsModel: tabManager.model)
}

if clearInProgress {
postClear = worker
} else {
addTab(url: url, inheritedAttribution: inheritedAttribution)
worker()
}
refreshOmniBar()
refreshTabIcon()
refreshControls()
tabsBarController?.refresh(tabsModel: tabManager.model)
}

func enterSearch() {
Expand Down Expand Up @@ -2021,6 +2032,11 @@ extension MainViewController: AutoClearWorker {
}

func forgetData() {
guard !clearInProgress else {
assertionFailure("Shouldn't get called multiple times")
return
}
clearInProgress = true
URLSession.shared.configuration.urlCache?.removeAllCachedResponses()

let pixel = TimedPixel(.forgetAllDataCleared)
Expand All @@ -2035,6 +2051,10 @@ extension MainViewController: AutoClearWorker {
}

self.refreshUIAfterClear()
self.clearInProgress = false

self.postClear?()
self.postClear = nil
}

}
Expand Down

0 comments on commit 6fb5136

Please sign in to comment.