Skip to content

Commit

Permalink
manage synced enabled errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaTardio committed Dec 13, 2023
1 parent 8a18fe7 commit e08fe9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
20 changes: 14 additions & 6 deletions DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate {
let okAction = UIAlertAction(title: UserText.syncPausedAlertOkButton, style: .default, handler: nil)
alertController.addAction(okAction)

// Give time to the is syncing view to appear
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
if type == .unableToSync {
// Give time to the is syncing view to appear
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.dismissPresentedViewController { [weak self] in
self?.present(alertController, animated: true, completion: nil)
}
}
} else {
self.dismissPresentedViewController { [weak self] in
self?.present(alertController, animated: true, completion: nil)
}
Expand Down Expand Up @@ -170,14 +176,15 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate {
alert.addAction(title: UserText.syncTurnOffConfirmAction, style: .destructive) {
Task { @MainActor in
do {
self.rootView.model.isSyncEnabled = false
try await self.syncService.disconnect()
self.rootView.model.isSyncEnabled = false
AppUserDefaults().isSyncBookmarksPaused = false
AppUserDefaults().isSyncCredentialsPaused = false
continuation.resume(returning: true)
} catch {
self.handleError(SyncError.unableToTurnSyncOff, error: error)
continuation.resume(returning: false)
}
continuation.resume(returning: true)
}
}
self.present(alert, animated: true)
Expand All @@ -195,14 +202,15 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate {
alert.addAction(title: UserText.syncDeleteAllConfirmAction, style: .destructive) {
Task { @MainActor in
do {
self.rootView.model.isSyncEnabled = false
try await self.syncService.deleteAccount()
self.rootView.model.isSyncEnabled = false
AppUserDefaults().isSyncBookmarksPaused = false
AppUserDefaults().isSyncCredentialsPaused = false
continuation.resume(returning: true)
} catch {
self.handleError(SyncError.unableToDeleteData, error: error)
continuation.resume(returning: false)
}
continuation.resume(returning: true)
}
}
self.present(alert, animated: true)
Expand Down
8 changes: 6 additions & 2 deletions DuckDuckGo/SyncSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ class SyncSettingsViewController: UIHostingController<SyncSettingsView> {

func dismissPresentedViewController(completion: (() -> Void)? = nil) {
guard let presentedViewController = navigationController?.presentedViewController,
!(presentedViewController is UIHostingController<SyncSettingsView>) else { return }
!(presentedViewController is UIHostingController<SyncSettingsView>) else {

Check failure on line 176 in DuckDuckGo/SyncSettingsViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Lines should not have trailing whitespace (trailing_whitespace)
completion?()
return
}
presentedViewController.dismiss(animated: true, completion: completion)
endConnectMode()
}
Expand All @@ -190,7 +193,8 @@ class SyncSettingsViewController: UIHostingController<SyncSettingsView> {
let devices = try await syncService.fetchDevices()
mapDevices(devices)
} catch {
handleError(SyncError.unableToGetDevices, error: error)
// Not displaying error since there is the spinner and it is called every few seconds
// assertionFailure(error.localizedDescription)
}
}
}
Expand Down

0 comments on commit e08fe9f

Please sign in to comment.