-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NetP iOS notifications settings (#541)
* 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
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
65 changes: 65 additions & 0 deletions
65
.../Status/UserNotifications/NetworkProtectionNotificationsPresenterTogglableDecorator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Sources/NetworkProtection/Storage/NetworkProtectionNotificationsSettingsStore.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../NetworkProtectionTestUtils/Storage/MockNetworkProtectionNotificationsSettingsStore.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |