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:
Doug
2025-07-22 10:19:26 +01:00
committed by GitHub
parent 97f517129f
commit 82c659f3da
17 changed files with 241 additions and 179 deletions
@@ -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.")
}