From 88131ce776838cf26cb8f46f9c45d63b81323304 Mon Sep 17 00:00:00 2001 From: Doug Date: Wed, 27 Aug 2025 16:13:39 +0100 Subject: [PATCH] Remove the BugReportService from the ServiceLocator. It is directly injected everywhere now. --- .../AccessibilityTestsAppCoordinator.swift | 1 - .../Sources/Application/AppCoordinator.swift | 26 ++++++++++--------- .../Sources/Application/ServiceLocator.swift | 6 ----- .../UITests/UITestsAppCoordinator.swift | 1 - .../UnitTests/UnitTestsAppCoordinator.swift | 1 - 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/ElementX/Sources/AccessibilityTests/AccessibilityTestsAppCoordinator.swift b/ElementX/Sources/AccessibilityTests/AccessibilityTestsAppCoordinator.swift index f0bdfc346..0eeea8729 100644 --- a/ElementX/Sources/AccessibilityTests/AccessibilityTestsAppCoordinator.swift +++ b/ElementX/Sources/AccessibilityTests/AccessibilityTestsAppCoordinator.swift @@ -40,7 +40,6 @@ class AccessibilityTestsAppCoordinator: AppCoordinatorProtocol { AppSettings.configureWithSuiteName("io.element.elementx.accessibilitytests") AppSettings.resetAllSettings() ServiceLocator.shared.register(appSettings: AppSettings()) - ServiceLocator.shared.register(bugReportService: BugReportServiceMock(.init())) let analyticsClient = AnalyticsClientMock() analyticsClient.isRunning = false diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 4df113964..0bd2d8402 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -23,6 +23,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg private let appSettings: AppSettings private let appDelegate: AppDelegate private let appHooks: AppHooks + private let bugReportService: BugReportServiceProtocol private let elementCallService: ElementCallServiceProtocol /// Common background task to continue long-running tasks in the background. @@ -115,8 +116,13 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg notificationManager = NotificationManager(notificationCenter: UNUserNotificationCenter.current(), appSettings: appSettings) + bugReportService = BugReportService(rageshakeURLPublisher: appSettings.bugReportRageshakeURL.publisher, + applicationID: appSettings.bugReportApplicationID, + sdkGitSHA: sdkGitSha(), + maxUploadSize: appSettings.bugReportMaxUploadSize, + appHooks: appHooks) Self.setupServiceLocator(appSettings: appSettings, appHooks: appHooks) - Self.setupSentry(appSettings: appSettings) + Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings) ServiceLocator.shared.analytics.signpost.start() ServiceLocator.shared.analytics.startIfEnabled() @@ -151,8 +157,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg appSettings.$analyticsConsentState .dropFirst() // Called above before configuring the ServiceLocator - .sink { _ in - Self.setupSentry(appSettings: appSettings) + .sink { [bugReportService] _ in + Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings) } .store(in: &cancellables) @@ -375,11 +381,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg private static func setupServiceLocator(appSettings: AppSettings, appHooks: AppHooks) { ServiceLocator.shared.register(userIndicatorController: UserIndicatorController()) ServiceLocator.shared.register(appSettings: appSettings) - ServiceLocator.shared.register(bugReportService: BugReportService(rageshakeURLPublisher: appSettings.bugReportRageshakeURL.publisher, - applicationID: appSettings.bugReportApplicationID, - sdkGitSHA: sdkGitSha(), - maxUploadSize: appSettings.bugReportMaxUploadSize, - appHooks: appHooks)) + let posthogAnalyticsClient = PostHogAnalyticsClient() posthogAnalyticsClient.updateSuperProperties(AnalyticsEvent.SuperProperties(appPlatform: .EXI, cryptoSDK: .Rust, cryptoSDKVersion: sdkGitSha())) ServiceLocator.shared.register(analytics: AnalyticsService(client: posthogAnalyticsClient, @@ -556,7 +558,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg appHooks: appHooks) let coordinator = AuthenticationFlowCoordinator(authenticationService: authenticationService, - bugReportService: ServiceLocator.shared.bugReportService, + bugReportService: bugReportService, navigationRootCoordinator: navigationRootCoordinator, appMediator: appMediator, appSettings: appSettings, @@ -642,7 +644,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg } let flowParameters = CommonFlowParameters(userSession: userSession, - bugReportService: ServiceLocator.shared.bugReportService, + bugReportService: bugReportService, elementCallService: elementCallService, timelineControllerFactory: TimelineControllerFactory(), emojiProvider: EmojiProvider(appSettings: appSettings), @@ -901,7 +903,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg } } - private static func setupSentry(appSettings: AppSettings) { + private static func setupSentry(bugReportService: BugReportServiceProtocol, appSettings: AppSettings) { guard let bugReportSentryURL = appSettings.bugReportSentryURL else { return } let options: Options = .init() @@ -954,7 +956,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg // multiple callbacks if there are multiple crash events to send (see method documentation) options.onCrashedLastRun = { event in MXLog.error("Sentry detected a crash in the previous run: \(event.eventId.sentryIdString)") - ServiceLocator.shared.bugReportService.lastCrashEventID = event.eventId.sentryIdString + bugReportService.lastCrashEventID = event.eventId.sentryIdString } SentrySDK.start(options: options) // Swift diff --git a/ElementX/Sources/Application/ServiceLocator.swift b/ElementX/Sources/Application/ServiceLocator.swift index 4fba3da44..4b591877f 100644 --- a/ElementX/Sources/Application/ServiceLocator.swift +++ b/ElementX/Sources/Application/ServiceLocator.swift @@ -29,10 +29,4 @@ class ServiceLocator { func register(analytics: AnalyticsService) { self.analytics = analytics } - - private(set) var bugReportService: BugReportServiceProtocol! - - func register(bugReportService: BugReportServiceProtocol) { - self.bugReportService = bugReportService - } } diff --git a/ElementX/Sources/UITests/UITestsAppCoordinator.swift b/ElementX/Sources/UITests/UITestsAppCoordinator.swift index 05e1aaeaf..3458617c9 100644 --- a/ElementX/Sources/UITests/UITestsAppCoordinator.swift +++ b/ElementX/Sources/UITests/UITestsAppCoordinator.swift @@ -37,7 +37,6 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate AppSettings.configureWithSuiteName("io.element.elementx.uitests") AppSettings.resetAllSettings() ServiceLocator.shared.register(appSettings: AppSettings()) - ServiceLocator.shared.register(bugReportService: BugReportServiceMock(.init())) let analyticsClient = AnalyticsClientMock() analyticsClient.isRunning = false diff --git a/ElementX/Sources/UnitTests/UnitTestsAppCoordinator.swift b/ElementX/Sources/UnitTests/UnitTestsAppCoordinator.swift index b66727079..69e51eaa9 100644 --- a/ElementX/Sources/UnitTests/UnitTestsAppCoordinator.swift +++ b/ElementX/Sources/UnitTests/UnitTestsAppCoordinator.swift @@ -21,7 +21,6 @@ class UnitTestsAppCoordinator: AppCoordinatorProtocol { AppSettings.configureWithSuiteName("io.element.elementx.unittests") AppSettings.resetAllSettings() ServiceLocator.shared.register(appSettings: AppSettings()) - ServiceLocator.shared.register(bugReportService: BugReportServiceMock(.init())) let analyticsClient = AnalyticsClientMock() analyticsClient.isRunning = false