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:
@@ -372,7 +372,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
private static func setupServiceLocator(appSettings: AppSettings, appHooks: AppHooks) {
|
||||
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController())
|
||||
ServiceLocator.shared.register(appSettings: appSettings)
|
||||
ServiceLocator.shared.register(bugReportService: BugReportService(baseURL: appSettings.bugReportServiceBaseURL,
|
||||
ServiceLocator.shared.register(bugReportService: BugReportService(rageshakeURL: appSettings.bugReportRageshakeURL,
|
||||
applicationID: appSettings.bugReportApplicationID,
|
||||
sdkGitSHA: sdkGitSha(),
|
||||
maxUploadSize: appSettings.bugReportMaxUploadSize,
|
||||
|
||||
@@ -249,7 +249,7 @@ final class AppSettings {
|
||||
|
||||
// MARK: - Bug report
|
||||
|
||||
let bugReportServiceBaseURL: URL? = Secrets.rageshakeServerURL.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping
|
||||
let bugReportRageshakeURL: URL? = Secrets.rageshakeURL.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping
|
||||
let bugReportSentryURL: URL? = Secrets.sentryDSN.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping
|
||||
let bugReportSentryRustURL: URL? = Secrets.sentryRustDSN.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping
|
||||
/// The name allocated by the bug report server
|
||||
|
||||
@@ -2142,6 +2142,47 @@ class BugReportServiceMock: BugReportServiceProtocol, @unchecked Sendable {
|
||||
var underlyingCrashedLastRun: Bool!
|
||||
var lastCrashEventID: String?
|
||||
|
||||
//MARK: - applyConfiguration
|
||||
|
||||
var applyConfigurationUnderlyingCallsCount = 0
|
||||
var applyConfigurationCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return applyConfigurationUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = applyConfigurationUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
applyConfigurationUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
applyConfigurationUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var applyConfigurationCalled: Bool {
|
||||
return applyConfigurationCallsCount > 0
|
||||
}
|
||||
var applyConfigurationReceivedConfiguration: RageshakeConfiguration?
|
||||
var applyConfigurationReceivedInvocations: [RageshakeConfiguration] = []
|
||||
var applyConfigurationClosure: ((RageshakeConfiguration) -> Void)?
|
||||
|
||||
func applyConfiguration(_ configuration: RageshakeConfiguration) {
|
||||
applyConfigurationCallsCount += 1
|
||||
applyConfigurationReceivedConfiguration = configuration
|
||||
DispatchQueue.main.async {
|
||||
self.applyConfigurationReceivedInvocations.append(configuration)
|
||||
}
|
||||
applyConfigurationClosure?(configuration)
|
||||
}
|
||||
//MARK: - submitBugReport
|
||||
|
||||
var submitBugReportProgressListenerUnderlyingCallsCount = 0
|
||||
|
||||
@@ -191,7 +191,7 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
|
||||
switch await widgetDriver.start(baseURL: baseURL,
|
||||
clientID: clientID,
|
||||
colorScheme: colorScheme,
|
||||
rageshakeURL: appSettings.bugReportServiceBaseURL?.absoluteString,
|
||||
rageshakeURL: appSettings.bugReportRageshakeURL?.absoluteString,
|
||||
analyticsConfiguration: analyticsConfiguration) {
|
||||
case .success(let url):
|
||||
state.url = url
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -46,6 +46,15 @@ enum BugReportServiceError: LocalizedError {
|
||||
}
|
||||
}
|
||||
|
||||
enum RageshakeConfiguration {
|
||||
/// 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
|
||||
protocol BugReportServiceProtocol: AnyObject {
|
||||
var isEnabled: Bool { get }
|
||||
@@ -53,6 +62,8 @@ 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