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)
}

@ -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)
}
}

@ -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)
}

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

@ -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)
}
}
}

@ -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<String>,
error: Binding<String?>,
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(

Loading…
Cancel
Save