-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/Issue URL: https://app.asana.com/0/414235014887631/1206524433066955/f Tech Design URL: CC: Description: Adds history collection to iOS Steps to test this PR: See add history to ios BrowserServicesKit#693 In the manager's computed var for the coordinator where the store is loaded, change code to set an error message and ensure that the preemptive crash alert is shown.
- Loading branch information
Showing
14 changed files
with
640 additions
and
34 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// HistoryCapture.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2024 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 Foundation | ||
import History | ||
|
||
public class HistoryCapture { | ||
|
||
enum VisitState { | ||
case added | ||
case expected | ||
} | ||
|
||
let historyManager: HistoryManaging | ||
var coordinator: HistoryCoordinating { | ||
historyManager.historyCoordinator | ||
} | ||
|
||
var url: URL? | ||
|
||
public init(historyManager: HistoryManaging) { | ||
self.historyManager = historyManager | ||
} | ||
|
||
public func webViewDidCommit(url: URL) { | ||
self.url = url | ||
coordinator.addVisit(of: url.urlOrDuckDuckGoCleanQuery) | ||
} | ||
|
||
public func titleDidChange(_ title: String?, forURL url: URL?) { | ||
guard self.url == url else { | ||
return | ||
} | ||
|
||
guard let url = url?.urlOrDuckDuckGoCleanQuery, let title, !title.isEmpty else { | ||
return | ||
} | ||
coordinator.updateTitleIfNeeded(title: title, url: url) | ||
coordinator.commitChanges(url: url) | ||
} | ||
|
||
} | ||
|
||
extension URL { | ||
|
||
var urlOrDuckDuckGoCleanQuery: URL { | ||
guard isDuckDuckGoSearch, | ||
let searchQuery, | ||
let url = URL.makeSearchURL(query: searchQuery)?.removingInternalSearchParameters() else { return self } | ||
return 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
Oops, something went wrong.