-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add toggling of NetP Notifications to iOS (#2112)
Co-authored-by: Sam Symons <[email protected]>
- Loading branch information
Showing
15 changed files
with
412 additions
and
7 deletions.
There are no files selected for viewing
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,34 @@ | ||
// | ||
// UserDefaults+NetworkProtection.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. | ||
// | ||
|
||
#if NETWORK_PROTECTION | ||
|
||
import Foundation | ||
|
||
public extension UserDefaults { | ||
static var networkProtectionGroupDefaults: UserDefaults { | ||
let suiteName = "\(Global.groupIdPrefix).netp" | ||
guard let defaults = UserDefaults(suiteName: suiteName) else { | ||
fatalError("Failed to create netP UserDefaults") | ||
} | ||
return defaults | ||
} | ||
} | ||
|
||
#endif |
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
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
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
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
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
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
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,90 @@ | ||
// | ||
// NetworkProtectionVPNNotificationsView.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. | ||
// | ||
|
||
#if NETWORK_PROTECTION | ||
|
||
import SwiftUI | ||
import UIKit | ||
import NetworkProtection | ||
import Core | ||
|
||
@available(iOS 15, *) | ||
struct NetworkProtectionVPNNotificationsView: View { | ||
@StateObject var model = NetworkProtectionVPNNotificationsViewModel() | ||
|
||
var body: some View { | ||
List { | ||
switch model.viewKind { | ||
case .loading: | ||
EmptyView() | ||
case .unauthorized: | ||
unauthorizedView | ||
case .authorized: | ||
authorizedView | ||
} | ||
} | ||
.animation(.default, value: model.viewKind) | ||
.applyInsetGroupedListStyle() | ||
.navigationTitle(UserText.netPVPNNotificationsTitle).onAppear { | ||
Task { | ||
await model.onViewAppeared() | ||
} | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
private var unauthorizedView: some View { | ||
Section { | ||
Button(UserText.netPTurnOnNotificationsButtonTitle) { | ||
model.turnOnNotifications() | ||
} | ||
.foregroundColor(.controlColor) | ||
} footer: { | ||
Text(UserText.netPTurnOnNotificationsSectionFooter) | ||
.foregroundColor(.textSecondary) | ||
.font(.system(size: 13)) | ||
.padding(.top, 6) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
private var authorizedView: some View { | ||
Section { | ||
Toggle(UserText.netPVPNAlertsToggleTitle, isOn: Binding( | ||
get: { model.alertsEnabled }, | ||
set: model.didToggleAlerts(to:) | ||
)) | ||
.toggleStyle(SwitchToggleStyle(tint: .controlColor)) | ||
} footer: { | ||
Text(UserText.netPVPNAlertsToggleSectionFooter) | ||
.foregroundColor(.textSecondary) | ||
.font(.system(size: 13)) | ||
.padding(.top, 6) | ||
} | ||
} | ||
} | ||
|
||
private extension Color { | ||
static let textPrimary = Color(designSystemColor: .textPrimary) | ||
static let textSecondary = Color(designSystemColor: .textSecondary) | ||
static let cellBackground = Color(designSystemColor: .surface) | ||
static let controlColor = Color(designSystemColor: .accent) | ||
} | ||
|
||
#endif |
Oops, something went wrong.