mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Support runtime customisation of the rageshake URL. (#4267)
This commit is contained in:
@@ -12,27 +12,30 @@ import Sentry
|
||||
import UIKit
|
||||
|
||||
class BugReportService: NSObject, BugReportServiceProtocol {
|
||||
private let baseURL: URL?
|
||||
/// 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 let applicationID: String
|
||||
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>()
|
||||
|
||||
var isEnabled: Bool { baseURL != nil }
|
||||
var isEnabled: Bool { rageshakeURL != nil }
|
||||
var lastCrashEventID: String?
|
||||
|
||||
init(baseURL: URL?,
|
||||
init(rageshakeURL: URL?,
|
||||
applicationID: String,
|
||||
sdkGitSHA: String,
|
||||
maxUploadSize: Int,
|
||||
session: URLSession = .shared,
|
||||
appHooks: AppHooks) {
|
||||
self.baseURL = baseURL
|
||||
defaultRageshakeURL = rageshakeURL
|
||||
self.rageshakeURL = rageshakeURL
|
||||
self.applicationID = applicationID
|
||||
self.sdkGitSHA = sdkGitSHA
|
||||
self.maxUploadSize = maxUploadSize
|
||||
@@ -46,11 +49,22 @@ class BugReportService: NSObject, BugReportServiceProtocol {
|
||||
var crashedLastRun: Bool {
|
||||
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 baseURL else {
|
||||
guard let rageshakeURL else {
|
||||
fatalError("No bug report URL set, the screen should not be shown in this case.")
|
||||
}
|
||||
|
||||
@@ -107,7 +121,7 @@ class BugReportService: NSObject, BugReportServiceProtocol {
|
||||
}
|
||||
body.appendString(string: "--\(boundary)--\r\n")
|
||||
|
||||
var request = URLRequest(url: baseURL)
|
||||
var request = URLRequest(url: rageshakeURL)
|
||||
request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
request.httpMethod = "POST"
|
||||
|
||||
Reference in New Issue
Block a user