Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8658,7 +8658,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 57.5.0;
version = 57.6.0;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 12 additions & 17 deletions DuckDuckGo/Preferences/Model/SyncPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ final class SyncPreferences: ObservableObject, SyncUI.ManagementViewModel {
@MainActor
func presentShowOrEnterCodeDialog() {
Task { @MainActor in
let devicesAtStart = self.devices
self.$devices
.removeDuplicates()
.dropFirst()
.prefix(1)
.sink { [weak self] _ in
self?.managementDialogModel.endFlow()
.sink { [weak self] value in
self?.presentDialog(for: .deviceSynced(value.filter { !$0.isCurrent }))
self?.objectWillChange.send()
}.store(in: &cancellables)
managementDialogModel.codeToDisplay = syncService.account?.recoveryCode
Expand Down Expand Up @@ -241,10 +240,15 @@ extension SyncPreferences: ManagementDialogModelDelegate {
}

@MainActor
private func login(_ recoveryKey: SyncCode.RecoveryKey) async throws {
private func loginAndShowPresentedDialog(_ recoveryKey: SyncCode.RecoveryKey) async throws {
let device = deviceInfo()
try await syncService.login(recoveryKey, deviceName: device.name, deviceType: device.type)
let knownDevices = Set(self.devices.map { $0.id })
let devices = try await syncService.login(recoveryKey, deviceName: device.name, deviceType: device.type)
mapDevices(devices)
let syncedDevices = self.devices.filter { !knownDevices.contains($0.id) && !$0.isCurrent }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be something wrong with this check, but if knownDevices really is a set of all previously known devices, that should all be fine.

Anyway, when adding a third device to sync, both iOS and macOS display either 2 devices or 0 devices in the “Device Synced!” popup. I tried with adding iOS to macOS and vice versa.


managementDialogModel.endFlow()
presentDialog(for: .deviceSynced(syncedDevices))
}

@MainActor
Expand Down Expand Up @@ -277,24 +281,16 @@ extension SyncPreferences: ManagementDialogModelDelegate {
}
if let recoveryKey = syncCode.recovery {
// This will error if the account already exists, we don't have good UI for this just now
try await login(recoveryKey)
presentDialog(for: .deviceSynced)
try await loginAndShowPresentedDialog(recoveryKey)
} else if let connectKey = syncCode.connect {
var isNewAccount = false
if syncService.account == nil {
let device = deviceInfo()
try await syncService.createAccount(deviceName: device.name, deviceType: device.type)
isNewAccount = true
}

try await syncService.transmitRecoveryKey(connectKey)

if isNewAccount {
presentDialog(for: .deviceSynced)
} else {
managementDialogModel.endFlow()
}

// The UI will update when the devices list changes.
} else {
managementDialogModel.errorMessage = "Invalid code"
return
Expand All @@ -312,8 +308,7 @@ extension SyncPreferences: ManagementDialogModelDelegate {
managementDialogModel.codeToDisplay = connector?.code
presentDialog(for: .syncAnotherDevice)
if let recoveryKey = try await connector?.pollForRecoveryKey() {
try await login(recoveryKey)
presentDialog(for: .deviceSynced)
try await loginAndShowPresentedDialog(recoveryKey)
} else {
// Polling was likeley cancelled elsewhere (e.g. dialog closed)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct DeleteAccountView: View {
}
.frame(width: 360,
// Grow with the number of devices, up to a point
height: min(410, 280 + (CGFloat(devices.count) * 40)))
height: min(410, 272 + (CGFloat(devices.count) * 44)))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import SwiftUI
struct SyncSetupCompleteView: View {
@EnvironmentObject var model: ManagementDialogModel

var device: SyncDevice {
.init(kind: .mobile, name: "Dave's iPhone 14", id: UUID().uuidString)
}
let devices: [SyncDevice]

var body: some View {
SyncDialog(spacing: 20.0) {
Expand All @@ -34,18 +32,19 @@ struct SyncSetupCompleteView: View {
Text(UserText.deviceSyncedExplanation)
.multilineTextAlignment(.center)

SyncPreferencesRow {
SyncedDeviceIcon(kind: device.kind)
} centerContent: {
Text(device.name)
ScrollView {
SyncedDevicesList(devices: devices)
}
.roundedBorder()

}
} buttons: {
Button(UserText.next) {
model.delegate?.confirmSetupComplete()
}
}
.frame(width: 360, height: 298)
.frame(width: 360,
// Grow with the number of devices, up to a point
height: min(410, 258 + (CGFloat(devices.count) * 44)))

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum ManagementDialogKind: Equatable {
case deleteAccount(_ devices: [SyncDevice])
case askToSyncAnotherDevice
case syncAnotherDevice
case deviceSynced
case deviceSynced(_ devices: [SyncDevice])
case saveRecoveryPDF
case turnOffSync
case deviceDetails(_ device: SyncDevice)
Expand Down Expand Up @@ -62,8 +62,8 @@ public struct ManagementDialog: View {
RecoverAccountView()
case .syncAnotherDevice:
SyncAnotherDeviceView()
case .deviceSynced:
SyncSetupCompleteView()
case .deviceSynced(let devices):
SyncSetupCompleteView(devices: devices)
case .saveRecoveryPDF:
SaveRecoveryPDFView()
case .turnOffSync:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct SyncedDevicesView<ViewModel>: View where ViewModel: ManagementViewModel {

@EnvironmentObject var model: ViewModel

let timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()
let timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()

var body: some View {
SyncedDevicesList(devices: model.devices,
Expand Down