diff --git a/Session/Home/New Conversation/NewMessageScreen.swift b/Session/Home/New Conversation/NewMessageScreen.swift index 924b8bc85..67e34376b 100644 --- a/Session/Home/New Conversation/NewMessageScreen.swift +++ b/Session/Home/New Conversation/NewMessageScreen.swift @@ -63,7 +63,7 @@ struct NewMessageScreen: View { } } - func continueWithAccountIdFromQRCode(onError: (() -> ())?) { + func continueWithAccountIdFromQRCode(onSuccess: (() -> ())?, onError: (() -> ())?) { startNewPrivateChatIfPossible(with: accountIdOrONS, onError: onError) } diff --git a/Session/Onboarding/LoadAccountScreen.swift b/Session/Onboarding/LoadAccountScreen.swift index abb6f4872..ab7fa9159 100644 --- a/Session/Onboarding/LoadAccountScreen.swift +++ b/Session/Onboarding/LoadAccountScreen.swift @@ -50,7 +50,7 @@ struct LoadAccountScreen: View { } } - private func continueWithSeed(seed: Data, from source: Onboarding.SeedSource, onError: (() -> ())?) { + private func continueWithSeed(seed: Data, from source: Onboarding.SeedSource, onSuccess: (() -> ())?, onError: (() -> ())?) { if (seed.count != 16) { errorString = source.genericErrorMessage DispatchQueue.main.asyncAfter(deadline: .now() + 1) { @@ -67,15 +67,19 @@ struct LoadAccountScreen: View { x25519KeyPair: x25519KeyPair ) + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + onSuccess?() + } + // Otherwise continue on to request push notifications permissions let viewController: SessionHostingViewController = SessionHostingViewController(rootView: PNModeScreen(flow: .link)) viewController.setUpNavBarSessionIcon() self.host.controller?.navigationController?.pushViewController(viewController, animated: true) } - func continueWithhexEncodedSeed(onError: (() -> ())?) { + func continueWithhexEncodedSeed(onSuccess: (() -> ())?, onError: (() -> ())?) { let seed = Data(hex: hexEncodedSeed) - continueWithSeed(seed: seed, from: .qrCode, onError: onError) + continueWithSeed(seed: seed, from: .qrCode, onSuccess: onSuccess, onError: onError) } func continueWithMnemonic() { @@ -99,7 +103,7 @@ struct LoadAccountScreen: View { return } let seed = Data(hex: hexEncodedSeed) - continueWithSeed(seed: seed, from: .mnemonic, onError: nil) + continueWithSeed(seed: seed, from: .mnemonic, onSuccess: nil, onError: nil) } } diff --git a/Session/Open Groups/JoinOpenGroupVC.swift b/Session/Open Groups/JoinOpenGroupVC.swift index 803f3935d..c47034d6f 100644 --- a/Session/Open Groups/JoinOpenGroupVC.swift +++ b/Session/Open Groups/JoinOpenGroupVC.swift @@ -144,7 +144,7 @@ final class JoinOpenGroupVC: BaseVC, UIPageViewControllerDataSource, UIPageViewC dismiss(animated: true, completion: nil) } - func controller(_ controller: QRCodeScanningViewController, didDetectQRCodeWith string: String, onError: (() -> ())?) { + func controller(_ controller: QRCodeScanningViewController, didDetectQRCodeWith string: String, onSuccess: (() -> ())?, onError: (() -> ())?) { joinOpenGroup(with: string, onError: onError) } diff --git a/Session/Settings/QRCodeScreen.swift b/Session/Settings/QRCodeScreen.swift index 9663ad66f..1234ac02d 100644 --- a/Session/Settings/QRCodeScreen.swift +++ b/Session/Settings/QRCodeScreen.swift @@ -56,7 +56,7 @@ struct QRCodeScreen: View { } } - func continueWithAccountId(onError: (() -> ())?) { + func continueWithAccountId(onSuccess: (() -> ())?, onError: (() -> ())?) { let hexEncodedPublicKey = accountId startNewPrivateChatIfPossible(with: hexEncodedPublicKey, onError: onError) } diff --git a/Session/Shared/QRCodeScanningViewController.swift b/Session/Shared/QRCodeScanningViewController.swift index 5ed5a0b09..5729c1fba 100644 --- a/Session/Shared/QRCodeScanningViewController.swift +++ b/Session/Shared/QRCodeScanningViewController.swift @@ -6,7 +6,7 @@ import SessionUIKit import SessionUtilitiesKit protocol QRScannerDelegate: AnyObject { - func controller(_ controller: QRCodeScanningViewController, didDetectQRCodeWith string: String, onError: (() -> ())?) + func controller(_ controller: QRCodeScanningViewController, didDetectQRCodeWith string: String, onSuccess: (() -> ())?, onError: (() -> ())?) } class QRCodeScanningViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate { @@ -16,6 +16,7 @@ class QRCodeScanningViewController: UIViewController, AVCaptureMetadataOutputObj private var capture: AVCaptureSession? private var captureLayer: AVCaptureVideoPreviewLayer? private var captureEnabled: Bool = false + private var shouldResumeCapture: Bool = false // MARK: - Initialization @@ -49,7 +50,7 @@ class QRCodeScanningViewController: UIViewController, AVCaptureMetadataOutputObj override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - if captureEnabled { + if captureEnabled || shouldResumeCapture { self.startCapture() } } @@ -199,9 +200,16 @@ class QRCodeScanningViewController: UIViewController, AVCaptureMetadataOutputObj // Vibrate AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) - self.scanDelegate?.controller(self, didDetectQRCodeWith: qrCode) { [weak self] in - self?.startCapture() - } + self.scanDelegate?.controller( + self, + didDetectQRCodeWith: qrCode, + onSuccess: { [weak self] in + self?.shouldResumeCapture = true + }, + onError: { [weak self] in + self?.startCapture() + } + ) } } @@ -212,7 +220,7 @@ struct QRCodeScanningVC_SwiftUI: UIViewControllerRepresentable { typealias UIViewControllerType = QRCodeScanningViewController let scanQRCodeVC = QRCodeScanningViewController() - var didDetectQRCode: (String, (() -> ())?) -> () + var didDetectQRCode: (String, (() -> ())?, (() -> ())?) -> () func makeUIViewController(context: Context) -> QRCodeScanningViewController { return scanQRCodeVC @@ -230,19 +238,19 @@ struct QRCodeScanningVC_SwiftUI: UIViewControllerRepresentable { } class Coordinator: NSObject, QRScannerDelegate { - var didDetectQRCode: (String, (() -> ())?) -> () + var didDetectQRCode: (String, (() -> ())?, (() -> ())?) -> () init( scanQRCodeVC: QRCodeScanningViewController, - didDetectQRCode: @escaping (String, (() -> ())?) -> () + didDetectQRCode: @escaping (String, (() -> ())?, (() -> ())?) -> () ) { self.didDetectQRCode = didDetectQRCode super.init() scanQRCodeVC.scanDelegate = self } - func controller(_ controller: QRCodeScanningViewController, didDetectQRCodeWith string: String, onError: (() -> ())?) { - didDetectQRCode(string, onError) + func controller(_ controller: QRCodeScanningViewController, didDetectQRCodeWith string: String, onSuccess: (() -> ())?, onError: (() -> ())?) { + didDetectQRCode(string, onSuccess, onError) } } } diff --git a/Session/Shared/ScanQRCodeScreen.swift b/Session/Shared/ScanQRCodeScreen.swift index 6434887d7..a2c6510e8 100644 --- a/Session/Shared/ScanQRCodeScreen.swift +++ b/Session/Shared/ScanQRCodeScreen.swift @@ -9,12 +9,12 @@ struct ScanQRCodeScreen: View { @Binding var error: String? @State var hasCameraAccess: Bool = (AVCaptureDevice.authorizationStatus(for: .video) == .authorized) - var continueAction: (((() -> ())?) -> Void)? + var continueAction: (((() -> ())?, (() -> ())?) -> Void)? init( _ result: Binding, error: Binding, - continueAction: (((() -> ())?) -> Void)? + continueAction: (((() -> ())?, (() -> ())?) -> Void)? ) { self._result = result self._error = error @@ -25,9 +25,9 @@ struct ScanQRCodeScreen: View { ZStack{ if hasCameraAccess { VStack { - QRCodeScanningVC_SwiftUI { result, onError in + QRCodeScanningVC_SwiftUI { result, onSuccess, onError in self.result = result - continueAction?(onError) + continueAction?(onSuccess, onError) } } .frame(