Skip to content

Commit

Permalink
Add the VPN waitlist type.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Oct 31, 2023
1 parent f6a30b2 commit 58f3cf5
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 6 deletions.
12 changes: 12 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
4B470EE4299C6DFB0086EBDC /* Core.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F143C2E41E4A4CD400CFDE3A /* Core.framework */; };
4B52648B25F9613B00CB4C24 /* trackerData.json in Resources */ = {isa = PBXBuildFile; fileRef = 4B52648A25F9613B00CB4C24 /* trackerData.json */; };
4B53648A26718D0E001AA041 /* EmailWaitlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B53648926718D0E001AA041 /* EmailWaitlist.swift */; };
4B5C46232AF1B4D4002A4432 /* VPNWaitlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B5C46222AF1B4D4002A4432 /* VPNWaitlist.swift */; };
4B60AC97252EC07B00E8D219 /* fullscreenvideo.js in Resources */ = {isa = PBXBuildFile; fileRef = 4B60AC96252EC07B00E8D219 /* fullscreenvideo.js */; };
4B60ACA1252EC0B100E8D219 /* FullScreenVideoUserScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B60ACA0252EC0B100E8D219 /* FullScreenVideoUserScript.swift */; };
4B62C4BA25B930DD008912C6 /* AppConfigurationFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B62C4B925B930DD008912C6 /* AppConfigurationFetchTests.swift */; };
Expand Down Expand Up @@ -1280,6 +1281,7 @@
4B470EE2299C6DD10086EBDC /* AppTrackingProtectionStoringModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppTrackingProtectionStoringModel.swift; sourceTree = "<group>"; };
4B52648A25F9613B00CB4C24 /* trackerData.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = trackerData.json; sourceTree = "<group>"; };
4B53648926718D0E001AA041 /* EmailWaitlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmailWaitlist.swift; sourceTree = "<group>"; };
4B5C46222AF1B4D4002A4432 /* VPNWaitlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNWaitlist.swift; sourceTree = "<group>"; };
4B60AC96252EC07B00E8D219 /* fullscreenvideo.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = fullscreenvideo.js; sourceTree = "<group>"; };
4B60ACA0252EC0B100E8D219 /* FullScreenVideoUserScript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullScreenVideoUserScript.swift; sourceTree = "<group>"; };
4B62C4B925B930DD008912C6 /* AppConfigurationFetchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppConfigurationFetchTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3351,13 +3353,22 @@
name = AppTrackingProtection;
sourceTree = "<group>";
};
4B5C46212AF1B436002A4432 /* VPN */ = {
isa = PBXGroup;
children = (
4B5C46222AF1B4D4002A4432 /* VPNWaitlist.swift */,
);
name = VPN;
sourceTree = "<group>";
};
4B6484F427FD1E390050A7A1 /* Waitlist */ = {
isa = PBXGroup;
children = (
37FCAAAA29911BF1000E420A /* WaitlistExtensions.swift */,
56244C1C2A137B1900EDF259 /* WaitlistViews.swift */,
37FCAAA0299117F9000E420A /* MacBrowser */,
37FCAAA129911801000E420A /* WindowsBrowser */,
4B5C46212AF1B436002A4432 /* VPN */,
8524AAAB2A3888FE00EEC6D2 /* Waitlist.xcassets */,
);
name = Waitlist;
Expand Down Expand Up @@ -6327,6 +6338,7 @@
3132FA2C27A07A1B00DD7A12 /* FilePreview.swift in Sources */,
85C861E628FF1B5F00189466 /* HomeViewSectionRenderersExtension.swift in Sources */,
F1D477C61F2126CC0031ED49 /* OmniBarState.swift in Sources */,
4B5C46232AF1B4D4002A4432 /* VPNWaitlist.swift in Sources */,
85F2FFCD2211F615006BB258 /* MainViewController+KeyCommands.swift in Sources */,
0268FC132A449F04000EE6A2 /* OnboardingContainerView.swift in Sources */,
858650D9246B0D3C00C36F8A /* DaxOnboardingViewController.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
let identifier = response.notification.request.identifier
if identifier == WindowsBrowserWaitlist.notificationIdentitier {
if identifier == WindowsBrowserWaitlist.notificationIdentifier {
presentWindowsBrowserWaitlistSettingsModal()
}

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/MacBrowserWaitlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct MacBrowserWaitlist: Waitlist {

static let backgroundTaskName = "Mac Browser Waitlist Status Task"
static let backgroundRefreshTaskIdentifier = "com.duckduckgo.app.macBrowserWaitlistStatus"
static let notificationIdentitier = "com.duckduckgo.ios.mac-browser.invite-code-available"
static let notificationIdentifier = "com.duckduckgo.ios.mac-browser.invite-code-available"
static let inviteAvailableNotificationTitle = UserText.macWaitlistAvailableNotificationTitle
static let inviteAvailableNotificationBody = UserText.waitlistAvailableNotificationBody

Expand Down
96 changes: 96 additions & 0 deletions DuckDuckGo/VPNWaitlist.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// VPNWaitlist.swift
// DuckDuckGo
//
// 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 BrowserServicesKit
import Combine
import Core
import Waitlist

final class VPNWaitlist: Waitlist {

static let identifier: String = "vpn"
static let apiProductName: String = "networkprotection_ios"
static let downloadURL: URL = URL.windows

static let shared: VPNWaitlist = .init()

static let backgroundTaskName = "VPN Waitlist Status Task"
static let backgroundRefreshTaskIdentifier = "com.duckduckgo.app.vpnWaitlistStatus"
static let notificationIdentifier = "com.duckduckgo.ios.vpn.invite-code-available"
static let inviteAvailableNotificationTitle = UserText.windowsWaitlistAvailableNotificationTitle
static let inviteAvailableNotificationBody = UserText.waitlistAvailableNotificationBody

var isAvailable: Bool {
isFeatureEnabled
}

var isWaitlistRemoved: Bool {
return false
}

let waitlistStorage: WaitlistStorage
let waitlistRequest: WaitlistRequest

init(store: WaitlistStorage, request: WaitlistRequest,
privacyConfigurationManager: PrivacyConfigurationManaging = ContentBlocking.shared.privacyConfigurationManager) {
self.waitlistStorage = store
self.waitlistRequest = request

isFeatureEnabled = true // privacyConfigurationManager.privacyConfig.isEnabled(featureKey: .windowsWaitlist)

// isFeatureEnabledCancellable = privacyConfigurationManager.updatesPublisher
// .map { [weak privacyConfigurationManager] in
// privacyConfigurationManager?.privacyConfig.isEnabled(featureKey: .windowsWaitlist) == true
// }
// .receive(on: DispatchQueue.main)
// .assign(to: \.isFeatureEnabled, onWeaklyHeld: self)
//
// isWaitlistRemovedCancellable = privacyConfigurationManager.updatesPublisher
// .map { [weak privacyConfigurationManager] in
// privacyConfigurationManager?.privacyConfig.isEnabled(featureKey: .windowsDownloadLink) == true
// }
// .receive(on: DispatchQueue.main)
// .assign(to: \.isWaitlistRemoved, onWeaklyHeld: self)
}

convenience init(store: WaitlistStorage, request: WaitlistRequest) {
self.init(store: store, request: request, privacyConfigurationManager: ContentBlocking.shared.privacyConfigurationManager)
}

var settingsSubtitle: String {
if waitlistStorage.isInvited {
return "Invited"
}

if waitlistStorage.isOnWaitlist {
return "On waitlist"
}

return "Default text"
}

// MARK: -

private var isFeatureEnabled: Bool = false
private var modeCancellable: AnyCancellable?
private var isFeatureEnabledCancellable: AnyCancellable?
private var isWaitlistRemovedCancellable: AnyCancellable?

}
2 changes: 1 addition & 1 deletion DuckDuckGo/WindowsBrowserWaitlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class WindowsBrowserWaitlist: Waitlist {

static let backgroundTaskName = "Windows Browser Waitlist Status Task"
static let backgroundRefreshTaskIdentifier = "com.duckduckgo.app.windowsBrowserWaitlistStatus"
static let notificationIdentitier = "com.duckduckgo.ios.windows-browser.invite-code-available"
static let notificationIdentifier = "com.duckduckgo.ios.windows-browser.invite-code-available"
static let inviteAvailableNotificationTitle = UserText.windowsWaitlistAvailableNotificationTitle
static let inviteAvailableNotificationBody = UserText.waitlistAvailableNotificationBody

Expand Down
4 changes: 2 additions & 2 deletions LocalPackages/Waitlist/Sources/Waitlist/Waitlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public protocol WaitlistConstants {
static var backgroundRefreshTaskIdentifier: String { get }
static var minimumConfigurationRefreshInterval: TimeInterval { get }

static var notificationIdentitier: String { get }
static var notificationIdentifier: String { get }
static var inviteAvailableNotificationTitle: String { get }
static var inviteAvailableNotificationBody: String { get }
}
Expand Down Expand Up @@ -189,7 +189,7 @@ public extension Waitlist {
notificationContent.title = Self.inviteAvailableNotificationTitle
notificationContent.body = Self.inviteAvailableNotificationBody

let notificationIdentifier = Self.notificationIdentitier
let notificationIdentifier = Self.notificationIdentifier
let request = UNNotificationRequest(identifier: notificationIdentifier, content: notificationContent, trigger: nil)

UNUserNotificationCenter.current().add(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public struct TestWaitlist: Waitlist {
public static var backgroundTaskName: String = "BG Task"

public static var backgroundRefreshTaskIdentifier: String = "bgtask"
public static var notificationIdentitier: String = "notification"
public static var notificationIdentifier: String = "notification"
public static var inviteAvailableNotificationTitle: String = "Title"
public static var inviteAvailableNotificationBody: String = "Body"
}

0 comments on commit 58f3cf5

Please sign in to comment.