This repository has been archived by the owner on Feb 24, 2025. It is now read-only.
-
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.
Merge branch 'main' into alex/zoom-improvements
- Loading branch information
Showing
85 changed files
with
2,477 additions
and
242 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
CURRENT_PROJECT_VERSION = 354 | ||
CURRENT_PROJECT_VERSION = 359 |
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
15 changes: 15 additions & 0 deletions
15
DuckDuckGo/Assets.xcassets/Images/Help-16.imageset/Contents.json
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,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Help-16.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
DuckDuckGo/Assets.xcassets/Images/Support-16.imageset/Contents.json
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,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Support-16.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// HistoryGroupingProvider.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 BrowserServicesKit | ||
import Common | ||
import FeatureFlags | ||
import Foundation | ||
import History | ||
import os.log | ||
|
||
/** | ||
* This protocol describes a data source (history provider) for `HistoryGroupingProvider`. | ||
*/ | ||
protocol HistoryGroupingDataSource: AnyObject { | ||
var history: BrowsingHistory? { get } | ||
} | ||
|
||
extension HistoryCoordinator: HistoryGroupingDataSource {} | ||
|
||
/** | ||
* This class is responsible for grouping history visits for History Menu. | ||
* | ||
* When `historyView` feature flag is enabled, visits are deduplicated | ||
* to only have the latest visit per URL per day. | ||
*/ | ||
final class HistoryGroupingProvider { | ||
private let featureFlagger: FeatureFlagger | ||
private(set) weak var dataSource: HistoryGroupingDataSource? | ||
|
||
init(dataSource: HistoryGroupingDataSource, featureFlagger: FeatureFlagger = NSApp.delegateTyped.featureFlagger) { | ||
self.featureFlagger = featureFlagger | ||
self.dataSource = dataSource | ||
} | ||
|
||
/** | ||
* Returns visits for a given day. | ||
*/ | ||
func getRecentVisits(maxCount: Int) -> [Visit] { | ||
removeDuplicatesIfNeeded(from: getSortedArrayOfVisits()) | ||
.prefix(maxCount) | ||
.filter { Calendar.current.isDateInToday($0.date) } | ||
} | ||
|
||
/** | ||
* Returns history visits bucketed per day. | ||
*/ | ||
func getVisitGroupings() -> [HistoryMenu.HistoryGrouping] { | ||
Dictionary(grouping: getSortedArrayOfVisits(), by: \.date.startOfDay) | ||
.map { date, sortedVisits in | ||
HistoryMenu.HistoryGrouping(date: date, visits: removeDuplicatesIfNeeded(from: sortedVisits)) | ||
} | ||
.sorted { $0.date > $1.date } | ||
} | ||
|
||
private func removeDuplicatesIfNeeded(from sortedVisits: [Visit]) -> [Visit] { | ||
// History View introduces visits deduplication to declutter history. | ||
// We don't want to release it before History View, so we're | ||
// only deduplicating visits if the feature flag is on. | ||
guard featureFlagger.isFeatureOn(.historyView) else { | ||
return sortedVisits | ||
} | ||
// It's so simple because visits array is sorted by timestamp, so removing duplicates would | ||
// remove items with older timestamps (as proven by unit tests). | ||
return sortedVisits.removingDuplicates(byKey: \.historyEntry?.url) | ||
} | ||
|
||
private func getSortedArrayOfVisits() -> [Visit] { | ||
guard let history = dataSource?.history else { | ||
Logger.general.error("HistoryCoordinator: No history available") | ||
return [] | ||
} | ||
return history.flatMap(\.visits).sorted { $0.date > $1.date } | ||
} | ||
} |
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
Oops, something went wrong.