Skip to content

Commit

Permalink
Fixex #1824 - Redirect universal links directly to the browser if the…
Browse files Browse the repository at this point in the history
…y're not supported
  • Loading branch information
stefanceriu committed Oct 5, 2023
1 parent 82abd0a commit b1ed681
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
26 changes: 25 additions & 1 deletion ElementX/Sources/Application/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct Application: App {
})
.onOpenURL {
if !appCoordinator.handleDeepLink($0) {
openURL($0)
openURLInSystemBrowser($0)
}
}
.introspect(.window, on: .supportedVersions) { window in
Expand All @@ -57,8 +57,32 @@ struct Application: App {
}
}
}

// MARK: - Private

/// Hide the status bar so it doesn't interfere with the screenshot tests
private var shouldHideStatusBar: Bool {
ProcessInfo.isRunningUITests
}

/// https://github.com/vector-im/element-x-ios/issues/1824
/// Avoid opening universal links in other app variants and infinite loops between them
private func openURLInSystemBrowser(_ originalURL: URL) {
guard var urlComponents = URLComponents(url: originalURL, resolvingAgainstBaseURL: true) else {
openURL(originalURL)
return
}

var queryItems = urlComponents.queryItems ?? []
queryItems.append(.init(name: "no_universal_links", value: "true"))

urlComponents.queryItems = queryItems

guard let url = urlComponents.url else {
openURL(originalURL)
return
}

openURL(url)
}
}
1 change: 1 addition & 0 deletions ElementX/SupportingFiles/ElementX.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<string>applinks:develop.element.io</string>
<string>applinks:mobile.element.io</string>
<string>applinks:call.element.io</string>
<string>applinks:call.element.dev</string>
<string>webcredentials:*.element.io</string>
</array>
<key>com.apple.developer.usernotifications.communication</key>
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1824.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Redirect universal links directly to the browser if they're not supported

0 comments on commit b1ed681

Please sign in to comment.