workaround for restarting capture after going back from message notification screen

pull/891/head
Ryan ZHAO 10 months ago
parent 057e71f942
commit ab2f93a993

@ -63,7 +63,7 @@ struct NewMessageScreen: View {
} }
} }
func continueWithAccountIdFromQRCode(onError: (() -> ())?) { func continueWithAccountIdFromQRCode(onSuccess: (() -> ())?, onError: (() -> ())?) {
startNewPrivateChatIfPossible(with: accountIdOrONS, onError: onError) startNewPrivateChatIfPossible(with: accountIdOrONS, onError: onError)
} }

@ -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) { if (seed.count != 16) {
errorString = source.genericErrorMessage errorString = source.genericErrorMessage
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
@ -67,15 +67,19 @@ struct LoadAccountScreen: View {
x25519KeyPair: x25519KeyPair x25519KeyPair: x25519KeyPair
) )
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
onSuccess?()
}
// Otherwise continue on to request push notifications permissions // Otherwise continue on to request push notifications permissions
let viewController: SessionHostingViewController = SessionHostingViewController(rootView: PNModeScreen(flow: .link)) let viewController: SessionHostingViewController = SessionHostingViewController(rootView: PNModeScreen(flow: .link))
viewController.setUpNavBarSessionIcon() viewController.setUpNavBarSessionIcon()
self.host.controller?.navigationController?.pushViewController(viewController, animated: true) self.host.controller?.navigationController?.pushViewController(viewController, animated: true)
} }
func continueWithhexEncodedSeed(onError: (() -> ())?) { func continueWithhexEncodedSeed(onSuccess: (() -> ())?, onError: (() -> ())?) {
let seed = Data(hex: hexEncodedSeed) let seed = Data(hex: hexEncodedSeed)
continueWithSeed(seed: seed, from: .qrCode, onError: onError) continueWithSeed(seed: seed, from: .qrCode, onSuccess: onSuccess, onError: onError)
} }
func continueWithMnemonic() { func continueWithMnemonic() {
@ -99,7 +103,7 @@ struct LoadAccountScreen: View {
return return
} }
let seed = Data(hex: hexEncodedSeed) let seed = Data(hex: hexEncodedSeed)
continueWithSeed(seed: seed, from: .mnemonic, onError: nil) continueWithSeed(seed: seed, from: .mnemonic, onSuccess: nil, onError: nil)
} }
} }

@ -144,7 +144,7 @@ final class JoinOpenGroupVC: BaseVC, UIPageViewControllerDataSource, UIPageViewC
dismiss(animated: true, completion: nil) 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) joinOpenGroup(with: string, onError: onError)
} }

@ -56,7 +56,7 @@ struct QRCodeScreen: View {
} }
} }
func continueWithAccountId(onError: (() -> ())?) { func continueWithAccountId(onSuccess: (() -> ())?, onError: (() -> ())?) {
let hexEncodedPublicKey = accountId let hexEncodedPublicKey = accountId
startNewPrivateChatIfPossible(with: hexEncodedPublicKey, onError: onError) startNewPrivateChatIfPossible(with: hexEncodedPublicKey, onError: onError)
} }

@ -6,7 +6,7 @@ import SessionUIKit
import SessionUtilitiesKit import SessionUtilitiesKit
protocol QRScannerDelegate: AnyObject { protocol QRScannerDelegate: AnyObject {
func controller(_ controller: QRCodeScanningViewController, didDetectQRCodeWith string: String, onError: (() -> ())?) func controller(_ controller: QRCodeScanningViewController, didDetectQRCodeWith string: String, onSuccess: (() -> ())?, onError: (() -> ())?)
} }
class QRCodeScanningViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate { class QRCodeScanningViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
@ -16,6 +16,7 @@ class QRCodeScanningViewController: UIViewController, AVCaptureMetadataOutputObj
private var capture: AVCaptureSession? private var capture: AVCaptureSession?
private var captureLayer: AVCaptureVideoPreviewLayer? private var captureLayer: AVCaptureVideoPreviewLayer?
private var captureEnabled: Bool = false private var captureEnabled: Bool = false
private var shouldResumeCapture: Bool = false
// MARK: - Initialization // MARK: - Initialization
@ -49,7 +50,7 @@ class QRCodeScanningViewController: UIViewController, AVCaptureMetadataOutputObj
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
if captureEnabled { if captureEnabled || shouldResumeCapture {
self.startCapture() self.startCapture()
} }
} }
@ -199,9 +200,16 @@ class QRCodeScanningViewController: UIViewController, AVCaptureMetadataOutputObj
// Vibrate // Vibrate
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
self.scanDelegate?.controller(self, didDetectQRCodeWith: qrCode) { [weak self] in self.scanDelegate?.controller(
self?.startCapture() 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 typealias UIViewControllerType = QRCodeScanningViewController
let scanQRCodeVC = QRCodeScanningViewController() let scanQRCodeVC = QRCodeScanningViewController()
var didDetectQRCode: (String, (() -> ())?) -> () var didDetectQRCode: (String, (() -> ())?, (() -> ())?) -> ()
func makeUIViewController(context: Context) -> QRCodeScanningViewController { func makeUIViewController(context: Context) -> QRCodeScanningViewController {
return scanQRCodeVC return scanQRCodeVC
@ -230,19 +238,19 @@ struct QRCodeScanningVC_SwiftUI: UIViewControllerRepresentable {
} }
class Coordinator: NSObject, QRScannerDelegate { class Coordinator: NSObject, QRScannerDelegate {
var didDetectQRCode: (String, (() -> ())?) -> () var didDetectQRCode: (String, (() -> ())?, (() -> ())?) -> ()
init( init(
scanQRCodeVC: QRCodeScanningViewController, scanQRCodeVC: QRCodeScanningViewController,
didDetectQRCode: @escaping (String, (() -> ())?) -> () didDetectQRCode: @escaping (String, (() -> ())?, (() -> ())?) -> ()
) { ) {
self.didDetectQRCode = didDetectQRCode self.didDetectQRCode = didDetectQRCode
super.init() super.init()
scanQRCodeVC.scanDelegate = self scanQRCodeVC.scanDelegate = self
} }
func controller(_ controller: QRCodeScanningViewController, didDetectQRCodeWith string: String, onError: (() -> ())?) { func controller(_ controller: QRCodeScanningViewController, didDetectQRCodeWith string: String, onSuccess: (() -> ())?, onError: (() -> ())?) {
didDetectQRCode(string, onError) didDetectQRCode(string, onSuccess, onError)
} }
} }
} }

@ -9,12 +9,12 @@ struct ScanQRCodeScreen: View {
@Binding var error: String? @Binding var error: String?
@State var hasCameraAccess: Bool = (AVCaptureDevice.authorizationStatus(for: .video) == .authorized) @State var hasCameraAccess: Bool = (AVCaptureDevice.authorizationStatus(for: .video) == .authorized)
var continueAction: (((() -> ())?) -> Void)? var continueAction: (((() -> ())?, (() -> ())?) -> Void)?
init( init(
_ result: Binding<String>, _ result: Binding<String>,
error: Binding<String?>, error: Binding<String?>,
continueAction: (((() -> ())?) -> Void)? continueAction: (((() -> ())?, (() -> ())?) -> Void)?
) { ) {
self._result = result self._result = result
self._error = error self._error = error
@ -25,9 +25,9 @@ struct ScanQRCodeScreen: View {
ZStack{ ZStack{
if hasCameraAccess { if hasCameraAccess {
VStack { VStack {
QRCodeScanningVC_SwiftUI { result, onError in QRCodeScanningVC_SwiftUI { result, onSuccess, onError in
self.result = result self.result = result
continueAction?(onError) continueAction?(onSuccess, onError)
} }
} }
.frame( .frame(

Loading…
Cancel
Save