mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Refactor Rageshake URL and Target configuration. (#4337)
* Move the rageshakeURL configuration from the BugReportService to AppSettings. * Refactor Target to return a handle when configuring. This helps with reconfiguration and removes the @MainActor constraint.
This commit is contained in:
@@ -12,10 +12,7 @@ import Sentry
|
||||
import UIKit
|
||||
|
||||
class BugReportService: NSObject, BugReportServiceProtocol {
|
||||
/// The rageshake URL as provided in the init.
|
||||
private let defaultRageshakeURL: URL?
|
||||
/// The rageshake URL currently being used by the service.
|
||||
private var rageshakeURL: URL?
|
||||
private var rageshakeURL: RageshakeConfiguration
|
||||
private let applicationID: String
|
||||
private let sdkGitSHA: String
|
||||
private let maxUploadSize: Int
|
||||
@@ -25,23 +22,27 @@ class BugReportService: NSObject, BugReportServiceProtocol {
|
||||
private let progressSubject = PassthroughSubject<Double, Never>()
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
var isEnabled: Bool { rageshakeURL != nil }
|
||||
var isEnabled: Bool { rageshakeURL != .disabled }
|
||||
var lastCrashEventID: String?
|
||||
|
||||
init(rageshakeURL: URL?,
|
||||
init(rageshakeURLPublisher: CurrentValuePublisher<RageshakeConfiguration, Never>,
|
||||
applicationID: String,
|
||||
sdkGitSHA: String,
|
||||
maxUploadSize: Int,
|
||||
session: URLSession = .shared,
|
||||
appHooks: AppHooks) {
|
||||
defaultRageshakeURL = rageshakeURL
|
||||
self.rageshakeURL = rageshakeURL
|
||||
rageshakeURL = rageshakeURLPublisher.value
|
||||
self.applicationID = applicationID
|
||||
self.sdkGitSHA = sdkGitSHA
|
||||
self.maxUploadSize = maxUploadSize
|
||||
self.session = session
|
||||
self.appHooks = appHooks
|
||||
|
||||
super.init()
|
||||
|
||||
rageshakeURLPublisher
|
||||
.weakAssign(to: \.rageshakeURL, on: self)
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
// MARK: - BugReportServiceProtocol
|
||||
@@ -50,21 +51,10 @@ class BugReportService: NSObject, BugReportServiceProtocol {
|
||||
SentrySDK.crashedLastRun
|
||||
}
|
||||
|
||||
func applyConfiguration(_ configuration: RageshakeConfiguration) {
|
||||
switch configuration {
|
||||
case .url(let url):
|
||||
rageshakeURL = url
|
||||
case .disabled:
|
||||
rageshakeURL = nil
|
||||
case .default:
|
||||
rageshakeURL = defaultRageshakeURL
|
||||
}
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
func submitBugReport(_ bugReport: BugReport,
|
||||
progressListener: CurrentValueSubject<Double, Never>) async -> Result<SubmitBugReportResponse, BugReportServiceError> {
|
||||
guard let rageshakeURL else {
|
||||
guard case let .url(rageshakeURL) = rageshakeURL else {
|
||||
fatalError("No bug report URL set, the screen should not be shown in this case.")
|
||||
}
|
||||
|
||||
|
||||
@@ -46,13 +46,11 @@ enum BugReportServiceError: LocalizedError {
|
||||
}
|
||||
}
|
||||
|
||||
enum RageshakeConfiguration {
|
||||
enum RageshakeConfiguration: Equatable {
|
||||
/// Rageshakes should be sent to the provided URL
|
||||
case url(URL)
|
||||
/// Rageshakes are disabled.
|
||||
case disabled
|
||||
/// No customisations are made, use the default configuration.
|
||||
case `default`
|
||||
}
|
||||
|
||||
// sourcery: AutoMockable
|
||||
@@ -62,8 +60,6 @@ protocol BugReportServiceProtocol: AnyObject {
|
||||
|
||||
var lastCrashEventID: String? { get set }
|
||||
|
||||
func applyConfiguration(_ configuration: RageshakeConfiguration)
|
||||
|
||||
func submitBugReport(_ bugReport: BugReport,
|
||||
progressListener: CurrentValueSubject<Double, Never>) async -> Result<SubmitBugReportResponse, BugReportServiceError>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user