Skip to content

Commit

Permalink
Switch Sync environment to production (#2009)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1205489036222324/f

Description:
This patch switches default server environment for Sync to production and adds environment switcher
to the Debug menu.
  • Loading branch information
ayoy authored Sep 14, 2023
1 parent de51a97 commit f4597a5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Core/UserDefaultsPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public struct UserDefaultsWrapper<T> {
case appTPUsed = "com.duckduckgo.ios.appTrackingProtection.appTPUsed"

case defaultBrowserUsageLastSeen = "com.duckduckgo.ios.default-browser-usage-last-seen"

case syncEnvironment = "com.duckduckgo.ios.sync-environment"
}

private let key: Key
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8878,7 +8878,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 77.4.0;
version = 78.0.0;
};
};
C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/DuckDuckGo/BrowserServicesKit",
"state": {
"branch": null,
"revision": "7ae180677e7fd28755ba6dd603e011605b75aa38",
"version": "77.4.0"
"revision": "2a3dc29c9f0a2d90465a75afe47083a78ecaafe8",
"version": "78.0.0"
}
},
{
Expand Down Expand Up @@ -156,7 +156,7 @@
},
{
"package": "TrackerRadarKit",
"repositoryURL": "https://github.com/duckduckgo/TrackerRadarKit.git",
"repositoryURL": "https://github.com/duckduckgo/TrackerRadarKit",
"state": {
"branch": null,
"revision": "4684440d03304e7638a2c8086895367e90987463",
Expand Down
13 changes: 10 additions & 3 deletions DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// MARK: Sync initialisation

let environment = ServerEnvironment(
UserDefaultsWrapper(
key: .syncEnvironment,
defaultValue: ServerEnvironment.production.description
).wrappedValue
) ?? .production

syncDataProviders = SyncDataProviders(bookmarksDatabase: bookmarksDatabase, secureVaultErrorReporter: SecureVaultErrorReporter.shared)
let syncService = DDGSync(dataProvidersSource: syncDataProviders, errorEvents: SyncErrorHandler(), log: .syncLog)
syncService.initializeIfNeeded(isInternalUser: InternalUserStore().isInternalUser)
let syncService = DDGSync(dataProvidersSource: syncDataProviders, errorEvents: SyncErrorHandler(), log: .syncLog, environment: environment)
syncService.initializeIfNeeded()
self.syncService = syncService

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
Expand Down Expand Up @@ -260,7 +267,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidBecomeActive(_ application: UIApplication) {
guard !testing else { return }

syncService.initializeIfNeeded(isInternalUser: InternalUserStore().isInternalUser)
syncService.initializeIfNeeded()
syncDataProviders.setUpDatabaseCleanersIfNeeded(syncService: syncService)

if !(overlayWindow?.rootViewController is AuthenticationViewController) {
Expand Down
32 changes: 31 additions & 1 deletion DuckDuckGo/SyncDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class SyncDebugViewController: UITableViewController {

private let titles = [
Sections.info: "Info",
Sections.models: "Models"
Sections.models: "Models",
Sections.environment: "Environment"
]

enum Sections: Int, CaseIterable {

case info
case models
case environment

}

Expand All @@ -51,6 +53,12 @@ class SyncDebugViewController: UITableViewController {

}

enum EnvironmentRows: Int, CaseIterable {

case toggle

}

private let bookmarksDatabase: CoreDataDatabase
private let sync: DDGSyncing

Expand Down Expand Up @@ -85,6 +93,7 @@ class SyncDebugViewController: UITableViewController {
return titles[section]
}

// swiftlint:disable:next cyclomatic_complexity
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

Expand Down Expand Up @@ -120,6 +129,17 @@ class SyncDebugViewController: UITableViewController {
break
}

case .environment:
switch EnvironmentRows(rawValue: indexPath.row) {
case .toggle:
let targetEnvironment: ServerEnvironment = sync.serverEnvironment == .production ? .development : .production
cell.textLabel?.text = sync.serverEnvironment.description
cell.detailTextLabel?.text = "Click to switch to \(targetEnvironment)"

case .none:
break
}

default: break
}

Expand All @@ -130,6 +150,7 @@ class SyncDebugViewController: UITableViewController {
switch Sections(rawValue: section) {
case .info: return InfoRows.allCases.count
case .models: return ModelRows.allCases.count
case .environment: return EnvironmentRows.allCases.count
case .none: return 0
}
}
Expand All @@ -142,6 +163,15 @@ class SyncDebugViewController: UITableViewController {
sync.scheduler.requestSyncImmediately()
default: break
}
case .environment:
switch EnvironmentRows(rawValue: indexPath.row) {
case .toggle:
let targetEnvironment: ServerEnvironment = sync.serverEnvironment == .production ? .development : .production
sync.updateServerEnvironment(targetEnvironment)
UserDefaults.standard.set(targetEnvironment.description, forKey: UserDefaultsWrapper<String>.Key.syncEnvironment.rawValue)
tableView.reloadSections(.init(integer: indexPath.section), with: .automatic)
default: break
}
default: break
}

Expand Down

0 comments on commit f4597a5

Please sign in to comment.