Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #6011: Suppress 'switch to app' annoyances by default. (#6054)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub authored Sep 28, 2022
1 parent a86f04b commit 3f59b86
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class BraveShieldsAndPrivacySettingsController: TableViewController {
}
}),
.boolRow(title: Strings.fingerprintingProtection, detailText: Strings.fingerprintingProtectionDescription, option: Preferences.Shields.fingerprintingProtection),

Row(
text: Strings.contentFiltering,
detailText: Strings.contentFilteringDescription,
Expand All @@ -119,12 +118,27 @@ class BraveShieldsAndPrivacySettingsController: TableViewController {
self?.navigationController?.pushViewController(controller, animated: true)
},
accessory: .disclosureIndicator, cellClass: MultilineSubtitleCell.self, uuid: "content-filtering"
)
),
],
footer: .title(Strings.shieldsDefaultsFooter)
)
return shields
}()

private var blockMobileAnnoyancesRow: Row {
let mobileAnnoyancesComponentID = FilterList.mobileAnnoyancesComponentID
let filterListDownloader = FilterListResourceDownloader.shared

return Row(
text: Strings.blockMobileAnnoyances,
accessory:
.view(SwitchAccessoryView(
initialValue: filterListDownloader.isEnabled(for: mobileAnnoyancesComponentID),
valueChange: { value in
FilterListResourceDownloader.shared.enableFilterList(for: mobileAnnoyancesComponentID, isEnabled: value)
})), cellClass: MultilineSubtitleCell.self, uuid: "blockMobileAnnoyances"
)
}

private lazy var toggles: [Bool] = {
let savedToggles = Preferences.Privacy.clearPrivateDataToggles.value
Expand Down Expand Up @@ -221,6 +235,7 @@ class BraveShieldsAndPrivacySettingsController: TableViewController {
}
),
.boolRow(title: Strings.blockPopups, option: Preferences.General.blockPopups),
blockMobileAnnoyancesRow,
.boolRow(title: Strings.followUniversalLinks, option: Preferences.General.followUniversalLinks),
]
)
Expand Down
5 changes: 0 additions & 5 deletions Client/Frontend/Settings/FilterListsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ struct FilterListsView: View {

}.navigationTitle(Strings.filterLists)
}

/// Get an index for the given filter list.
func getIndex(for filterList: FilterList) -> Int? {
return downloader.filterLists.firstIndex(where: { $0.id == filterList.id })
}
}

#if DEBUG
Expand Down
2 changes: 2 additions & 0 deletions Client/WebFilters/FilterList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ struct FilterList: Decodable, Identifiable {
case uuid, title, componentId, description = "desc", urlString = "url"
}

public static let mobileAnnoyancesComponentID = "ldbgldhcahahpffloggbbmjllggnkenk"

let uuid: String
let title: String
let description: String
Expand Down
35 changes: 34 additions & 1 deletion Client/WebFilters/FilterListResourceDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class FilterListResourceDownloader: ObservableObject {
return allFilterListSettings.first(where: { $0.uuid == uuid })?.isEnabled ?? false
}

/// - Warning: Do not call this before we load core data
public func isEnabled(for componentID: String) -> Bool {
return allFilterListSettings.first(where: { $0.componentId == componentID })?.isEnabled ?? false
}

/// Set the enabled status of a filter list setting
/// Otherwise it will create a new setting with the specified properties
///
Expand Down Expand Up @@ -217,11 +222,28 @@ public class FilterListResourceDownloader: ObservableObject {
}
}

/// Enables a filter list for the given component ID. Returns true if the filter list exists or not.
@discardableResult
public func enableFilterList(for componentID: String, isEnabled: Bool) -> Bool {
// Enable the setting
if let index = filterLists.firstIndex(where: { $0.componentId == componentID }) {
filterLists[index].isEnabled = isEnabled
return true
} else {
return false
}
}

/// Tells us if the filter list is enabled for the given `UUID`
@MainActor public func isEnabled(filterListUUID uuid: String) -> Bool {
return settingsManager.isEnabled(forUUID: uuid)
}

/// Tells us if the filter list is enabled for the given `componentID`
@MainActor public func isEnabled(for componentID: String) -> Bool {
return settingsManager.isEnabled(for: componentID)
}

/// Invoked when shield components are loaded
///
/// This function will start fetching data and subscribe publishers once if it hasn't already done so.
Expand Down Expand Up @@ -265,11 +287,22 @@ public class FilterListResourceDownloader: ObservableObject {
)
}

/// This method allows us to enable selected lists by default for new users.
/// Make sure you use componentID to identify the filter list, as `uuid` will be deprecated in the future.
private func newFilterListEnabledOverride(for componentId: String) -> Bool? {
let componentIDsToOverride = [FilterList.mobileAnnoyancesComponentID]

return componentIDsToOverride.contains(componentId) ? true : nil
}

/// Load filter lists from the ad block service
private func loadFilterLists(from regionalFilterLists: [AdblockFilterList], filterListSettings: [FilterListSetting]) -> [FilterList] {
return regionalFilterLists.map { adBlockFilterList in
let setting = filterListSettings.first(where: { $0.uuid == adBlockFilterList.uuid })
return FilterList(from: adBlockFilterList, isEnabled: setting?.isEnabled ?? false)
return FilterList(from: adBlockFilterList,
isEnabled: setting?.isEnabled
?? newFilterListEnabledOverride(for: adBlockFilterList.componentId)
?? false)
}
}

Expand Down
1 change: 1 addition & 0 deletions Sources/BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ extension Strings {
public static let googleSafeBrowsing = NSLocalizedString("GoogleSafeBrowsing", tableName: "BraveShared", bundle: .strings, value: "Block dangerous sites", comment: "")
public static let googleSafeBrowsingUsingWebKitDescription = NSLocalizedString("GoogleSafeBrowsingUsingWebKitDescription", tableName: "BraveShared", bundle: .strings, value: "Sends obfuscated URLs of some pages you visit to the Google Safe Browsing service, when your security is at risk.", comment: "")
public static let contentFiltering = NSLocalizedString("ContentFiltering", tableName: "BraveShared", bundle: .strings, value: "Content Filtering", comment: "A title to the content filtering page under global shield settings and the title on the Content filtering page")
public static let blockMobileAnnoyances = NSLocalizedString("blockMobileAnnoyances", tableName: "BraveShared", bundle: .strings, value: "Block 'Switch to App' Notices", comment: "A title for setting which blocks 'switch to app' popups")
public static let contentFilteringDescription = NSLocalizedString("ContentFilteringDescription", tableName: "BraveShared", bundle: .strings, value: "Enable custom filters that block regional and language-specific trackers and Annoyances", comment: "A description of the content filtering page.")
public static let filterLists = NSLocalizedString("FilterLists", tableName: "BraveShared", bundle: .strings, value: "Filter Lists", comment: "A title on the content filtering screen that allows you to enable/disable filter lists")
public static let filterListsDescription = NSLocalizedString("FilterListsDescription", tableName: "BraveShared", bundle: .strings, value: "Additional popular community lists. Note that enabling too many filters will degrade browsing speeds.", comment: "A description on the content filtering screen for the filter lists section.")
Expand Down

0 comments on commit 3f59b86

Please sign in to comment.