Skip to content

Commit

Permalink
Fixes unit tests and a warning
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoreymendez committed Mar 22, 2024
1 parent c117a41 commit 2af7457
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 67 deletions.
14 changes: 0 additions & 14 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2318,8 +2318,6 @@
7BEEA5162AD1236E00A9E72B /* NetworkProtectionUI in Frameworks */ = {isa = PBXBuildFile; productRef = 7BEEA5152AD1236E00A9E72B /* NetworkProtectionUI */; };
7BF6557D2BADA45E00F37667 /* NetworkProtectionSubscription in Frameworks */ = {isa = PBXBuildFile; productRef = 7BF6557C2BADA45E00F37667 /* NetworkProtectionSubscription */; };
7BF6557F2BADA46600F37667 /* NetworkProtectionSubscription in Frameworks */ = {isa = PBXBuildFile; productRef = 7BF6557E2BADA46600F37667 /* NetworkProtectionSubscription */; };
7BF655822BADA54600F37667 /* ConvenienceInitializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BF655812BADA54600F37667 /* ConvenienceInitializers.swift */; };
7BF655832BADA5E400F37667 /* ConvenienceInitializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BF655812BADA54600F37667 /* ConvenienceInitializers.swift */; };
7BFCB74E2ADE7E1A00DA3EA7 /* PixelKit in Frameworks */ = {isa = PBXBuildFile; productRef = 7BFCB74D2ADE7E1A00DA3EA7 /* PixelKit */; };
7BFCB7502ADE7E2300DA3EA7 /* PixelKit in Frameworks */ = {isa = PBXBuildFile; productRef = 7BFCB74F2ADE7E2300DA3EA7 /* PixelKit */; };
7BFE95522A9DF1CE0081ABE9 /* NetworkProtectionWaitlistFeatureFlagOverridesMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BFE95512A9DF1CE0081ABE9 /* NetworkProtectionWaitlistFeatureFlagOverridesMenu.swift */; };
Expand Down Expand Up @@ -4021,7 +4019,6 @@
7BEC20402B0F505F00243D3E /* AddBookmarkPopoverView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddBookmarkPopoverView.swift; sourceTree = "<group>"; };
7BEC20412B0F505F00243D3E /* AddBookmarkFolderPopoverView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddBookmarkFolderPopoverView.swift; sourceTree = "<group>"; };
7BF1A9D72AE054D300FCA683 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7BF655812BADA54600F37667 /* ConvenienceInitializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvenienceInitializers.swift; sourceTree = "<group>"; };
7BFE95512A9DF1CE0081ABE9 /* NetworkProtectionWaitlistFeatureFlagOverridesMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionWaitlistFeatureFlagOverridesMenu.swift; sourceTree = "<group>"; };
7BFE95532A9DF2930081ABE9 /* UserDefaults+NetworkProtectionWaitlist.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UserDefaults+NetworkProtectionWaitlist.swift"; sourceTree = "<group>"; };
85012B0129133F9F003D0DCC /* NavigationBarPopovers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBarPopovers.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6442,7 +6439,6 @@
7BA7CC0D2AD11DC80042E5CE /* DuckDuckGoVPN */ = {
isa = PBXGroup;
children = (
7BF655802BADA53000F37667 /* ConvenienceInitializers */,
7BA7CC132AD11DC80042E5CE /* AppLauncher+DefaultInitializer.swift */,
7BA7CC0E2AD11DC80042E5CE /* DuckDuckGoVPNAppDelegate.swift */,
7BD1688D2AD4A4C400D24876 /* NetworkExtensionController.swift */,
Expand Down Expand Up @@ -6489,14 +6485,6 @@
path = VPNProxyExtension;
sourceTree = "<group>";
};
7BF655802BADA53000F37667 /* ConvenienceInitializers */ = {
isa = PBXGroup;
children = (
7BF655812BADA54600F37667 /* ConvenienceInitializers.swift */,
);
path = ConvenienceInitializers;
sourceTree = "<group>";
};
853014D425E6709500FB8205 /* Support */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -11148,7 +11136,6 @@
7BA7CC592AD1203B0042E5CE /* UserText+NetworkProtection.swift in Sources */,
EEDE50112BA360C80017F3C4 /* NetworkProtection+VPNAgentConvenienceInitializers.swift in Sources */,
7BA7CC562AD11FFB0042E5CE /* NetworkProtectionOptionKeyExtension.swift in Sources */,
7BF655822BADA54600F37667 /* ConvenienceInitializers.swift in Sources */,
7B2DDCFA2A93B25F0039D884 /* KeychainType+ClientDefault.swift in Sources */,
7BA7CC4C2AD11EC70042E5CE /* NetworkProtectionControllerErrorStore.swift in Sources */,
B6F92BAC2A6937B3002ABA6B /* OptionalExtension.swift in Sources */,
Expand Down Expand Up @@ -11184,7 +11171,6 @@
7B1459552B7D438F00047F2C /* VPNProxyLauncher.swift in Sources */,
EEDE50122BA360C80017F3C4 /* NetworkProtection+VPNAgentConvenienceInitializers.swift in Sources */,
B6F92BAD2A6937B5002ABA6B /* OptionalExtension.swift in Sources */,
7BF655832BADA5E400F37667 /* ConvenienceInitializers.swift in Sources */,
4BA7C4D92B3F61FB00AFE511 /* BundleExtension.swift in Sources */,
EEC589DC2A4F1CE800BCD60C /* AppLauncher.swift in Sources */,
7BA7CC3F2AD11E3D0042E5CE /* AppLauncher+DefaultInitializer.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,4 @@ extension NetworkProtectionLocationListCompositeRepository {
}
}

extension VPNSubscriptionStatusObserver {
convenience init() {
self.init(accountManager: AccountManager())
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager {
let subscriptionStatusObserver = VPNSubscriptionStatusObserver()

let popover = NetworkProtectionPopover(controller: controller,
showSubscriptionExpired: subscriptionStatusObserver.$showSubscriptionExpired,
showSubscriptionExpired: subscriptionStatusObserver.showSubscriptionExpired,
onboardingStatusPublisher: onboardingStatusPublisher,
statusReporter: statusReporter,
appLauncher: appLauncher,
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Preferences/Model/PreferencesSidebarModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ final class PreferencesSidebarModel: ObservableObject {
}
.store(in: &cancellables)

VPNSubscriptionStatusObserver().$showSubscriptionExpired.sink { expired in
VPNSubscriptionStatusObserver().showSubscriptionExpired.sink { expired in
if expired && self.selectedPane == .vpn {
self.selectedPane = .general
}
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions DuckDuckGoVPN/DuckDuckGoVPNAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ final class DuckDuckGoVPNAppDelegate: NSObject, NSApplicationDelegate {

return StatusBarMenu(
model: model,
showSubscriptionExpired: subscriptionStatusObserver.$showSubscriptionExpired,
showSubscriptionExpired: subscriptionStatusObserver.showSubscriptionExpired,
onboardingStatusPublisher: onboardingStatusPublisher,
statusReporter: statusReporter,
controller: tunnelController,
Expand Down Expand Up @@ -360,7 +360,7 @@ final class DuckDuckGoVPNAppDelegate: NSObject, NSApplicationDelegate {

private func setUpSubscriptionMonitoring() {
#if SUBSCRIPTION
subscriptionStatusObserver.$showSubscriptionExpired.sink { expired in
subscriptionStatusObserver.showSubscriptionExpired.sink { expired in
guard expired else {
return
}
Expand Down
3 changes: 0 additions & 3 deletions LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ let package = Package(
dependencies: [
.product(name: "Subscription", package: "BrowserServicesKit"),
],
resources: [
.copy("Resources/Assets.xcassets")
],
swiftSettings: [
.define("DEBUG", .when(configuration: .debug))
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ import Subscription

public final class VPNSubscriptionStatusObserver {

private let accountManager: AccountManager
public var showSubscriptionExpired: AnyPublisher<Bool, Never> {
publisher.eraseToAnyPublisher()
}

@Published
public var showSubscriptionExpired = false
private let publisher = CurrentValueSubject<Bool, Never>(false)
private var cancellables = Set<AnyCancellable>()

public init(accountManager: AccountManager,
notificationCenter: NotificationCenter = .default) {

self.accountManager = accountManager

public init(notificationCenter: NotificationCenter = .default) {
subscribeToEntitlementChangeNotifications(through: notificationCenter)
}

Expand All @@ -45,7 +42,7 @@ public final class VPNSubscriptionStatusObserver {
return
}

self.showSubscriptionExpired = !entitlements.contains { entitlement in
publisher.value = !entitlements.contains { entitlement in
entitlement.product == .networkProtection
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class StatusBarMenu: NSObject {
@MainActor
public init(model: StatusBarMenuModel,
statusItem: NSStatusItem? = nil,
showSubscriptionExpired: Published<Bool>.Publisher,
showSubscriptionExpired: AnyPublisher<Bool, Never>,
onboardingStatusPublisher: OnboardingStatusPublisher,
statusReporter: NetworkProtectionStatusReporter,
controller: TunnelController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class NetworkProtectionPopover: NSPopover {
private var appLifecycleCancellable: AnyCancellable?

public required init(controller: TunnelController,
showSubscriptionExpired: Published<Bool>.Publisher,
showSubscriptionExpired: AnyPublisher<Bool, Never>,
onboardingStatusPublisher: OnboardingStatusPublisher,
statusReporter: NetworkProtectionStatusReporter,
appLauncher: AppLaunching,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ extension NetworkProtectionStatusView {
// MARK: - Initialization & Deinitialization

public init(controller: TunnelController,
showSubscriptionExpired: Published<Bool>.Publisher,
showSubscriptionExpired: AnyPublisher<Bool, Never>,
onboardingStatusPublisher: OnboardingStatusPublisher,
statusReporter: NetworkProtectionStatusReporter,
debugInformationPublisher: AnyPublisher<Bool, Never>,
Expand Down Expand Up @@ -189,7 +189,7 @@ extension NetworkProtectionStatusView {
}
}

private func subscribeToShowSubscriptionExpired(_ publisher: Published<Bool>.Publisher) {
private func subscribeToShowSubscriptionExpired(_ publisher: AnyPublisher<Bool, Never>) {
publisher.receive(on: DispatchQueue.main)
.assign(to: \.showSubscriptionExpired, onWeaklyHeld: self)
.store(in: &cancellables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ final class StatusBarMenuTests: XCTestCase {
let menu = StatusBarMenu(
model: model,
statusItem: item,
showSubscriptionExpired: Just(false).eraseToAnyPublisher(),
onboardingStatusPublisher: Just(OnboardingStatus.completed).eraseToAnyPublisher(),
statusReporter: MockNetworkProtectionStatusReporter(),
controller: TestTunnelController(),
Expand All @@ -74,6 +75,7 @@ final class StatusBarMenuTests: XCTestCase {
let menu = StatusBarMenu(
model: model,
statusItem: item,
showSubscriptionExpired: Just(false).eraseToAnyPublisher(),
onboardingStatusPublisher: Just(OnboardingStatus.completed).eraseToAnyPublisher(),
statusReporter: MockNetworkProtectionStatusReporter(),
controller: TestTunnelController(),
Expand Down

0 comments on commit 2af7457

Please sign in to comment.