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

Commit

Permalink
Fix #8148: Problem with toggling Sync Types from Settings (#8149)
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel committed Sep 25, 2023
1 parent e27e68a commit d228068
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ extension BraveSyncAPI {
}

@discardableResult
func joinSyncGroup(codeWords: String, syncProfileService: BraveSyncProfileServiceIOS, shouldEnableBookmarks: Bool) -> Bool {
func joinSyncGroup(codeWords: String, syncProfileService: BraveSyncProfileServiceIOS) -> Bool {
if setSyncCode(codeWords) {
enableSyncTypes(syncProfileService: syncProfileService, shouldEnableBookmarks: shouldEnableBookmarks)
// Enable default sync type Bookmarks when joining a chain
Preferences.Chromium.syncBookmarksEnabled.value = true
enableSyncTypes(syncProfileService: syncProfileService)
requestSync()
setSetupComplete()
Preferences.Chromium.syncEnabled.value = true
Expand Down Expand Up @@ -92,13 +94,9 @@ extension BraveSyncAPI {
resetSync()
}

func enableSyncTypes(syncProfileService: BraveSyncProfileServiceIOS, shouldEnableBookmarks: Bool) {
func enableSyncTypes(syncProfileService: BraveSyncProfileServiceIOS) {
syncProfileService.userSelectedTypes = []

// This value is true by default
// In some cases while joining a sync chain all values must be disabled
Preferences.Chromium.syncBookmarksEnabled.value = shouldEnableBookmarks

if Preferences.Chromium.syncBookmarksEnabled.value {
syncProfileService.userSelectedTypes.update(with: .BOOKMARKS)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class SyncSettingsTableViewController: SyncViewController, UITableViewDelegate,
}
}

syncAPI.enableSyncTypes(syncProfileService: syncProfileService, shouldEnableBookmarks: false)
syncAPI.enableSyncTypes(syncProfileService: syncProfileService)
}
}

Expand Down
10 changes: 6 additions & 4 deletions Sources/Brave/Frontend/Sync/SyncWelcomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import BraveShared
import BraveCore
import BraveUI
import os.log
import Preferences

/// Sometimes during heavy operations we want to prevent user from navigating back, changing screen etc.
protocol NavigationPrevention {
Expand Down Expand Up @@ -261,7 +262,7 @@ class SyncWelcomeViewController: SyncViewController {
}
}

self.syncAPI.joinSyncGroup(codeWords: self.syncAPI.getSyncCode(), syncProfileService: self.syncProfileServices, shouldEnableBookmarks: true)
self.syncAPI.joinSyncGroup(codeWords: self.syncAPI.getSyncCode(), syncProfileService: self.syncProfileServices)
self.handleSyncSetupFailure()
}

Expand Down Expand Up @@ -337,7 +338,7 @@ extension SyncWelcomeViewController: SyncPairControllerDelegate {

// In parallel set code words - request sync and setup complete
// should be called on brave-core side
syncAPI.joinSyncGroup(codeWords: codeWords, syncProfileService: syncProfileServices, shouldEnableBookmarks: false)
syncAPI.joinSyncGroup(codeWords: codeWords, syncProfileService: syncProfileServices)
handleSyncSetupFailure()
}

Expand Down Expand Up @@ -485,8 +486,9 @@ extension SyncWelcomeViewController: SyncPairControllerDelegate {
}

private func enableDefaultTypeAndPushSettings() {
// Enable Bookmark Syncing and push settings
syncAPI.enableSyncTypes(syncProfileService: syncProfileServices, shouldEnableBookmarks: true)
// Enable default sync type Bookmarks and push settings
Preferences.Chromium.syncBookmarksEnabled.value = true
syncAPI.enableSyncTypes(syncProfileService: syncProfileServices)
pushSettings()
}

Expand Down
3 changes: 1 addition & 2 deletions Sources/Brave/Migration/Migration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class Migration {
}

// Adding Observer to enable sync types

NotificationCenter.default.addObserver(
self,
selector: #selector(enableUserSelectedTypesForSync),
Expand All @@ -56,7 +55,7 @@ public class Migration {
return
}

braveCore.syncAPI.enableSyncTypes(syncProfileService: braveCore.syncProfileService, shouldEnableBookmarks: true)
braveCore.syncAPI.enableSyncTypes(syncProfileService: braveCore.syncProfileService)
}

/// Adblock files don't have to be moved, they now have a new directory and will be downloaded there.
Expand Down

0 comments on commit d228068

Please sign in to comment.