Skip to content

Commit

Permalink
Add View for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandroboron committed Dec 17, 2024
1 parent f4eaebe commit 91a047a
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 11 deletions.
4 changes: 4 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@
9F06EB7D2D0AEBD000905426 /* MaliciousSiteProtectionManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB7C2D0AEBD000905426 /* MaliciousSiteProtectionManagerTests.swift */; };
9F06EB822D0AEE1F00905426 /* MaliciousSiteProtectionMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB802D0AEE1F00905426 /* MaliciousSiteProtectionMocks.swift */; };
9F06EB872D0C733B00905426 /* MaliciousSiteProtectionPreferencesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB862D0C733900905426 /* MaliciousSiteProtectionPreferencesManager.swift */; };
9F06EB8A2D10560200905426 /* SettingsMaliciousSiteProtectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB892D10560200905426 /* SettingsMaliciousSiteProtectionView.swift */; };
9F06EB8C2D10578000905426 /* MaliciousSiteProtectionSettingsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB8B2D10578000905426 /* MaliciousSiteProtectionSettingsViewModelTests.swift */; };
9F06EB922D10740500905426 /* MaliciousSiteProtectionPreferencesManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB912D10740500905426 /* MaliciousSiteProtectionPreferencesManagerTests.swift */; };
9F16230B2CA0F0190093C4FC /* DebouncerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F16230A2CA0F0190093C4FC /* DebouncerTests.swift */; };
Expand Down Expand Up @@ -2630,6 +2631,7 @@
9F06EB7C2D0AEBD000905426 /* MaliciousSiteProtectionManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionManagerTests.swift; sourceTree = "<group>"; };
9F06EB802D0AEE1F00905426 /* MaliciousSiteProtectionMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionMocks.swift; sourceTree = "<group>"; };
9F06EB862D0C733900905426 /* MaliciousSiteProtectionPreferencesManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionPreferencesManager.swift; sourceTree = "<group>"; };
9F06EB892D10560200905426 /* SettingsMaliciousSiteProtectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsMaliciousSiteProtectionView.swift; sourceTree = "<group>"; };
9F06EB8B2D10578000905426 /* MaliciousSiteProtectionSettingsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionSettingsViewModelTests.swift; sourceTree = "<group>"; };
9F06EB912D10740500905426 /* MaliciousSiteProtectionPreferencesManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionPreferencesManagerTests.swift; sourceTree = "<group>"; };
9F16230A2CA0F0190093C4FC /* DebouncerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebouncerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3419,6 +3421,7 @@
1DEAADED2BA45DFE00E25A97 /* SettingsDataClearingView.swift */,
D65625A02C232F5E006EF297 /* SettingsDuckPlayerView.swift */,
317CA3422CFF82DB00F88848 /* SettingsAIChatView.swift */,
9F06EB892D10560200905426 /* SettingsMaliciousSiteProtectionView.swift */,
);
name = MainSettings;
sourceTree = "<group>";
Expand Down Expand Up @@ -8335,6 +8338,7 @@
9FCFCD852C75C91A006EB7A0 /* ProgressBarView.swift in Sources */,
6F3537A42C4AC140009F8717 /* NewTabPageDaxLogoView.swift in Sources */,
314C92B827C3DD660042EC96 /* QuickLookPreviewView.swift in Sources */,
9F06EB8A2D10560200905426 /* SettingsMaliciousSiteProtectionView.swift in Sources */,
6F5345AF2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift in Sources */,
F1AE54E81F0425FC00D9A700 /* AuthenticationViewController.swift in Sources */,
560E990F2BEE2CB800507CE0 /* SyncErrorMessage.swift in Sources */,
Expand Down
12 changes: 1 addition & 11 deletions DuckDuckGo/SettingsGeneralView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,7 @@ struct SettingsGeneralView: View {
accessory: .toggle(isOn: viewModel.universalLinksBinding))
}

if viewModel.threatDetectionSettingsViewModel.shouldShowMaliciousSiteProtectionSection {
Section(
header: Text(verbatim: "Malicious Site Protection"),
footer: Text(verbatim: "Disabling this feature can put your personal information at risk. ")
.foregroundColor(.red)
) {
SettingsCellView(label: "Warn me when a webpage may be malicious or fraudulent",
accessory: .toggle(isOn: viewModel.threatDetectionSettingsViewModel.threatDetectionBinding))
}
}

SettingsMaliciousProtectionView()

}
.applySettingsListModifiers(title: UserText.general,
Expand Down
56 changes: 56 additions & 0 deletions DuckDuckGo/SettingsMaliciousSiteProtectionView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// SettingsMaliciousSiteProtectionView.swift
// DuckDuckGo
//
// Copyright © 2024 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 SwiftUI
import DuckUI

struct SettingsMaliciousProtectionView: View {
@StateObject private var maliciousSiteProtectionSettingsModel = MaliciousSiteProtectionSettingsViewModel()

var body: some View {
if maliciousSiteProtectionSettingsModel.shouldShowMaliciousSiteProtectionSection {
Section(
header: Text(UserText.MaliciousSiteProtectionSettings.header),
footer:
VStack(alignment: .leading, spacing: 10) {
Button(action: maliciousSiteProtectionSettingsModel.learnMoreAction) {
Text(UserText.MaliciousSiteProtectionSettings.footerLearnMore)
.foregroundColor(.blueBase)
}

Text(UserText.MaliciousSiteProtectionSettings.footerDisabledMessage)
.opacity(maliciousSiteProtectionSettingsModel.maliciousSiteProtectionBinding.wrappedValue ? 0 : 1)
.foregroundColor(.red)
.font(.footnote)
}
) {
SettingsCellView(
label: UserText.MaliciousSiteProtectionSettings.toggleMessage,
accessory: .toggle(isOn: maliciousSiteProtectionSettingsModel.maliciousSiteProtectionBinding)
)
}
} else {
EmptyView()
}
}
}

#Preview {
SettingsMaliciousProtectionView()
}
7 changes: 7 additions & 0 deletions DuckDuckGo/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,13 @@ AI Chat is an optional feature available at [duck.ai](ddgquicklink://duck.ai) th

public static let aiChatSettingsEnableAddressBarToggle = NSLocalizedString("aichat.settings.enable.address-bar-toggle", value: "Show AI Chat While Searching", comment: "Toggle text to enable/disable AI Chat in the address bar")

public enum MaliciousSiteProtectionSettings {
public static let header = NSLocalizedString("malicious-site-protection.settings.header", value: "Malicious Site Protection", comment: "Header text for Malicious Site Protection settings")
public static let toggleMessage = NSLocalizedString("malicious-site-protection.settings.toggle.message", value: "Warn me on sites flagged for phishing or malware", comment: "Text explaining what happens when Malicious Site Protection is enabled")
public static let footerLearnMore = NSLocalizedString("malicious-site-protection.settings.footer.button.learn-more", value: "Learn More", comment: "Button that redirect the user to a web page explaining what Malicious Site Protection is")
public static let footerDisabledMessage = NSLocalizedString("malicious-site-protection.settings.footer.message", value: "Disabling this feature can put your personal information at risk.", comment: "Footer text for Malicious Site Protection settings warning the user about the risks of disabling the feature")
}

// MARK: - New Tab Page

// MARK: Shortcuts
Expand Down
12 changes: 12 additions & 0 deletions DuckDuckGo/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,18 @@ https://duckduckgo.com/mac";
/* Title for the Mac Waitlist feature */
"mac-waitlist.title" = "DuckDuckGo App for Mac";

/* Button that redirect the user to a web page explaining what Malicious Site Protection is */
"malicious-site-protection.settings.footer.button.learn-more" = "Learn More";

/* Footer text for Malicious Site Protection settings warning the user about the risks of disabling the feature */
"malicious-site-protection.settings.footer.message" = "Disabling this feature can put your personal information at risk.";

/* Header text for Malicious Site Protection settings */
"malicious-site-protection.settings.header" = "Malicious Site Protection";

/* Text explaining what happens when Malicious Site Protection is enabled */
"malicious-site-protection.settings.toggle.message" = "Warn me on sites flagged for phishing or malware";

/* No comment provided by engineer. */
"menu.button.hint" = "Browsing Menu";

Expand Down

0 comments on commit 91a047a

Please sign in to comment.