Skip to content

Commit

Permalink
NetP iOS notifications settings (#541)
Browse files Browse the repository at this point in the history
* Add helpers for toggling netP notifications

* Extract a protocol for the settings store

* Add MockNetworkProtectionNotificationsSettingsStore

* Update Sources/NetworkProtection/Storage/NetworkProtectionNotificationsSettingsStore.swift

Co-authored-by: Sam Symons <[email protected]>

* Remove dead property

---------

Co-authored-by: Sam Symons <[email protected]>
  • Loading branch information
graeme and samsymons authored Oct 31, 2023
1 parent 8768193 commit 71e916d
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// NetworkProtectionNotificationsPresenterTogglableDecorator.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

final public class NetworkProtectionNotificationsPresenterTogglableDecorator: NetworkProtectionNotificationsPresenter {
private let notificationSettingsStore: NetworkProtectionNotificationsSettingsStore
private let wrappeePresenter: NetworkProtectionNotificationsPresenter

public init(notificationSettingsStore: NetworkProtectionNotificationsSettingsStore, wrappee: NetworkProtectionNotificationsPresenter) {
self.notificationSettingsStore = notificationSettingsStore
self.wrappeePresenter = wrappee
}

public func showConnectedNotification(serverLocation: String?) {
guard notificationSettingsStore.alertsEnabled else {
return
}
wrappeePresenter.showConnectedNotification(serverLocation: serverLocation)
}

public func showReconnectingNotification() {
guard notificationSettingsStore.alertsEnabled else {
return
}
wrappeePresenter.showReconnectingNotification()
}

public func showConnectionFailureNotification() {
guard notificationSettingsStore.alertsEnabled else {
return
}
wrappeePresenter.showConnectionFailureNotification()
}

public func showSupersededNotification() {
guard notificationSettingsStore.alertsEnabled else {
return
}
wrappeePresenter.showSupersededNotification()
}

public func showTestNotification() {
guard notificationSettingsStore.alertsEnabled else {
return
}
wrappeePresenter.showTestNotification()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// NetworkProtectionNotificationsSettingsStore.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

public protocol NetworkProtectionNotificationsSettingsStore {
var alertsEnabled: Bool { get set }
}

final public class NetworkProtectionNotificationsSettingsUserDefaultsStore: NetworkProtectionNotificationsSettingsStore {
private enum Key {
static let alerts = "com.duckduckgo.vpnNotificationSettings.alertsEnabled"
}

private let userDefaults: UserDefaults

public init(userDefaults: UserDefaults) {
self.userDefaults = userDefaults
}

public var alertsEnabled: Bool {
get {
guard self.userDefaults.object(forKey: Key.alerts) != nil else {
return true
}
return self.userDefaults.bool(forKey: Key.alerts)
}
set {
self.userDefaults.set(newValue, forKey: Key.alerts)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// MockNetworkProtectionNotificationsSettingsStore.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 NetworkProtection

public class MockNetworkProtectionNotificationsSettingsStore: NetworkProtectionNotificationsSettingsStore {
public var alertsEnabled: Bool = false
}

0 comments on commit 71e916d

Please sign in to comment.