Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #4470: Sync UX hotfix. (#4471)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub committed Nov 4, 2021
1 parent 2d6cf17 commit aa2b865
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
4 changes: 4 additions & 0 deletions BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@ extension Strings {
public static let syncRemoveOtherDeviceTitle = NSLocalizedString("SyncRemoveOtherDeviceTitle", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Remove %@ from Sync Chain?", comment: "Title for removing other device from Sync")
public static let syncRemoveOtherDeviceMessage = NSLocalizedString("SyncRemoveOtherDeviceMessage", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Removing the device from the Sync Chain will not clear previously synced data from the device.", comment: "Message for removing other device from Sync")
public static let syncRemoveDeviceDefaultName = NSLocalizedString("SyncRemoveDeviceDefaultName", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Device", comment: "Default name for a device")
public static let syncJoinChainCodewordsWarning = NSLocalizedString("syncJoinChainCodewordsWarning", tableName: "BraveShared", bundle: Bundle.braveShared, value: "This will share your Brave data, including potentially your passwords, with the device that generated these code words. Please double check that these code words were generated by a device that you own. Are you sure you want to do this?", comment: "Default name for a device")
public static let syncJoinChainCameraWarning = NSLocalizedString("syncJoinChainCameraWarning", tableName: "BraveShared", bundle: Bundle.braveShared, value: "This will share your Brave data, including potentially your passwords, with the device that generated this QR code. Please double check that this QR code was generated by a device that you own. Are you sure you want to do this?", comment: "Default name for a device")
public static let syncJoinChainWarningTitle = NSLocalizedString("syncJoinChainWarningTitle", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Warning", comment: "Title for pairing sync device")

}

extension Strings {
Expand Down
62 changes: 39 additions & 23 deletions Client/Frontend/Sync/SyncPairCameraViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ class SyncPairCameraViewController: SyncViewController {
cameraView.layer.cornerRadius = 4
cameraView.layer.cornerCurve = .continuous
cameraView.layer.masksToBounds = true
cameraView.scanCallback = { data in

if !DeviceInfo.hasConnectivity() {
self.present(SyncAlerts.noConnection, animated: true)
return
}
cameraView.scanCallback = { [weak self] data in
guard let self = self else { return }

// TODO: Functional, but needs some cleanup
struct Scanner { static var lock = false }
Expand All @@ -60,27 +56,47 @@ class SyncPairCameraViewController: SyncViewController {
}

Scanner.lock = true
self.cameraView.cameraOverlaySucess()
// Freezing the camera frame after QR has been scanned.
self.cameraView.captureSession?.stopRunning()

// Vibrate.
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

// Forced timeout
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(25.0) * Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC), execute: {
Scanner.lock = false
self.cameraView.cameraOverlayError()
})
let alert = UIAlertController(title: Strings.syncJoinChainWarningTitle,
message: Strings.syncJoinChainCameraWarning,
preferredStyle: .alert)

// If multiple calls get in here due to race conditions it isn't a big deal
let okAction = UIAlertAction(title: Strings.yes, style: .default, handler: { _ in
if !DeviceInfo.hasConnectivity() {
self.present(SyncAlerts.noConnection, animated: true)
return
}
self.cameraView.cameraOverlaySucess()
// Freezing the camera frame after QR has been scanned.
self.cameraView.captureSession?.stopRunning()

// Vibrate.
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

// Forced timeout
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(25.0) * Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC), execute: {
Scanner.lock = false
self.cameraView.cameraOverlayError()
})

// If multiple calls get in here due to race conditions it isn't a big deal

let codeWords = BraveSyncAPI.shared.syncCode(fromHexSeed: data)
if codeWords.isEmpty {
self.cameraView.cameraOverlayError()
} else {
self.syncHandler?(codeWords)
}
})

let codeWords = BraveSyncAPI.shared.syncCode(fromHexSeed: data)
if codeWords.isEmpty {
self.cameraView.cameraOverlayError()
} else {
self.syncHandler?(codeWords)
let cancelAction = UIAlertAction(title: Strings.CancelString, style: .cancel) { _ in
Scanner.lock = false
}

alert.addAction(okAction)
alert.addAction(cancelAction)

self.present(alert, animated: true)
}

stackView.addArrangedSubview(cameraView)
Expand Down
19 changes: 16 additions & 3 deletions Client/Frontend/Sync/SyncPairWordsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,22 @@ class SyncPairWordsViewController: SyncViewController {
}

@objc func SEL_done() {
doIfConnected {
checkCodes()
}
let alert = UIAlertController(title: Strings.syncJoinChainWarningTitle,
message: Strings.syncJoinChainCodewordsWarning,
preferredStyle: .alert)

let okAction = UIAlertAction(title: Strings.yes, style: .default, handler: { [weak self] _ in
self?.doIfConnected {
self?.checkCodes()
}
})

let cancelAction = UIAlertAction(title: Strings.CancelString, style: .cancel)

alert.addAction(okAction)
alert.addAction(cancelAction)

present(alert, animated: true)
}

private func checkCodes() {
Expand Down

0 comments on commit aa2b865

Please sign in to comment.