Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions wBlock/AppFilterManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ class AppFilterManager: ObservableObject {
}

let ruleCountForThisTarget = conversionResult.safariRulesCount
overallSafariRulesApplied += ruleCountForThisTarget

// Collect advanced rules for later engine building
if let advancedRulesText = conversionResult.advancedRulesText, !advancedRulesText.isEmpty {
Expand Down Expand Up @@ -647,14 +646,16 @@ class AppFilterManager: ObservableObject {
if ruleCountForThisTarget > ruleLimit {
await ConcurrentLogManager.shared.log("CRITICAL: Rule limit \(ruleLimit) exceeded for \(targetInfo.bundleIdentifier) with \(ruleCountForThisTarget) rules.")

// Auto-reset this specific category instead of showing global alert
// Auto-reset this specific category and warn the user
await resetCategoryToRecommended(targetInfo.primaryCategory)
if let secondaryCategory = targetInfo.secondaryCategory {
await resetCategoryToRecommended(secondaryCategory)
}

// Show category warning alert to inform user about the rule limit exceeded
await MainActor.run {
self.statusDescription = "Auto-reset \(targetInfo.primaryCategory.rawValue) filters due to rule limit exceeded (\(ruleCountForThisTarget)/\(ruleLimit)). Continuing with other categories..."
self.showCategoryWarning(for: targetInfo.primaryCategory)
// self.statusDescription = "Auto-reset \(targetInfo.primaryCategory.rawValue) filters due to rule limit exceeded (\(ruleCountForThisTarget)/\(ruleLimit)). Continuing with other categories..."
}
await ConcurrentLogManager.shared.log("Auto-reset category \(targetInfo.primaryCategory.rawValue) due to rule limit exceeded.")

Expand All @@ -663,7 +664,10 @@ class AppFilterManager: ObservableObject {
let containerURL = await MainActor.run { self.loader.getSharedContainerURL() }
var resetRulesString = ""

for filter in allSelectedFilters {
// FIX: Get the updated filter list after reset instead of using the old allSelectedFilters
let updatedSelectedFilters = await MainActor.run { self.filterLists.filter { $0.isSelected } }

for filter in updatedSelectedFilters {
if filter.isSelected && (filter.category == targetInfo.primaryCategory ||
(targetInfo.secondaryCategory != nil && filter.category == targetInfo.secondaryCategory!)) {
guard let containerURL = containerURL else { continue }
Expand Down Expand Up @@ -720,6 +724,9 @@ class AppFilterManager: ObservableObject {
await ConcurrentLogManager.shared.log("🔄 After reset, \(targetInfo.primaryCategory.rawValue) now has \(resetRuleCount) rules")
continue
}
else {
overallSafariRulesApplied += ruleCountForThisTarget
}
}
await MainActor.run {
self.isInConversionPhase = false
Expand Down
8 changes: 6 additions & 2 deletions wBlock/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ struct ContentView: View {
}
// Show the last applied rule count, falling back to source count if no prior apply
private var displayedRuleCount: Int {
max(filterManager.lastRuleCount, sourceRulesCount)
if (filterManager.lastRuleCount > 0) {
return filterManager.lastRuleCount
} else {
return sourceRulesCount
}
}

private var displayableCategories: [FilterListCategory] {
Expand Down Expand Up @@ -321,7 +325,7 @@ struct ContentView: View {
valueColor: .primary
)
StatCard(
title: "Filter Rules",
title: "Applied Rules",
value: displayedRuleCount.formatted(),
icon: "shield.lefthalf.filled",
pillColor: .clear,
Expand Down