Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #7439: Update clear history app intent for SwiftUI (#8501)
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel authored and Brandon-T committed Dec 14, 2023
1 parent 5f1626f commit b9c73e7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ extension BrowserViewController: TopToolbarDelegate {
feedDataSource: self.feedDataSource,
historyAPI: self.braveCore.historyAPI,
p3aUtilities: self.braveCore.p3aUtils,
clearDataCallback: { [weak self] isLoading in
clearDataCallback: { [weak self] isLoading, isHistoryCleared in
guard let view = self?.navigationController?.view, view.window != nil else {
assertionFailure()
return
Expand All @@ -416,6 +416,13 @@ extension BrowserViewController: TopToolbarDelegate {
spinner?.dismiss()
spinner = nil
}

if isHistoryCleared {
// Donate Clear Browser History for suggestions
let clearBrowserHistoryActivity = ActivityShortcutManager.shared.createShortcutActivity(type: .clearBrowsingHistory)
self?.userActivity = clearBrowserHistoryActivity
clearBrowserHistoryActivity.becomeCurrent()
}
}
))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol

// Clearing History should clear Recently Closed
RecentlyClosed.removeAll()

// Donate Clear Browser History for suggestions
let clearBrowserHistoryActivity = ActivityShortcutManager.shared.createShortcutActivity(type: .clearBrowsingHistory)
self.userActivity = clearBrowserHistoryActivity
clearBrowserHistoryActivity.becomeCurrent()
}

// Asking Sync Engine To Remove Visits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import os
}
}

typealias ClearDataCallback = @MainActor (Bool) -> Void
typealias ClearDataCallback = @MainActor (Bool, Bool) -> Void
@Published var clearableSettings: [ClearableSetting]

private var subscriptions: [AnyCancellable] = []
Expand Down Expand Up @@ -106,12 +106,12 @@ import os
}

func clearPrivateData(_ clearables: [Clearable]) async {
clearDataCallback(true)
await clearPrivateDataInternal(clearables)
clearDataCallback(false)
clearDataCallback(true, false)
let isHistoryCleared = await clearPrivateDataInternal(clearables)
clearDataCallback(false, isHistoryCleared)
}

private func clearPrivateDataInternal(_ clearables: [Clearable]) async {
private func clearPrivateDataInternal(_ clearables: [Clearable]) async -> Bool {
@Sendable func _clear(_ clearables: [Clearable], secondAttempt: Bool = false) async {
await withThrowingTaskGroup(of: Void.self) { group in
for clearable in clearables {
Expand Down Expand Up @@ -176,6 +176,8 @@ import os
}

_toggleFolderAccessForBlockCookies(locked: true)

return historyCleared
}

private func registerSubscriptions() {
Expand Down
9 changes: 8 additions & 1 deletion Sources/Brave/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class SettingsViewController: TableViewController {
feedDataSource: self.feedDataSource,
historyAPI: self.historyAPI,
p3aUtilities: self.p3aUtilities,
clearDataCallback: { [weak self] isLoading in
clearDataCallback: { [weak self] isLoading, isHistoryCleared in
guard let view = self?.navigationController?.view, view.window != nil else {
assertionFailure()
return
Expand All @@ -259,6 +259,13 @@ class SettingsViewController: TableViewController {
spinner?.dismiss()
spinner = nil
}

if isHistoryCleared {
// Donate Clear Browser History for suggestions
let clearBrowserHistoryActivity = ActivityShortcutManager.shared.createShortcutActivity(type: .clearBrowsingHistory)
self?.userActivity = clearBrowserHistoryActivity
clearBrowserHistoryActivity.becomeCurrent()
}
}
))

Expand Down

0 comments on commit b9c73e7

Please sign in to comment.