Skip to content

Commit

Permalink
Fix URL deeplink (#2035)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bunn authored Sep 26, 2023
1 parent 56e861d commit 7691228
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 12 additions & 1 deletion Core/AppDeepLinkSchemes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,21 @@ public enum AppDeepLinkSchemes: String, CaseIterable {
}

public static func query(fromQuickLink url: URL) -> String {
return url.absoluteString
let query = url.absoluteString
.replacingOccurrences(of: AppDeepLinkSchemes.quickLink.url.absoluteString,
with: "",
options: .caseInsensitive)

return AppDeepLinkSchemes.fixURLScheme(query)
}

private static func fixURLScheme(_ urlString: String) -> String {
let pattern = "^https?//"

if urlString.range(of: pattern, options: .regularExpression) != nil {
return urlString.replacingOccurrences(of: "//", with: "://")
} else {
return urlString
}
}
}
13 changes: 10 additions & 3 deletions DuckDuckGo/AppDelegate+AppDeepLinks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ extension AppDelegate {
mainViewController.newTab(reuseExisting: true)
mainViewController.enterSearch()


case .favorites:
mainViewController.newTab(reuseExisting: true, allowingKeyboard: false)

case .quickLink:
let query = AppDeepLinkSchemes.query(fromQuickLink: url)
mainViewController.loadQueryInNewTab(query, reuseExisting: true)
handleQuickLink(url, mainViewController)

case .addFavorite:
mainViewController.startAddFavoriteFlow()
Expand Down Expand Up @@ -67,4 +65,13 @@ extension AppDelegate {
return true
}

private func handleQuickLink(_ url: URL, _ mainViewController: MainViewController) {
let query = AppDeepLinkSchemes.query(fromQuickLink: url)
if let url = URL(string: query) {
mainViewController.loadUrlInNewTab(url, reuseExisting: true, inheritedAttribution: nil)
} else {
mainViewController.loadQueryInNewTab(query, reuseExisting: true)
}
}

}

0 comments on commit 7691228

Please sign in to comment.