mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Add a bug report hook. (#2988)
This commit is contained in:
parent
1178561853
commit
78b0c7068d
@ -95,7 +95,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
|
||||
navigationRootCoordinator = NavigationRootCoordinator()
|
||||
|
||||
Self.setupServiceLocator(appSettings: appSettings)
|
||||
Self.setupServiceLocator(appSettings: appSettings, appHooks: appHooks)
|
||||
|
||||
ServiceLocator.shared.analytics.startIfEnabled()
|
||||
|
||||
@ -340,14 +340,15 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private static func setupServiceLocator(appSettings: AppSettings) {
|
||||
private static func setupServiceLocator(appSettings: AppSettings, appHooks: AppHooks) {
|
||||
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController())
|
||||
ServiceLocator.shared.register(appSettings: appSettings)
|
||||
ServiceLocator.shared.register(networkMonitor: NetworkMonitor())
|
||||
ServiceLocator.shared.register(bugReportService: BugReportService(withBaseURL: appSettings.bugReportServiceBaseURL,
|
||||
applicationId: appSettings.bugReportApplicationId,
|
||||
sdkGitSHA: sdkGitSha(),
|
||||
maxUploadSize: appSettings.bugReportMaxUploadSize))
|
||||
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,
|
||||
|
@ -19,7 +19,7 @@ import Foundation
|
||||
// MARK: Registration
|
||||
|
||||
class AppHooks: AppHooksProtocol {
|
||||
private(set) var appSettingsHook: AppSettingsHookProtocol?
|
||||
private var appSettingsHook: AppSettingsHookProtocol?
|
||||
func registerAppSettingsHook(_ hook: AppSettingsHookProtocol) {
|
||||
appSettingsHook = hook
|
||||
}
|
||||
@ -28,6 +28,16 @@ class AppHooks: AppHooksProtocol {
|
||||
guard let appSettingsHook else { return appSettings }
|
||||
return appSettingsHook.run(appSettings: appSettings)
|
||||
}
|
||||
|
||||
private var bugReportHook: BugReportHookProtocol?
|
||||
func registerBugReportHook(_ hook: BugReportHookProtocol) {
|
||||
bugReportHook = hook
|
||||
}
|
||||
|
||||
func runBugReportHook(_ bugReport: BugReport) -> BugReport {
|
||||
guard let bugReportHook else { return bugReport }
|
||||
return bugReportHook.run(bugReport: bugReport)
|
||||
}
|
||||
}
|
||||
|
||||
protocol AppHooksProtocol {
|
||||
@ -43,3 +53,7 @@ extension AppHooksProtocol {
|
||||
protocol AppSettingsHookProtocol {
|
||||
func run(appSettings: AppSettings) -> AppSettings
|
||||
}
|
||||
|
||||
protocol BugReportHookProtocol {
|
||||
func run(bugReport: BugReport) -> BugReport
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ class BugReportService: NSObject, BugReportServiceProtocol {
|
||||
private let sdkGitSHA: String
|
||||
private let maxUploadSize: Int
|
||||
private let session: URLSession
|
||||
|
||||
private let appHooks: AppHooks
|
||||
|
||||
private let progressSubject = PassthroughSubject<Double, Never>()
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
@ -35,12 +38,14 @@ class BugReportService: NSObject, BugReportServiceProtocol {
|
||||
applicationId: String,
|
||||
sdkGitSHA: String,
|
||||
maxUploadSize: Int,
|
||||
session: URLSession = .shared) {
|
||||
session: URLSession = .shared,
|
||||
appHooks: AppHooks) {
|
||||
self.baseURL = baseURL
|
||||
self.applicationId = applicationId
|
||||
self.sdkGitSHA = sdkGitSHA
|
||||
self.maxUploadSize = maxUploadSize
|
||||
self.session = session
|
||||
self.appHooks = appHooks
|
||||
super.init()
|
||||
}
|
||||
|
||||
@ -53,6 +58,8 @@ class BugReportService: NSObject, BugReportServiceProtocol {
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
func submitBugReport(_ bugReport: BugReport,
|
||||
progressListener: CurrentValueSubject<Double, Never>) async -> Result<SubmitBugReportResponse, BugReportServiceError> {
|
||||
let bugReport = appHooks.runBugReportHook(bugReport)
|
||||
|
||||
var params = [
|
||||
MultipartFormData(key: "text", type: .text(value: bugReport.text)),
|
||||
MultipartFormData(key: "can_contact", type: .text(value: "\(bugReport.canContact)"))
|
||||
|
@ -26,7 +26,7 @@ struct BugReport: Equatable {
|
||||
let text: String
|
||||
let includeLogs: Bool
|
||||
let canContact: Bool
|
||||
let githubLabels: [String]
|
||||
var githubLabels: [String]
|
||||
let files: [URL]
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit e03750f654cd3800c14b41827fb3f6ab57f7d5f0
|
||||
Subproject commit 9fae88678e844e9284c3b10591ac700970862d9c
|
@ -54,7 +54,8 @@ class BugReportServiceTests: XCTestCase {
|
||||
applicationId: "mock_app_id",
|
||||
sdkGitSHA: "1234",
|
||||
maxUploadSize: ServiceLocator.shared.settings.bugReportMaxUploadSize,
|
||||
session: .mock)
|
||||
session: .mock,
|
||||
appHooks: AppHooks())
|
||||
XCTAssertFalse(service.crashedLastRun)
|
||||
}
|
||||
|
||||
@ -63,7 +64,8 @@ class BugReportServiceTests: XCTestCase {
|
||||
applicationId: "mock_app_id",
|
||||
sdkGitSHA: "1234",
|
||||
maxUploadSize: ServiceLocator.shared.settings.bugReportMaxUploadSize,
|
||||
session: .mock)
|
||||
session: .mock,
|
||||
appHooks: AppHooks())
|
||||
|
||||
let bugReport = BugReport(userID: "@mock:client.com",
|
||||
deviceID: nil,
|
||||
|
Loading…
x
Reference in New Issue
Block a user