From 800ff95ff7a7154fe3a3f71652984a9578e5aa18 Mon Sep 17 00:00:00 2001 From: Dominik Kapusta Date: Thu, 14 Sep 2023 12:00:26 +0200 Subject: [PATCH] Switch Sync environment to production (#1622) 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. --- DuckDuckGo.xcodeproj/project.pbxproj | 10 ++- .../xcshareddata/swiftpm/Package.resolved | 4 +- DuckDuckGo/AppDelegate/AppDelegate.swift | 16 ++++- .../Utilities/UserDefaultsWrapper.swift | 4 ++ DuckDuckGo/Menus/MainMenu.storyboard | 34 +++++++-- DuckDuckGo/Sync/SyncDebugMenu.swift | 69 +++++++++++++++++++ .../DataBrokerProtection/Package.swift | 2 +- .../NetworkProtectionUI/Package.swift | 2 +- 8 files changed, 126 insertions(+), 15 deletions(-) create mode 100644 DuckDuckGo/Sync/SyncDebugMenu.swift diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index e286d1feef..d5c25a67d1 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -1608,6 +1608,9 @@ 3707C72E294B5D4400682A9F /* ContentBlockerRulesManagerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B610F2E727AA397100FCEBE9 /* ContentBlockerRulesManagerMock.swift */; }; 3707C72F294B5D4F00682A9F /* WebViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3783F92229432E1800BCA897 /* WebViewTests.swift */; }; 3707C730294B5D5C00682A9F /* DuckPlayerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3714B1E828EDBAAB0056C57A /* DuckPlayerTests.swift */; }; + 370A34B12AB24E3700C77F7C /* SyncDebugMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370A34B02AB24E3700C77F7C /* SyncDebugMenu.swift */; }; + 370A34B22AB24E3700C77F7C /* SyncDebugMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370A34B02AB24E3700C77F7C /* SyncDebugMenu.swift */; }; + 370A34B32AB24E3700C77F7C /* SyncDebugMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370A34B02AB24E3700C77F7C /* SyncDebugMenu.swift */; }; 3714B1E728EDB7FA0056C57A /* DuckPlayerPreferencesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3714B1E628EDB7FA0056C57A /* DuckPlayerPreferencesTests.swift */; }; 3714B1E928EDBAAB0056C57A /* DuckPlayerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3714B1E828EDBAAB0056C57A /* DuckPlayerTests.swift */; }; 37197EA12942441700394917 /* Tab+UIDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B634DBDE293C8F7F00C3C99E /* Tab+UIDelegate.swift */; }; @@ -3058,6 +3061,7 @@ 3706FE99293F661700E42796 /* Unit Tests App Store.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Unit Tests App Store.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 3706FEB2293F662100E42796 /* Integration Tests App Store.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Integration Tests App Store.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 3706FEC7293F6F7500E42796 /* BWManagement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BWManagement.swift; sourceTree = ""; }; + 370A34B02AB24E3700C77F7C /* SyncDebugMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncDebugMenu.swift; sourceTree = ""; }; 3714B1E628EDB7FA0056C57A /* DuckPlayerPreferencesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuckPlayerPreferencesTests.swift; sourceTree = ""; }; 3714B1E828EDBAAB0056C57A /* DuckPlayerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuckPlayerTests.swift; sourceTree = ""; }; 371C0A2827E33EDC0070591F /* FeedbackPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackPresenter.swift; sourceTree = ""; }; @@ -4503,6 +4507,7 @@ 3775913429AB99DA00E26367 /* Sync */ = { isa = PBXGroup; children = ( + 370A34B02AB24E3700C77F7C /* SyncDebugMenu.swift */, 3775913529AB9A1C00E26367 /* SyncManagementDialogViewController.swift */, 373D9B4729EEAC1B00381FDD /* SyncMetadataDatabase.swift */, 37445F982A1566420029F789 /* SyncDataProviders.swift */, @@ -9300,6 +9305,7 @@ 3192A1AC2A4C4CFF0084EA89 /* RandomAccessCollectionExtension.swift in Sources */, 3192A1AD2A4C4CFF0084EA89 /* NSOutlineViewExtensions.swift in Sources */, 3192A1AE2A4C4CFF0084EA89 /* AppDelegate.swift in Sources */, + 370A34B32AB24E3700C77F7C /* SyncDebugMenu.swift in Sources */, 3192A1AF2A4C4CFF0084EA89 /* ContentOverlayViewController.swift in Sources */, 3192A1B02A4C4CFF0084EA89 /* ContentBlockingTabExtension.swift in Sources */, 3192A1B12A4C4CFF0084EA89 /* OnboardingViewController.swift in Sources */, @@ -9714,6 +9720,7 @@ 4B4032852AAAC24400CCA602 /* WaitlistActivationDateStore.swift in Sources */, 3706FB93293F65D500E42796 /* PasteboardFolder.swift in Sources */, 3706FB94293F65D500E42796 /* CookieManagedNotificationView.swift in Sources */, + 370A34B22AB24E3700C77F7C /* SyncDebugMenu.swift in Sources */, 4B4D60BE2A0C848A00BCD287 /* NetworkProtection+ConvenienceInitializers.swift in Sources */, 3706FB95293F65D500E42796 /* PermissionType.swift in Sources */, 3706FB96293F65D500E42796 /* RecentlyClosedWindow.swift in Sources */, @@ -10788,6 +10795,7 @@ AA5C8F632591021700748EB7 /* NSApplicationExtension.swift in Sources */, AA9E9A5625A3AE8400D1959D /* NSWindowExtension.swift in Sources */, 7BD3AF5D2A8E7AF1006F9F56 /* KeychainType+ClientDefault.swift in Sources */, + 370A34B12AB24E3700C77F7C /* SyncDebugMenu.swift in Sources */, AAC5E4C725D6A6E8007F5990 /* BookmarkPopover.swift in Sources */, 37CC53F027E8D1440028713D /* PreferencesDownloadsView.swift in Sources */, B6F7127E29F6779000594A45 /* QRSharingService.swift in Sources */, @@ -12277,7 +12285,7 @@ repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = 77.3.1; + version = 78.0.0; }; }; AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 99199d4092..aa6f6bcaf6 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/BrowserServicesKit", "state" : { - "revision" : "a459d5a65c57ca03cbc4e337f025781aa54b53e3", - "version" : "77.3.0" + "revision" : "2a3dc29c9f0a2d90465a75afe47083a78ecaafe8", + "version" : "78.0.0" } }, { diff --git a/DuckDuckGo/AppDelegate/AppDelegate.swift b/DuckDuckGo/AppDelegate/AppDelegate.swift index 5412daa0b4..a9aeba2685 100644 --- a/DuckDuckGo/AppDelegate/AppDelegate.swift +++ b/DuckDuckGo/AppDelegate/AppDelegate.swift @@ -216,7 +216,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel } func applicationDidBecomeActive(_ notification: Notification) { - syncService?.initializeIfNeeded(isInternalUser: internalUserDecider?.isInternalUser ?? false) + syncService?.initializeIfNeeded() syncService?.scheduler.notifyAppLifecycleEvent() #if NETWORK_PROTECTION @@ -287,9 +287,19 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel // MARK: - Sync private func startupSync() { +#if DEBUG || REVIEW + let environment = ServerEnvironment( + UserDefaultsWrapper( + key: .syncEnvironment, + defaultValue: ServerEnvironment.production.description + ).wrappedValue + ) ?? .production +#else + let environment = ServerEnvironment.production +#endif let syncDataProviders = SyncDataProviders(bookmarksDatabase: BookmarkDatabase.shared.db) - let syncService = DDGSync(dataProvidersSource: syncDataProviders, errorEvents: SyncErrorHandler(), log: OSLog.sync) - syncService.initializeIfNeeded(isInternalUser: internalUserDecider?.isInternalUser ?? false) + let syncService = DDGSync(dataProvidersSource: syncDataProviders, errorEvents: SyncErrorHandler(), log: OSLog.sync, environment: environment) + syncService.initializeIfNeeded() syncDataProviders.setUpDatabaseCleaners(syncService: syncService) // This is also called in applicationDidBecomeActive, but we're also calling it here, since diff --git a/DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift b/DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift index 9db0019249..e2270b38d6 100644 --- a/DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift +++ b/DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift @@ -165,6 +165,10 @@ public struct UserDefaultsWrapper { case pixelExperimentEnrollmentDate = "pixel.experiment.enrollment.date" case pixelExperimentFiredPixels = "pixel.experiment.pixels.fired" case campaignVariant = "campaign.variant" + + // Sync + + case syncEnvironment = "sync.environment" } enum RemovedKeys: String, CaseIterable { diff --git a/DuckDuckGo/Menus/MainMenu.storyboard b/DuckDuckGo/Menus/MainMenu.storyboard index aec4236e88..bdd20ac149 100644 --- a/DuckDuckGo/Menus/MainMenu.storyboard +++ b/DuckDuckGo/Menus/MainMenu.storyboard @@ -7,12 +7,12 @@ - + - + - + @@ -480,7 +480,7 @@ - + @@ -834,9 +834,29 @@ CQ + + + + + + + + + + + + + + + + + + + + - + @@ -897,7 +917,7 @@ CQ - + @@ -982,7 +1002,7 @@ CQ - + diff --git a/DuckDuckGo/Sync/SyncDebugMenu.swift b/DuckDuckGo/Sync/SyncDebugMenu.swift new file mode 100644 index 0000000000..e920d1695f --- /dev/null +++ b/DuckDuckGo/Sync/SyncDebugMenu.swift @@ -0,0 +1,69 @@ +// +// SyncDebugMenu.swift +// +// Copyright © 2023 DuckDuckGo. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Foundation +import DDGSync + +@objc @MainActor +final class SyncDebugMenu: NSMenu { + + @IBOutlet private weak var environmentMenu: NSMenu! { + didSet { + populateEnvironmentMenu() + } + } + + override func update() { + populateEnvironmentMenu() + } + + private func populateEnvironmentMenu() { + environmentMenu.removeAllItems() + + guard let syncService = (NSApp.delegate as? AppDelegate)?.syncService else { + return + } + + let currentEnvironment = syncService.serverEnvironment + let anotherEnvironment: ServerEnvironment = syncService.serverEnvironment == .development ? .production : .development + + let statusMenuItem = NSMenuItem(title: "Current: \(currentEnvironment.description)", action: nil, keyEquivalent: "") + statusMenuItem.isEnabled = false + environmentMenu.addItem(statusMenuItem) + + let toggleMenuItem = NSMenuItem( + title: "Switch to \(anotherEnvironment.description)", + action: #selector(switchSyncEnvironment), + target: self, + representedObject: anotherEnvironment) + environmentMenu.addItem(toggleMenuItem) + } + + @objc func switchSyncEnvironment(_ sender: NSMenuItem) { +#if DEBUG || REVIEW + guard let syncService = (NSApp.delegate as? AppDelegate)?.syncService, + let environment = sender.representedObject as? ServerEnvironment + else { + return + } + + syncService.updateServerEnvironment(environment) + UserDefaults.standard.set(environment.description, forKey: UserDefaultsWrapper.Key.syncEnvironment.rawValue) +#endif + } +} diff --git a/LocalPackages/DataBrokerProtection/Package.swift b/LocalPackages/DataBrokerProtection/Package.swift index 11442b6ccb..19b02b9ccd 100644 --- a/LocalPackages/DataBrokerProtection/Package.swift +++ b/LocalPackages/DataBrokerProtection/Package.swift @@ -29,7 +29,7 @@ let package = Package( targets: ["DataBrokerProtection"]) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "77.3.1"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "78.0.0"), .package(path: "../SwiftUIExtensions") ], targets: [ diff --git a/LocalPackages/NetworkProtectionUI/Package.swift b/LocalPackages/NetworkProtectionUI/Package.swift index b7433bb2b9..9a641a3394 100644 --- a/LocalPackages/NetworkProtectionUI/Package.swift +++ b/LocalPackages/NetworkProtectionUI/Package.swift @@ -15,7 +15,7 @@ let package = Package( targets: ["NetworkProtectionUI"]) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "77.3.1"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "78.0.0"), .package(path: "../SwiftUIExtensions") ], targets: [