mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 08:15:24 +00:00
8753fe3980
Second step towards loading MapLibre on demand: everything that touches it now lives in one framework, so that framework can later be left unlinked. The interactive map view, its annotation view and the coordinate animator move into MapLibreShim, which reaches the app through MapLibreShimProtocol. The app side keeps its MapLibreMapView call site and becomes a thin wrapper that builds a MapViewConfiguration, passing the app-only pieces (map style URLs, marker views, tint colour) across as closures so the shim needs nothing from the app. LocationAnnotation loses its MapLibre conformance and becomes a plain struct, with the shim mapping it onto its own annotation type. MapLibre's log forwarding moves into the shim as well, since TargetConfiguration can no longer reach it.
83 lines
2.9 KiB
Swift
83 lines
2.9 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
// Copyright 2022-2025 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import Combine
|
|
import Foundation
|
|
import MatrixRustSDK
|
|
|
|
nonisolated enum Target: String {
|
|
case mainApp = "elementx"
|
|
case nse
|
|
case shareExtension = "shareextension"
|
|
case tests
|
|
|
|
var useLightweightTokioRuntime: Bool {
|
|
switch self {
|
|
case .mainApp: false
|
|
case .nse: true
|
|
case .shareExtension: true
|
|
case .tests: false
|
|
}
|
|
}
|
|
|
|
var logFilePrefix: String {
|
|
switch self {
|
|
case .mainApp:
|
|
"console"
|
|
default:
|
|
rawValue
|
|
}
|
|
}
|
|
|
|
/// Configures the target with logging and an appropriate runtime.
|
|
///
|
|
/// Returns a `ConfigurationResult` which should be stored to
|
|
/// a) detect whether the platform is already configured.
|
|
/// b) automatically reconfigure the platform as necessary.
|
|
func configure(logLevel: LogLevel,
|
|
traceLogPacks: Set<TraceLogPack>,
|
|
sentryURL: URL?,
|
|
rageshakeURL: RemotePreference<RageshakeConfiguration>,
|
|
appHooks: AppHooks) -> ConfigurationResult {
|
|
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
|
|
traceLogPacks: traceLogPacks,
|
|
currentTarget: rawValue,
|
|
filePrefix: logFilePrefix,
|
|
sentryURL: sentryURL)
|
|
|
|
do {
|
|
try initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: useLightweightTokioRuntime)
|
|
} catch {
|
|
fatalError("Failed configuring target \(self) with error: \(error)")
|
|
}
|
|
|
|
// Setup sentry above but disable it by default. It will be started
|
|
// later together with the analytics service if the user consents.
|
|
enableSentryLogging(enabled: false)
|
|
|
|
MXLog.configure(currentTarget: rawValue)
|
|
|
|
let hookCancellable = rageshakeURL.publisher
|
|
.sink { _ in
|
|
appHooks.tracingHook.update(tracingConfiguration, with: rageshakeURL)
|
|
}
|
|
|
|
return ConfigurationResult(hookCancellable: hookCancellable)
|
|
}
|
|
|
|
/// The result of calling ``configure(logLevel:traceLogPacks:sentryURL:)``.
|
|
/// This must be stored - see the docs on the configure method to learn more.
|
|
struct ConfigurationResult {
|
|
private let hookCancellable: AnyCancellable
|
|
|
|
init(hookCancellable: AnyCancellable) {
|
|
self.hookCancellable = hookCancellable
|
|
}
|
|
}
|
|
}
|