Use a different scheme for Element Call in the form of io.element.call:/?url=some_url

This commit is contained in:
Stefan Ceriu
2023-09-19 15:56:14 +03:00
committed by Stefan Ceriu
parent 501c3aed23
commit f95331d3a6
7 changed files with 43 additions and 21 deletions
@@ -80,15 +80,13 @@ struct ElementAppURLParser: URLParser {
/// The parser for Element Call links. This always returns a `.genericCallLink`
struct ElementCallURLParser: URLParser {
private let knownHosts = ["call.element.io"]
private let customSchemeHost = "call"
private let customSchemeURLQueryParameterName = "url"
func route(from url: URL) -> AppRoute? {
// First try processing URLs with custom schemes
if let scheme = url.scheme,
scheme == InfoPlistReader.app.appScheme {
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
components.host == customSchemeHost else {
scheme == InfoPlistReader.app.elementCallScheme {
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
return nil
}
+19 -9
View File
@@ -33,6 +33,7 @@ struct InfoPlistReader {
static let otlpTracingPassword = "otlpTracingPassword"
static let bundleURLTypes = "CFBundleURLTypes"
static let bundleURLName = "CFBundleURLName"
static let bundleURLSchemes = "CFBundleURLSchemes"
}
@@ -117,14 +118,11 @@ struct InfoPlistReader {
// MARK: - Custom App Scheme
var appScheme: String {
let urlTypes: [[String: Any]] = infoPlistValue(forKey: Keys.bundleURLTypes)
guard let urlSchemes = urlTypes.first?[Keys.bundleURLSchemes] as? [String],
let scheme = urlSchemes.first else {
fatalError("Invalid custon application scheme configuration")
}
return scheme
customSchemeForName("Application")
}
var elementCallScheme: String {
customSchemeForName("Element Call")
}
// MARK: - Mention Pills
@@ -140,11 +138,23 @@ struct InfoPlistReader {
}
// MARK: - Private
private func infoPlistValue<T>(forKey key: String) -> T {
guard let result = bundle.object(forInfoDictionaryKey: key) as? T else {
fatalError("Add \(key) into your target's Info.plst")
}
return result
}
private func customSchemeForName(_ name: String) -> String {
let urlTypes: [[String: Any]] = infoPlistValue(forKey: Keys.bundleURLTypes)
guard let urlType = urlTypes.first(where: { $0[Keys.bundleURLName] as? String == name }),
let urlSchemes = urlType[Keys.bundleURLSchemes] as? [String],
let scheme = urlSchemes.first else {
fatalError("Invalid custom application scheme configuration")
}
return scheme
}
}
+12 -2
View File
@@ -41,10 +41,20 @@
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>$(BASE_BUNDLE_IDENTIFIER)</string>
<string>Element Call</string>
<key>CFBundleURLSchemes</key>
<array>
<string>$(APP_CUSTOM_SCHEME)</string>
<string>io.element.call</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>Application</string>
<key>CFBundleURLSchemes</key>
<array>
<string>io.element</string>
</array>
</dict>
</array>
+9 -2
View File
@@ -57,9 +57,16 @@ targets:
CFBundleURLTypes: [
{
CFBundleTypeRole: Editor,
CFBundleURLName: $(BASE_BUNDLE_IDENTIFIER),
CFBundleURLName: "Element Call",
CFBundleURLSchemes: [
$(APP_CUSTOM_SCHEME)
io.element.call
]
},
{
CFBundleTypeRole: Editor,
CFBundleURLName: "Application",
CFBundleURLSchemes: [
io.element
]
}
]