Skip to content

Commit

Permalink
Switch Sync environment to production (#1622)
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 b835c0a commit 800ff95
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 15 deletions.
10 changes: 9 additions & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
370A34B02AB24E3700C77F7C /* SyncDebugMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncDebugMenu.swift; sourceTree = "<group>"; };
3714B1E628EDB7FA0056C57A /* DuckPlayerPreferencesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuckPlayerPreferencesTests.swift; sourceTree = "<group>"; };
3714B1E828EDBAAB0056C57A /* DuckPlayerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuckPlayerTests.swift; sourceTree = "<group>"; };
371C0A2827E33EDC0070591F /* FeedbackPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackPresenter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4503,6 +4507,7 @@
3775913429AB99DA00E26367 /* Sync */ = {
isa = PBXGroup;
children = (
370A34B02AB24E3700C77F7C /* SyncDebugMenu.swift */,
3775913529AB9A1C00E26367 /* SyncManagementDialogViewController.swift */,
373D9B4729EEAC1B00381FDD /* SyncMetadataDatabase.swift */,
37445F982A1566420029F789 /* SyncDataProviders.swift */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -12277,7 +12285,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 77.3.1;
version = 78.0.0;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
16 changes: 13 additions & 3 deletions DuckDuckGo/AppDelegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public struct UserDefaultsWrapper<T> {
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 {
Expand Down
34 changes: 27 additions & 7 deletions DuckDuckGo/Menus/MainMenu.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<!--Application-->
<scene sceneID="JPo-4y-FX3">
<objects>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="DuckDuckGo_DBP" customModuleProvider="target"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<customObject id="WIK-gq-Ncg" customClass="CopyHandler" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target"/>
<customObject id="WIK-gq-Ncg" customClass="CopyHandler" customModule="DuckDuckGo_DBP" customModuleProvider="target"/>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<application id="hnw-xV-0zn" sceneMemberID="viewController">
<menu key="mainMenu" title="Main Menu" systemMenu="main" id="AYu-sK-qS6" customClass="MainMenu" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target">
<menu key="mainMenu" title="Main Menu" systemMenu="main" id="AYu-sK-qS6" customClass="MainMenu" customModule="DuckDuckGo_DBP" customModuleProvider="target">
<items>
<menuItem title="DuckDuckGo" id="1Xt-HY-uBw">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down Expand Up @@ -480,7 +480,7 @@
</menuItem>
<menuItem title="History" id="aVY-po-b3d">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="History" id="SLT-Z6-mh7" customClass="HistoryMenu" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target">
<menu key="submenu" title="History" id="SLT-Z6-mh7" customClass="HistoryMenu" customModule="DuckDuckGo_DBP" customModuleProvider="target">
<items>
<menuItem title="Back" enabled="NO" keyEquivalent="[" id="VWV-vB-Mtc">
<connections>
Expand Down Expand Up @@ -834,9 +834,29 @@ CQ
</items>
</menu>
</menuItem>
<menuItem title="Sync" id="8rI-iH-wNC">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Sync" id="Kw4-67-mit" customClass="SyncDebugMenu" customModule="DuckDuckGo_DBP" customModuleProvider="target">
<items>
<menuItem title="Environment" id="qD7-Gw-s2h">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Environment" id="lRd-Ih-n5j">
<items>
<menuItem title="Item" id="amC-1R-0QS">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</menuItem>
</items>
<connections>
<outlet property="environmentMenu" destination="lRd-Ih-n5j" id="xxg-yh-bfI"/>
</connections>
</menu>
</menuItem>
<menuItem title="Network Protection" id="Dt6-sj-4hn">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Network Protection" id="Rah-lS-gno" customClass="NetworkProtectionDebugMenu" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target">
<menu key="submenu" title="Network Protection" id="Rah-lS-gno" customClass="NetworkProtectionDebugMenu" customModule="DuckDuckGo_DBP" customModuleProvider="target">
<items>
<menuItem title="Reset All State Keeping Invite" id="Mqz-Le-LgQ">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down Expand Up @@ -897,7 +917,7 @@ CQ
</menuItem>
<menuItem title="Onboarding" id="xu6-z0-age">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Onboarding" id="L82-We-Wwv" customClass="NetworkProtectionOnboardingMenu" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target">
<menu key="submenu" title="Onboarding" id="L82-We-Wwv" customClass="NetworkProtectionOnboardingMenu" customModule="DuckDuckGo_DBP" customModuleProvider="target">
<items>
<menuItem title="Reset Onboarding Status" id="gfc-0G-Ujy">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down Expand Up @@ -982,7 +1002,7 @@ CQ
</menuItem>
<menuItem title="Simulate Failure" id="K5h-D4-For">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Simulate Failure" id="iLs-sj-2Gd" customClass="NetworkProtectionSimulateFailureMenu" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target">
<menu key="submenu" title="Simulate Failure" id="iLs-sj-2Gd" customClass="NetworkProtectionSimulateFailureMenu" customModule="DuckDuckGo_DBP" customModuleProvider="target">
<items>
<menuItem title="Enable NetP &gt; Controller Failure" id="xyA-ob-gEy" userLabel="Controller Failure">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down
69 changes: 69 additions & 0 deletions DuckDuckGo/Sync/SyncDebugMenu.swift
Original file line number Diff line number Diff line change
@@ -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<String>.Key.syncEnvironment.rawValue)
#endif
}
}
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit 800ff95

Please sign in to comment.