mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Add developer options for Rust's Trace Log Packs. (#3929)
* Add support for configuring log packs. * Update call widget parameters. * Update the SDK.
This commit is contained in:
@@ -69,7 +69,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
|
||||
let appSettings = appHooks.appSettingsHook.configure(AppSettings())
|
||||
|
||||
Target.mainApp.configure(logLevel: appSettings.logLevel)
|
||||
Target.mainApp.configure(logLevel: appSettings.logLevel, traceLogPacks: appSettings.traceLogPacks)
|
||||
|
||||
let appName = InfoPlistReader.main.bundleDisplayName
|
||||
let appVersion = InfoPlistReader.main.bundleShortVersionString
|
||||
|
||||
@@ -11,6 +11,7 @@ import SwiftUI
|
||||
// Common settings between app and NSE
|
||||
protocol CommonSettingsProtocol {
|
||||
var logLevel: LogLevel { get }
|
||||
var traceLogPacks: Set<TraceLogPack> { get }
|
||||
var enableOnlySignedDeviceIsolationMode: Bool { get }
|
||||
var hideInviteAvatars: Bool { get }
|
||||
var hideTimelineMedia: Bool { get }
|
||||
@@ -36,6 +37,7 @@ final class AppSettings {
|
||||
case enableInAppNotifications
|
||||
case pusherProfileTag
|
||||
case logLevel
|
||||
case traceLogPacks
|
||||
case viewSourceEnabled
|
||||
case optimizeMediaUploads
|
||||
case appAppearance
|
||||
@@ -306,6 +308,9 @@ final class AppSettings {
|
||||
@UserPreference(key: UserDefaultsKeys.logLevel, defaultValue: LogLevel.info, storageType: .userDefaults(store))
|
||||
var logLevel
|
||||
|
||||
@UserPreference(key: UserDefaultsKeys.traceLogPacks, defaultValue: [], storageType: .userDefaults(store))
|
||||
var traceLogPacks: Set<TraceLogPack>
|
||||
|
||||
/// Configuration to enable only signed device isolation mode for crypto. In this mode only devices signed by their owner will be considered in e2ee rooms.
|
||||
@UserPreference(key: UserDefaultsKeys.enableOnlySignedDeviceIsolationMode, defaultValue: false, storageType: .userDefaults(store))
|
||||
var enableOnlySignedDeviceIsolationMode
|
||||
|
||||
@@ -15,23 +15,35 @@ enum Target: String {
|
||||
|
||||
private static var isConfigured = false
|
||||
|
||||
func configure(logLevel: LogLevel) {
|
||||
func configure(logLevel: LogLevel, traceLogPacks: Set<TraceLogPack>) {
|
||||
guard !Self.isConfigured else {
|
||||
return
|
||||
}
|
||||
|
||||
switch self {
|
||||
case .mainApp:
|
||||
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, currentTarget: rawValue, filePrefix: nil)
|
||||
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
|
||||
traceLogPacks: traceLogPacks,
|
||||
currentTarget: rawValue,
|
||||
filePrefix: nil)
|
||||
initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false)
|
||||
case .nse:
|
||||
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, currentTarget: rawValue, filePrefix: rawValue)
|
||||
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
|
||||
traceLogPacks: traceLogPacks,
|
||||
currentTarget: rawValue,
|
||||
filePrefix: rawValue)
|
||||
initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true)
|
||||
case .shareExtension:
|
||||
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, currentTarget: rawValue, filePrefix: rawValue)
|
||||
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
|
||||
traceLogPacks: traceLogPacks,
|
||||
currentTarget: rawValue,
|
||||
filePrefix: rawValue)
|
||||
initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: true)
|
||||
case .tests:
|
||||
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel, currentTarget: rawValue, filePrefix: rawValue)
|
||||
let tracingConfiguration = Tracing.buildConfiguration(logLevel: logLevel,
|
||||
traceLogPacks: traceLogPacks,
|
||||
currentTarget: rawValue,
|
||||
filePrefix: rawValue)
|
||||
initPlatform(config: tracingConfiguration, useLightweightTokioRuntime: false)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Copyright 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 Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
enum TraceLogPack: Codable, CaseIterable {
|
||||
case eventCache, sendQueue, timeline
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .eventCache:
|
||||
return "Event cache"
|
||||
case .sendQueue:
|
||||
return "Send queue"
|
||||
case .timeline:
|
||||
return "Timeline"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension TraceLogPack {
|
||||
// periphery:ignore - Unused, but added to detect new cases when updating the SDK.
|
||||
init(rustLogPack: MatrixRustSDK.TraceLogPacks) {
|
||||
switch rustLogPack {
|
||||
case .eventCache:
|
||||
self = .eventCache
|
||||
case .sendQueue:
|
||||
self = .sendQueue
|
||||
case .timeline:
|
||||
self = .timeline
|
||||
}
|
||||
}
|
||||
|
||||
var rustLogPack: MatrixRustSDK.TraceLogPacks {
|
||||
switch self {
|
||||
case .eventCache:
|
||||
return .eventCache
|
||||
case .sendQueue:
|
||||
return .sendQueue
|
||||
case .timeline:
|
||||
return .timeline
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ enum Tracing {
|
||||
|
||||
static let fileExtension = "log"
|
||||
|
||||
static func buildConfiguration(logLevel: LogLevel, currentTarget: String, filePrefix: String?) -> TracingConfiguration {
|
||||
static func buildConfiguration(logLevel: LogLevel, traceLogPacks: Set<TraceLogPack>, currentTarget: String, filePrefix: String?) -> TracingConfiguration {
|
||||
let fileName = if let filePrefix {
|
||||
"\(Tracing.filePrefix)-\(filePrefix)"
|
||||
} else {
|
||||
@@ -39,6 +39,7 @@ enum Tracing {
|
||||
let level: LogLevel = ProcessInfo.isRunningIntegrationTests ? .trace : logLevel
|
||||
|
||||
return .init(logLevel: level.rustLogLevel,
|
||||
traceLogPacks: traceLogPacks.map(\.rustLogPack),
|
||||
extraTargets: [currentTarget],
|
||||
writeToStdoutOrSystem: true,
|
||||
writeToFiles: .init(path: logsDirectory.path(percentEncoded: false),
|
||||
|
||||
+1
@@ -37,6 +37,7 @@ enum DeveloperOptionsScreenViewAction {
|
||||
|
||||
protocol DeveloperOptionsProtocol: AnyObject {
|
||||
var logLevel: LogLevel { get set }
|
||||
var traceLogPacks: Set<TraceLogPack> { get set }
|
||||
var publicSearchEnabled: Bool { get set }
|
||||
var hideUnreadMessagesBadge: Bool { get set }
|
||||
var fuzzyRoomListSearchEnabled: Bool { get set }
|
||||
|
||||
+22
@@ -21,6 +21,14 @@ struct DeveloperOptionsScreen: View {
|
||||
Form {
|
||||
Section("Logging") {
|
||||
LogLevelConfigurationView(logLevel: $context.logLevel)
|
||||
|
||||
DisclosureGroup("SDK trace packs") {
|
||||
ForEach(TraceLogPack.allCases, id: \.self) { pack in
|
||||
Toggle(isOn: $context.traceLogPacks[pack]) {
|
||||
Text(pack.title)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section("General") {
|
||||
@@ -153,6 +161,20 @@ private struct LogLevelConfigurationView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private extension Set<TraceLogPack> {
|
||||
/// A custom subscript that allows binding a toggle to add/remove a pack from the array.
|
||||
subscript(pack: TraceLogPack) -> Bool {
|
||||
get { contains(pack) }
|
||||
set {
|
||||
if newValue {
|
||||
insert(pack)
|
||||
} else {
|
||||
remove(pack)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct DeveloperOptionsScreen_Previews: PreviewProvider {
|
||||
|
||||
@@ -81,11 +81,17 @@ class ElementCallWidgetDriver: WidgetCapabilitiesProvider, ElementCallWidgetDriv
|
||||
preload: nil,
|
||||
fontScale: nil,
|
||||
appPrompt: false,
|
||||
skipLobby: true,
|
||||
confineToRoom: true,
|
||||
font: nil,
|
||||
analyticsId: nil,
|
||||
encryption: useEncryption ? .perParticipantKeys : .unencrypted))
|
||||
encryption: useEncryption ? .perParticipantKeys : .unencrypted,
|
||||
intent: .startCall,
|
||||
hideScreensharing: false, // The web view will hide it automatically
|
||||
posthogUserId: nil,
|
||||
posthogApiHost: nil,
|
||||
posthogApiKey: nil,
|
||||
rageshakeSubmitUrl: nil,
|
||||
sentryDsn: nil,
|
||||
sentryEnvironment: nil))
|
||||
} catch {
|
||||
MXLog.error("Failed to build widget settings: \(error)")
|
||||
return .failure(.failedBuildingWidgetSettings)
|
||||
|
||||
Reference in New Issue
Block a user