summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/View controllers/ProblemReport
diff options
context:
space:
mode:
authormojganii <mojgan.jelodar@codic.se>2024-12-02 15:49:28 +0100
committerBug Magnet <marco.nikic@mullvad.net>2024-12-03 11:35:30 +0100
commit82062e2e21f880dfdd58db07997029b6de967c2b (patch)
tree20d05969709305d05a67c46fb573b859c9121f41 /ios/MullvadVPN/View controllers/ProblemReport
parent8e490385b0b86f5c0998980774566294c4f414e3 (diff)
downloadmullvadvpn-82062e2e21f880dfdd58db07997029b6de967c2b.tar.xz
mullvadvpn-82062e2e21f880dfdd58db07997029b6de967c2b.zip
Fix log redaction loading issue
Diffstat (limited to 'ios/MullvadVPN/View controllers/ProblemReport')
-rw-r--r--ios/MullvadVPN/View controllers/ProblemReport/ProblemReportInteractor.swift84
-rw-r--r--ios/MullvadVPN/View controllers/ProblemReport/ProblemReportReviewViewController.swift61
-rw-r--r--ios/MullvadVPN/View controllers/ProblemReport/ProblemReportViewController.swift4
3 files changed, 94 insertions, 55 deletions
diff --git a/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportInteractor.swift b/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportInteractor.swift
index bbc740f453..616ea7d081 100644
--- a/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportInteractor.swift
+++ b/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportInteractor.swift
@@ -14,51 +14,79 @@ import Operations
final class ProblemReportInteractor {
private let apiProxy: APIQuerying
private let tunnelManager: TunnelManager
+ private let consolidatedLog: ConsolidatedApplicationLog
+ private var reportedString = ""
- private lazy var consolidatedLog: ConsolidatedApplicationLog = {
- let securityGroupIdentifier = ApplicationConfiguration.securityGroupIdentifier
- let redactStrings = [tunnelManager.deviceState.accountData?.number].compactMap { $0 }
-
- let report = ConsolidatedApplicationLog(
- redactCustomStrings: redactStrings,
- redactContainerPathsForSecurityGroupIdentifiers: [securityGroupIdentifier]
+ init(apiProxy: APIQuerying, tunnelManager: TunnelManager) {
+ self.apiProxy = apiProxy
+ self.tunnelManager = tunnelManager
+ let redactCustomStrings = [tunnelManager.deviceState.accountData?.number].compactMap { $0 }
+ self.consolidatedLog = ConsolidatedApplicationLog(
+ redactCustomStrings: redactCustomStrings.isEmpty ? nil : redactCustomStrings,
+ redactContainerPathsForSecurityGroupIdentifiers: [ApplicationConfiguration.securityGroupIdentifier],
+ bufferSize: ApplicationConfiguration.logMaximumFileSize
)
+ }
- let logFileURLs = ApplicationTarget.allCases.flatMap {
+ func fetchReportString(completion: @escaping (String) -> Void) {
+ consolidatedLog.addLogFiles(fileURLs: ApplicationTarget.allCases.flatMap {
ApplicationConfiguration.logFileURLs(for: $0, in: ApplicationConfiguration.containerURL)
+ }) { [weak self] in
+ guard let self else { return }
+ completion(consolidatedLog.string)
}
- report.addLogFiles(fileURLs: logFileURLs)
-
- return report
- }()
-
- var reportString: String {
- consolidatedLog.string
}
- init(apiProxy: APIQuerying, tunnelManager: TunnelManager) {
- self.apiProxy = apiProxy
- self.tunnelManager = tunnelManager
+ func sendReport(
+ email: String,
+ message: String,
+ completion: @escaping (Result<Void, Error>) -> Void
+ ) {
+ let logString = self.consolidatedLog.string
+
+ if logString.isEmpty {
+ fetchReportString { [weak self] updatedLogString in
+ self?.sendProblemReport(
+ email: email,
+ message: message,
+ logString: updatedLogString,
+ completion: completion
+ )
+ }
+ } else {
+ sendProblemReport(
+ email: email,
+ message: message,
+ logString: logString,
+ completion: completion
+ )
+ }
}
- func sendReport(
+ private func sendProblemReport(
email: String,
message: String,
+ logString: String,
completion: @escaping (Result<Void, Error>) -> Void
- ) -> Cancellable {
+ ) {
+ let metadataDict = self.consolidatedLog.metadata.reduce(into: [:]) { output, entry in
+ output[entry.key.rawValue] = entry.value
+ }
+
let request = REST.ProblemReportRequest(
address: email,
message: message,
- log: consolidatedLog.string,
- metadata: consolidatedLog.metadata.reduce(into: [:]) { output, entry in
- output[entry.key.rawValue] = entry.value
- }
+ log: logString,
+ metadata: metadataDict
)
- return apiProxy.sendProblemReport(
+ _ = self.apiProxy.sendProblemReport(
request,
- retryStrategy: .default,
- completionHandler: completion
- )
+ retryStrategy: .default
+ ) { result in
+ DispatchQueue.main.async {
+ completion(result)
+ }
+ }
}
}
diff --git a/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportReviewViewController.swift b/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportReviewViewController.swift
index a12d32362a..d7b6f54c38 100644
--- a/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportReviewViewController.swift
+++ b/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportReviewViewController.swift
@@ -9,8 +9,14 @@
import UIKit
class ProblemReportReviewViewController: UIViewController {
+ private let spinnerView = SpinnerActivityIndicatorView(style: .large)
private var textView = UITextView()
private let interactor: ProblemReportInteractor
+ private lazy var spinnerContainerView: UIView = {
+ let view = UIView()
+ view.backgroundColor = .black.withAlphaComponent(0.5)
+ return view
+ }()
init(interactor: ProblemReportInteractor) {
self.interactor = interactor
@@ -23,7 +29,7 @@ class ProblemReportReviewViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
-
+ view.backgroundColor = .secondaryColor
view.accessibilityIdentifier = .appLogsView
navigationItem.title = NSLocalizedString(
@@ -60,14 +66,21 @@ class ProblemReportReviewViewController: UIViewController {
)
textView.backgroundColor = .systemBackground
- view.addSubview(textView)
+ view.addConstrainedSubviews([textView]) {
+ textView.pinEdgesToSuperview(.all().excluding(.top))
+ textView.pinEdgeToSuperviewMargin(.top(0))
+ }
- NSLayoutConstraint.activate([
- textView.topAnchor.constraint(equalTo: view.topAnchor),
- textView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
- textView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
- textView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
- ])
+ textView.addConstrainedSubviews([spinnerContainerView]) {
+ spinnerContainerView.pinEdgesToSuperview()
+ spinnerContainerView.widthAnchor.constraint(equalTo: textView.widthAnchor)
+ spinnerContainerView.heightAnchor.constraint(equalTo: textView.heightAnchor)
+ }
+
+ spinnerContainerView.addConstrainedSubviews([spinnerView]) {
+ spinnerView.centerXAnchor.constraint(equalTo: view.centerXAnchor)
+ spinnerView.centerYAnchor.constraint(equalTo: view.centerYAnchor)
+ }
// Used to layout constraints so that navigation controller could properly adjust the text
// view insets.
@@ -81,30 +94,28 @@ class ProblemReportReviewViewController: UIViewController {
}
private func loadLogs() {
- let presentation = AlertPresentation(
- id: "problem-report-load",
- icon: .spinner,
- buttons: []
- )
-
- let alertController = AlertViewController(presentation: presentation)
-
- present(alertController, animated: true) {
- self.textView.text = self.interactor.reportString
- self.dismiss(animated: true)
+ spinnerView.startAnimating()
+ interactor.fetchReportString { [weak self] reportString in
+ guard let self else { return }
+ textView.text = reportString
+ spinnerView.stopAnimating()
+ spinnerContainerView.isHidden = true
}
}
#if DEBUG
private func share() {
- let activityController = UIActivityViewController(
- activityItems: [interactor.reportString],
- applicationActivities: nil
- )
+ interactor.fetchReportString { [weak self] reportString in
+ guard let self,!reportString.isEmpty else { return }
+ let activityController = UIActivityViewController(
+ activityItems: [reportString],
+ applicationActivities: nil
+ )
- activityController.popoverPresentationController?.barButtonItem = navigationItem.leftBarButtonItem
+ activityController.popoverPresentationController?.barButtonItem = navigationItem.leftBarButtonItem
- present(activityController, animated: true)
+ present(activityController, animated: true)
+ }
}
#endif
}
diff --git a/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportViewController.swift b/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportViewController.swift
index 15d21ee9db..47ba3225e9 100644
--- a/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportViewController.swift
+++ b/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportViewController.swift
@@ -131,7 +131,7 @@ final class ProblemReportViewController: UIViewController, UITextFieldDelegate {
@objc func handleViewLogsButtonTap() {
let reviewController = ProblemReportReviewViewController(interactor: interactor)
- let navigationController = UINavigationController(rootViewController: reviewController)
+ let navigationController = CustomNavigationController(rootViewController: reviewController)
present(navigationController, animated: true)
}
@@ -258,7 +258,7 @@ final class ProblemReportViewController: UIViewController, UITextFieldDelegate {
willSendProblemReport()
- _ = interactor.sendReport(
+ interactor.sendReport(
email: viewModel.email,
message: viewModel.message
) { completion in