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

Commit

Permalink
Ref #3939: When deleting history, delete its Screen Time entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub committed Sep 25, 2023
1 parent e6da27d commit 2c05eca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import BraveCore
import Favicon
import UIKit
import DesignSystem
import ScreenTime

class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol {

Expand Down Expand Up @@ -293,6 +294,13 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol
// Reoving a history item should remove its corresponded Recently Closed item
RecentlyClosed.remove(with: historyItem.url.absoluteString)

do {
let screenTimeHistory = try STWebHistory(bundleIdentifier: Bundle.main.bundleIdentifier!)
screenTimeHistory.deleteHistory(for: historyItem.url)
} catch {
assertionFailure("STWebHistory could not be initialized: \(error)")
}

if isHistoryBeingSearched {
reloadDataAndShowLoading(with: searchQuery)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import BraveCore
import BraveShared
import CoreData
import Shared
import ScreenTime

extension BraveHistoryAPI {

Expand Down Expand Up @@ -53,10 +54,20 @@ extension BraveHistoryAPI {
}
}

func deleteAll(completion: @escaping () -> Void) {
func deleteAll(includeScreenTimeHistory: Bool = true, completion: @escaping () -> Void) {
var screenTimeHistory: STWebHistory?
if includeScreenTimeHistory {
do {
screenTimeHistory = try STWebHistory(bundleIdentifier: Bundle.main.bundleIdentifier!)
} catch {
assertionFailure("STWebHistory could not be initialized: \(error)")
}
}

DispatchQueue.main.async {
self.removeAll {
Domain.deleteNonBookmarkedAndClearSiteVisits() {
screenTimeHistory?.deleteAllHistory()
completion()
}
}
Expand Down

0 comments on commit 2c05eca

Please sign in to comment.