Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Simplify connecting sync accounts when two exist #3747

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,13 @@ extension Pixel {
case syncSecureStorageDecodingError
case syncAccountRemoved(reason: String)

case syncAskUserToSwitchAccount
case syncUserAcceptedSwitchingAccount
case syncUserCancelledSwitchingAccount
case syncUserSwitchedAccount
case syncUserSwitchedLogoutError
case syncUserSwitchedLoginError

case syncGetOtherDevices
case syncGetOtherDevicesCopy
case syncGetOtherDevicesShare
Expand Down Expand Up @@ -1620,6 +1627,13 @@ extension Pixel.Event {
case .syncSecureStorageDecodingError: return "sync_secure_storage_decoding_error"
case .syncAccountRemoved(let reason): return "sync_account_removed_reason_\(reason)"

case .syncAskUserToSwitchAccount: return "sync_ask_user_to_switch_account"
case .syncUserAcceptedSwitchingAccount: return "sync_user_accepted_switching_account"
case .syncUserCancelledSwitchingAccount: return "sync_user_cancelled_switching_account"
case .syncUserSwitchedAccount: return "sync_user_switched_account"
case .syncUserSwitchedLogoutError: return "sync_user_switched_logout_error"
case .syncUserSwitchedLoginError: return "sync_user_switched_login_error"

case .syncGetOtherDevices: return "sync_get_other_devices"
case .syncGetOtherDevicesCopy: return "sync_get_other_devices_copy"
case .syncGetOtherDevicesShare: return "sync_get_other_devices_share"
Expand Down
39 changes: 39 additions & 0 deletions DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,45 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate {
}
}

@MainActor
func promptToSwitchAccounts(recoveryKey: SyncCode.RecoveryKey) {
let alertController = UIAlertController(
title: UserText.syncAlertSwitchAccountTitle,
message: UserText.syncAlertSwitchAccountMessage,
preferredStyle: .alert)
alertController.addAction(title: UserText.syncAlertSwitchAccountButton, style: .default) { [weak self] in
Task {
Pixel.fire(pixel: .syncUserAcceptedSwitchingAccount)
await self?.switchAccounts(recoveryKey: recoveryKey)
}
}
alertController.addAction(title: UserText.actionCancel, style: .cancel) {
Pixel.fire(pixel: .syncUserCancelledSwitchingAccount)
}
// Gives time to the is syncing view to appear
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
self?.dismissPresentedViewController { [weak self] in
self?.present(alertController, animated: true, completion: nil)
Pixel.fire(pixel: .syncAskUserToSwitchAccount)
}
}
}

func switchAccounts(recoveryKey: SyncCode.RecoveryKey) async {
do {
try await syncService.disconnect()
} catch {
Pixel.fire(pixel: .syncUserSwitchedLogoutError)
}

do {
try await loginAndShowDeviceConnected(recoveryKey: recoveryKey)
} catch {
Pixel.fire(pixel: .syncUserSwitchedLoginError)
}
Pixel.fire(pixel: .syncUserSwitchedAccount)
}

private func getErrorType(from errorString: String?) -> AsyncErrorType? {
guard let errorString = errorString else {
return nil
Expand Down
10 changes: 9 additions & 1 deletion DuckDuckGo/SyncSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ extension SyncSettingsViewController: ScanOrPasteCodeViewModelDelegate {
return true
} catch {
if self.rootView.model.isSyncEnabled {
handleError(.unableToMergeTwoAccounts, error: error, event: .syncLoginExistingAccountError)
await handleTwoSyncAccountsFoundDuringRecovery(recoveryKey)
} else {
handleError(.unableToSyncToServer, error: error, event: .syncLoginError)
}
Expand Down Expand Up @@ -402,6 +402,14 @@ extension SyncSettingsViewController: ScanOrPasteCodeViewModelDelegate {
return false
}

private func handleTwoSyncAccountsFoundDuringRecovery(_ recoveryKey: SyncCode.RecoveryKey) async {
if rootView.model.devices.count > 1 {
promptToSwitchAccounts(recoveryKey: recoveryKey)
} else {
await switchAccounts(recoveryKey: recoveryKey)
}
}

func dismissVCAndShowRecoveryPDF() {
self.navigationController?.topViewController?.dismiss(animated: true, completion: self.showRecoveryPDF)
}
Expand Down
3 changes: 3 additions & 0 deletions DuckDuckGo/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,9 @@ But if you *do* want a peek under the hood, you can find more information about
static let unknownErrorTryAgainMessage = NSLocalizedString("error.unknown.try.again", value: "An unknown error has occurred", comment: "Generic error message on a dialog for when the cause is not known.")
public static let syncPausedAlertOkButton = NSLocalizedString("alert.sync-paused-alert-ok-button", value: "OK", comment: "Confirmation button in alert")
public static let syncPausedAlertLearnMoreButton = NSLocalizedString("alert.sync-paused-alert-learn-more-button", value: "Learn More", comment: "Learn more button in alert")
public static let syncAlertSwitchAccountTitle = NSLocalizedString("alert.sync-switch-account-title", value: "Switch to a different Sync?", comment: "Switch account title in alert")
public static let syncAlertSwitchAccountMessage = NSLocalizedString("alert.sync-switch-account-message", value: "This device is already synced, are you sure you want to sync it with a different backup or device? Switching won't remove any data already synced to this device.", comment: "Description for switching sync accounts when there's two")
public static let syncAlertSwitchAccountButton = NSLocalizedString("alert.sync-switch-account-button", value: "Switch Sync", comment: "Switch account button in alert")
public static let syncErrorAlertTitle = NSLocalizedString("alert.sync-error", value: "Sync & Backup Error", comment: "Title for sync error alert")
public static let unableToSyncToServerDescription = NSLocalizedString("alert.unable-to-sync-to-server-description", value: "Unable to connect to the server.", comment: "Description for unable to sync to server error")
public static let unableToSyncWithOtherDeviceDescription = NSLocalizedString("alert.unable-to-sync-with-other-device-description", value: "Unable to Sync with another device.", comment: "Description for unable to sync with another device error")
Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/bg.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Синхронизирането е на пауза";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Превключване на синхронизирането";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Това устройство вече е синхронизирано, сигурни ли сте, че искате да го синхронизирате с друго резервно копие или устройство? Превключването няма да изтрие данните, които вече са синхронизирани с това устройство.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Превключване към друго синхронизиране?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Sync & Backup временно не е налична.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/cs.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Synchronizace je pozastavená";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Přepnout synchronizaci";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Tohle zařízení už je synchronizované. Opravdu ho chceš synchronizovat s jinou zálohou nebo zařízením? Přepnutím se nesmažou žádná data, která už s tímto zařízením byla synchronizována.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Přepnout synchronizaci?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Funkce Sync & Backup je dočasně nedostupná.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/da.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Synkronisering er sat på pause";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Skift synkronisering";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Denne enhed er allerede synkroniseret. Er du sikker på, at du vil synkronisere den med en anden sikkerhedskopi eller enhed? Et skifte fjerner ikke data, der allerede er synkroniseret til denne enhed.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Skift til en anden synkronisering?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Sync & Backup er midlertidigt utilgængelig.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Synchronisierung angehalten";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Synchronisierung wechseln";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Dieses Gerät ist bereits synchronisiert. Bist du sicher, dass du es mit einem anderen Back-up oder Gerät synchronisieren möchtest? Beim Wechsel werden keine bereits mit diesem Gerät synchronisierten Daten entfernt.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Zu einer anderen Synchronisierung wechseln?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Sync & Backup ist vorübergehend nicht verfügbar.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/el.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Ο συγχρονισμός έχει τεθεί σε παύση";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Αλλαγή συγχρονισμού";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Η συσκευή αυτή είναι ήδη συγχρονισμένη. Θέλετε σίγουρα να τη συγχρονίσετε με ένα διαφορετικό αντίγραφο ασφαλείας ή συσκευή; Η αλλαγή δεν θα αφαιρέσει δεδομένα που έχουν ήδη συγχρονιστεί σε αυτήν τη συσκευή.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Αλλαγή σε διαφορετικό συγχρονισμό;";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Το Sync & Backup είναι προσωρινά μη διαθέσιμο.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Sync is Paused";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Switch Sync";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "This device is already synced, are you sure you want to sync it with a different backup or device? Switching won't remove any data already synced to this device.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Switch to a different Sync?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Sync & Backup is temporarily unavailable.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "La sincronización está en pausa";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Cambiar sincronización";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Este dispositivo ya está sincronizado. ¿Seguro que deseas sincronizarlo con una copia de seguridad o con un dispositivo diferente? Cambiar no eliminará ningún dato ya sincronizado en este dispositivo.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "¿Cambiar a una sincronización diferente?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "La sincronización y la copia de seguridad no están disponibles temporalmente.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/et.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Sünkroonimine on peatatud";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Synci lülitamine";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "See seade on juba sünkroonitud, kas soovid kindlasti seda sünkroonida teise varukoopia või seadmega? Vahetamine ei eemalda selle seadmega juba sünkroonitud andmeid.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Kas lülituda teisele Sync'ile?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Sync & Backup pole ajutiselt saadaval.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/fi.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Synkronointi on keskeytetty";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Vaihda synkronointi";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Tämä laite on jo synkronoitu. Haluatko varmasti synkronoida sen toisen varmuuskopion tai laitteen kanssa? Vaihtaminen ei poista tähän laitteeseen jo synkronoituja tietoja.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Vaihdetaanko toiseen synkronointiin?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Synkronointi ja varmuuskopiointi on tilapäisesti poissa käytöstä.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "La synchronisation est suspendue";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Changer de synchronisation";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Cet appareil est déjà synchronisé. Voulez-vous vraiment le synchroniser avec une autre sauvegarde ou un autre appareil ? Ce changement ne supprimera aucune donnée déjà synchronisée sur cet appareil.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Passer à une autre synchronisation ?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Sync & Backup est temporairement indisponible.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/hr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Sinkronizacija je pauzirana";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Prebaci sinkronizaciju";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Ovaj je uređaj već sinkroniziran. Jesi li siguran da ga želiš sinkronizirati s drugom sigurnosnom kopijom ili uređajem? Prebacivanjem se neće ukloniti nijedan podatak koji je već sinkroniziran s ovim uređajem.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Prijeđi na drugu sinkronizaciju?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Sinkronizacija i sigurnosno kopiranje Sync & Backup privremeno su nedostupni.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/hu.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "A szinkronizálás szünetel";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Váltás másik szinkronizálási lehetőségre";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Ez az eszköz már szinkronizálva van. Biztosan szinkronizálni szeretnéd egy másik biztonsági mentéssel vagy eszközzel? A váltás nem távolítja el ezzel az eszközzel már szinkronizált adatokat.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Átváltasz egy másik szinkronizációs lehetőségre?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "A szinkronizálás és biztonsági mentés átmenetileg nem érhető el.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/it.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Sync è in pausa";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Cambia sincronizzazione";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Questo dispositivo è già sincronizzato. Vuoi davvero sincronizzarlo con un backup o un dispositivo diverso? L'operazione non rimuoverà alcun dato già sincronizzato su questo dispositivo.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Vuoi passare a una sincronizzazione diversa?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Sync & Backup non è temporaneamente disponibile.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/lt.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Sinchronizavimas pristabdytas";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Perjungti sinchronizavimą";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Šis įrenginys jau sinchronizuotas, ar tikrai norite jį sinchronizuoti su kita atsargine kopija ar įrenginiu? Perjungiant nebus pašalinti jokie duomenys, jau sinchronizuoti su šiuo įrenginiu.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Perjungti į kitą sinchronizaciją?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Sinchronizavimas ir atsarginės kopijos kūrimas laikinai nepasiekiami.";

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/lv.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
/* Title for alert shown when sync paused for an error */
"alert.sync-paused-title" = "Sinhronizācija ir apturēta";

/* Switch account button in alert */
"alert.sync-switch-account-button" = "Pārslēgt sinhronizāciju";

/* Description for switching sync accounts when there's two */
"alert.sync-switch-account-message" = "Šī ierīce jau ir sinhronizēta, vai tiešām vēlies to sinhronizēt ar citu dublēšanas sistēmu vai ierīci? Pārslēdzot netiks dzēsti dati, kas jau ir sinhronizēti ar šo ierīci.";

/* Switch account title in alert */
"alert.sync-switch-account-title" = "Vai pārslēgt uz citu sinhronizāciju?";

/* Description for alert shown when sync error occurs because of too many requests */
"alert.sync-too-many-requests-error-description" = "Sync & Backup uz laiku nav pieejams.";

Expand Down
Loading
Loading