Skip to content

Commit

Permalink
fix connect two unsynced devices path
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaTardio committed Nov 27, 2023
1 parent c041451 commit a2785c1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 44 deletions.
3 changes: 1 addition & 2 deletions DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate {
@MainActor
func handleError(_ error: Error) {
// Work out how to handle this properly later
// assertionFailure(error.localizedDescription)
assertionFailure(error.localizedDescription)
}

func showSyncWithAnotherDevice() {
Expand All @@ -88,7 +88,6 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate {
rootView: DeviceConnectedView())
navigationController?.present(controller, animated: true) { [weak self] in
self?.rootView.model.syncEnabled(recoveryCode: self!.recoveryCode)
// self?.refreshDevices()
}
}

Expand Down
26 changes: 20 additions & 6 deletions DuckDuckGo/SyncSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,16 @@ class SyncSettingsViewController: UIHostingController<SyncSettingsView> {
}

func dismissPresentedViewController() {
navigationController?.topViewController?.dismiss(animated: true)
if let presentedViewController = navigationController?.presentedViewController {
if !(presentedViewController is UIHostingController<SyncSettingsView>) {
presentedViewController.dismiss(animated: true, completion: nil)
}
}
// guard let vc = navigationController?.topViewController else { return }
// guard let view = vc.view else { return }
// if !(view is SyncSettingsView) {
// vc.dismiss(animated: true)
// }
}

func refreshDevices(clearDevices: Bool = true) {
Expand Down Expand Up @@ -188,7 +197,7 @@ extension SyncSettingsViewController: ScanOrPasteCodeViewModelDelegate {
// let knownDevices = Set(self.rootView.model.devices.map { $0.id })
let registeredDevices = try await syncService.login(recoveryKey, deviceName: deviceName, deviceType: deviceType)
mapDevices(registeredDevices)
navigationController?.topViewController?.dismiss(animated: true, completion: showRecoveryPDF)
dismissVCAndShowRecoveryPDF()
// let devices = self.rootView.model.devices.filter { !knownDevices.contains($0.id) && !$0.isThisDevice }
// let isSecondDevice = devices.count == 1
// showDeviceConnected(devices, optionsModel: self.rootView.model, isSingleSetUp: false, shouldShowOptions: isActiveSyncDevice && isSecondDevice)
Expand Down Expand Up @@ -216,27 +225,28 @@ extension SyncSettingsViewController: ScanOrPasteCodeViewModelDelegate {
guard let syncCode = try? SyncCode.decodeBase64String(code) else {
return false
}

if let recoveryKey = syncCode.recovery {
dismissPresentedViewController()
showPreparingSync()
try await loginAndShowDeviceConnected(recoveryKey: recoveryKey, isActiveSyncDevice: true)
return true
} else if let connectKey = syncCode.connect {
dismissPresentedViewController()
showPreparingSync()
if syncService.account == nil {
try await syncService.createAccount(deviceName: deviceName, deviceType: deviceType)
rootView.model.syncEnabled(recoveryCode: recoveryCode)
}
try await syncService.transmitRecoveryKey(connectKey)
self.dismissPresentedViewController()
self.rootView.model.isSyncingDevices = true

self.rootView.model.$devices
.removeDuplicates()
.dropFirst()
.prefix(1)
.sink { [weak self] devices in
.sink { [weak self] _ in
guard let self else { return }
self.showDeviceConnected()
self.dismissVCAndShowRecoveryPDF()
self.rootView.model.isSyncingDevices = false
}.store(in: &cancellables)

Expand All @@ -249,6 +259,10 @@ extension SyncSettingsViewController: ScanOrPasteCodeViewModelDelegate {
return false
}

func dismissVCAndShowRecoveryPDF() {
self.navigationController?.topViewController?.dismiss(animated: true, completion: self.showRecoveryPDF)
}

func codeCollectionCancelled() {
assert(navigationController?.visibleViewController is UIHostingController<AnyView>)
dismissPresentedViewController()
Expand Down
30 changes: 16 additions & 14 deletions LocalPackages/SyncUI/Sources/SyncUI/Views/Internal/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,23 @@ public struct CameraView: View {
cameraUnavailable()
}
.padding(.horizontal, 0)

VStack {
Spacer()
Text(UserText.cameraPointCameraIndication)
.padding(.vertical, 8)
.padding(.horizontal, 20)
.background(
RoundedRectangle(cornerRadius: 56)
.fill(.clear)
.background(BlurView(style: .light))
.cornerRadius(20)
)
.daxCaption()

if model.showCamera {
VStack {
Spacer()
Text(UserText.cameraPointCameraIndication)
.padding(.vertical, 8)
.padding(.horizontal, 20)
.background(
RoundedRectangle(cornerRadius: 56)
.fill(.clear)
.background(BlurView(style: .light))
.cornerRadius(20)
)
.daxCaption()
}
.padding(.bottom, 20)
}
.padding(.bottom, 20)
}
}
.ignoresSafeArea()
Expand Down
48 changes: 26 additions & 22 deletions LocalPackages/SyncUI/Sources/SyncUI/Views/SyncSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,32 @@ extension SyncSettingsView {
@ViewBuilder
func syncWithAnotherDeviceView() -> some View {
Section {
VStack(alignment: .center, spacing: 8) {
Image("Sync-Pair-96")
Text(UserText.syncWithAnotherDeviceTitle)
.daxTitle3()
Text(UserText.syncWithAnotherDeviceMessage)
.daxBodyRegular()
.multilineTextAlignment(.center)
.foregroundColor(Color(designSystemColor: .textPrimary))
Button(action: {
model.scanQRCode()
}, label: {
Text(UserText.syncWithAnotherDeviceButton)
.daxButton()
.foregroundColor(.white)
.frame(maxWidth: 310)
.frame(height: 50)
.background(
RoundedRectangle(cornerRadius: 8)
.fill(Color(designSystemColor: .accent))
)
})
.padding(.vertical, 16)
HStack {
Spacer()
VStack(alignment: .center, spacing: 8) {
Image("Sync-Pair-96")
Text(UserText.syncWithAnotherDeviceTitle)
.daxTitle3()
Text(UserText.syncWithAnotherDeviceMessage)
.daxBodyRegular()
.multilineTextAlignment(.center)
.foregroundColor(Color(designSystemColor: .textPrimary))
Button(action: {
model.scanQRCode()
}, label: {
Text(UserText.syncWithAnotherDeviceButton)
.daxButton()
.foregroundColor(.white)
.frame(maxWidth: 310)
.frame(height: 50)
.background(
RoundedRectangle(cornerRadius: 8)
.fill(Color(designSystemColor: .accent))
)
})
.padding(.vertical, 16)
}
Spacer()
}
} footer: {
Text(UserText.syncWithAnotherDeviceFooter)
Expand Down

0 comments on commit a2785c1

Please sign in to comment.