-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add History Debug Menu on macOS and display only 1 week of history wh…
…en history view is enabled (#3833) Task/Issue URL: https://app.asana.com/0/72649045549333/1209328755192085 Description: This change updates History Menu when historyView feature flag is enabled, to only keep history items for last 7 days, and offer opening Full History View in order to view all history. For testing purposes, History Debug Menu was added, where history can be populated with visits to fake websites.
- Loading branch information
Showing
14 changed files
with
155 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// | ||
// HistoryDebugMenu.swift | ||
// | ||
// Copyright © 2025 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import AppKit | ||
import History | ||
|
||
final class HistoryDebugMenu: NSMenu { | ||
|
||
let historyCoordinator: HistoryCoordinating | ||
|
||
private let environmentMenu = NSMenu() | ||
|
||
init(historyCoordinator: HistoryCoordinating = HistoryCoordinator.shared) { | ||
self.historyCoordinator = historyCoordinator | ||
super.init(title: "") | ||
|
||
buildItems { | ||
NSMenuItem( | ||
title: "Add 10 history visits each day (10 domains)", | ||
action: #selector(populateFakeHistory), | ||
target: self, | ||
representedObject: (10, FakeURLsPool.random10Domains) | ||
) | ||
NSMenuItem( | ||
title: "Populate 100 history visits each day (10 domains)", | ||
action: #selector(populateFakeHistory), | ||
target: self, | ||
representedObject: (100, FakeURLsPool.random10Domains) | ||
) | ||
NSMenuItem( | ||
title: "Populate 100 history visits each day (200 domains – SLOW!)", | ||
action: #selector(populateFakeHistory), | ||
target: self, | ||
representedObject: (100, FakeURLsPool.random200Domains) | ||
) | ||
} | ||
} | ||
|
||
required init(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
@objc func populateFakeHistory(_ sender: NSMenuItem) { | ||
guard let (maxVisitsPerDay, pool) = sender.representedObject as? (Int, FakeURLsPool) else { | ||
return | ||
} | ||
Task.detached { | ||
self.populateHistory(maxVisitsPerDay, pool.urls) | ||
} | ||
} | ||
|
||
private func populateHistory(_ maxVisitsPerDay: Int, _ urls: [URL]) { | ||
var date = Date() | ||
let endDate = Date.monthAgo | ||
|
||
var visitsPerDay = 0 | ||
|
||
while date > endDate { | ||
guard let url = urls.randomElement() else { | ||
continue | ||
} | ||
let visitDate = Date(timeIntervalSince1970: TimeInterval.random(in: date.startOfDay.timeIntervalSince1970..<date.timeIntervalSince1970)) | ||
historyCoordinator.addVisit(of: url, at: visitDate) | ||
visitsPerDay += 1 | ||
if visitsPerDay >= maxVisitsPerDay { | ||
date = date.daysAgo(1) | ||
visitsPerDay = 0 | ||
} | ||
} | ||
} | ||
|
||
enum FakeURLsPool { | ||
case random10Domains | ||
case random200Domains | ||
|
||
var urls: [URL] { | ||
switch self { | ||
case .random10Domains: | ||
Self.fakeURLs10Domains | ||
case .random200Domains: | ||
Self.fakeURLs200Domains | ||
} | ||
} | ||
|
||
private static let fakeURLs10Domains: [URL] = generateFakeURLs(numberOfDomains: 10) | ||
private static let fakeURLs200Domains: [URL] = generateFakeURLs(numberOfDomains: 200) | ||
|
||
private static func generateFakeURLs(numberOfDomains: Int) -> [URL] { | ||
(0..<numberOfDomains).flatMap { _ in | ||
let hostname = UUID().uuidString.lowercased().prefix(8) | ||
return (1...3).map { i in | ||
"https://\(hostname).com/index\(i).html".url! | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters