Add a bug report hook. (#2988)

This commit is contained in:
Doug
2024-07-01 13:53:24 +01:00
committed by GitHub
parent 1178561853
commit 78b0c7068d
6 changed files with 33 additions and 9 deletions
@@ -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,
+15 -1
View File
@@ -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]
}