Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 1a8168e

Browse files
dnarcesechrmod
authored andcommitted
Fix #7326: Add deeplink for changing default browser (#7328)
1 parent 12323b6 commit 1a8168e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Diff for: Client/Application/NavigationRouter.swift

+18
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ enum SettingsPage: String {
2929
case fxa = "fxa"
3030
}
3131

32+
enum DefaultBrowserPath: String {
33+
case systemSettings = "system-settings"
34+
}
35+
3236
// Used by the App to navigate to different views.
3337
// To open a URL use /open-url or to open a blank tab use /open-url with no params
3438
enum DeepLink {
3539
case settings(SettingsPage)
3640
case homePanel(HomePanelPath)
41+
case defaultBrowser(DefaultBrowserPath)
3742
init?(urlString: String) {
3843
let paths = urlString.split(separator: "/")
3944
guard let component = paths[safe: 0], let componentPath = paths[safe: 1] else {
@@ -43,6 +48,8 @@ enum DeepLink {
4348
self = .settings(link)
4449
} else if component == "homepanel", let link = HomePanelPath(rawValue: String(componentPath)) {
4550
self = .homePanel(link)
51+
} else if component == "default-browser", let link = DefaultBrowserPath(rawValue: String(componentPath)) {
52+
self = .defaultBrowser(link)
4653
} else {
4754
return nil
4855
}
@@ -126,6 +133,8 @@ enum NavigationPath {
126133
break
127134
case .settings(let settingsPath):
128135
NavigationPath.handleSettings(settings: settingsPath, and: bvc)
136+
case .defaultBrowser(let path):
137+
NavigationPath.handleDefaultBrowser(path: path)
129138
}
130139
}
131140

@@ -180,6 +189,13 @@ enum NavigationPath {
180189
break
181190
}
182191
}
192+
193+
private static func handleDefaultBrowser(path: DefaultBrowserPath) {
194+
switch path {
195+
case .systemSettings:
196+
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:])
197+
}
198+
}
183199
}
184200

185201
extension NavigationPath: Equatable {}
@@ -203,6 +219,8 @@ func == (lhs: DeepLink, rhs: DeepLink) -> Bool {
203219
return lhs == rhs
204220
case let (.homePanel(lhs), .homePanel(rhs)):
205221
return lhs == rhs
222+
case let (.defaultBrowser(lhs), .defaultBrowser(rhs)):
223+
return lhs == rhs
206224
default:
207225
return false
208226
}

Diff for: ClientTests/NavigationRouterTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class NavigationRouterTests: XCTestCase {
3939
XCTAssertEqual(NavigationPath(url: URL(string: "\(appScheme)://deep-link?url=/homepanel/bookmarks")!), NavigationPath.deepLink(DeepLink.homePanel(.bookmarks)))
4040
XCTAssertEqual(NavigationPath(url: URL(string: "\(appScheme)://deep-link?url=/homepanel/top-sites")!), NavigationPath.deepLink(DeepLink.homePanel(.topSites)))
4141
XCTAssertEqual(NavigationPath(url: URL(string: "\(appScheme)://deep-link?url=/homepanel/history")!), NavigationPath.deepLink(DeepLink.homePanel(.history)))
42+
XCTAssertEqual(NavigationPath(url: URL(string: "\(appScheme)://deep-link?url=/default-browser/system-settings")!), NavigationPath.deepLink(DeepLink.defaultBrowser(.systemSettings)))
4243
XCTAssertEqual(NavigationPath(url: URL(string: "\(appScheme)://deep-link?url=/homepanel/badbad")!), nil)
4344
}
4445

0 commit comments

Comments
 (0)