From ae6635a89b5bb792d03c9f49f22552627a3146a2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 14 Aug 2026 09:10:16 +0000 Subject: [PATCH] feat: setting to hide currently blocked apps Adds a 'Hide Blocked Apps' toggle in General settings. When enabled, the Status screen omits apps, websites, categories and custom domains that are currently blocked, and shows a count of what was hidden instead. --- Normal/Models/Settings.swift | 1 + Normal/Views/Home/BlockedItemVisibility.swift | 18 ++++++ Normal/Views/Home/StatusDetailView.swift | 60 ++++++++++++++++--- .../Views/Settings/GeneralSettingsView.swift | 8 ++- NormalTests/Models/SettingsTests.swift | 1 + .../Views/BlockedItemVisibilityTests.swift | 55 +++++++++++++++++ 6 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 Normal/Views/Home/BlockedItemVisibility.swift create mode 100644 NormalTests/Views/BlockedItemVisibilityTests.swift diff --git a/Normal/Models/Settings.swift b/Normal/Models/Settings.swift index b517fd0..652726f 100644 --- a/Normal/Models/Settings.swift +++ b/Normal/Models/Settings.swift @@ -12,6 +12,7 @@ final class Settings { var blockAllPreventsAppDelete: Bool = true var defaultTab: AppTab? var hideDonateButton: Bool = false + var hideBlockedApps: Bool = false var showTimedUnblockLiveActivity: Bool = false var enableCustomDomains: Bool = false diff --git a/Normal/Views/Home/BlockedItemVisibility.swift b/Normal/Views/Home/BlockedItemVisibility.swift new file mode 100644 index 0000000..eb94482 --- /dev/null +++ b/Normal/Views/Home/BlockedItemVisibility.swift @@ -0,0 +1,18 @@ +import Foundation + +/// Decides which entries of a status list stay visible when the user has opted to +/// hide whatever is currently blocked. Generic over the item so the rules can be +/// tested without Screen Time tokens, which cannot be built outside the system. +struct BlockedItemVisibility { + let hideBlocked: Bool + + func visible(_ items: [Item], isBlocked: (Item) -> Bool) -> [Item] { + guard hideBlocked else { return items } + return items.filter { !isBlocked($0) } + } + + func hiddenCount(_ items: [Item], isBlocked: (Item) -> Bool) -> Int { + guard hideBlocked else { return 0 } + return items.filter(isBlocked).count + } +} diff --git a/Normal/Views/Home/StatusDetailView.swift b/Normal/Views/Home/StatusDetailView.swift index 3bd9567..a1c7d90 100644 --- a/Normal/Views/Home/StatusDetailView.swift +++ b/Normal/Views/Home/StatusDetailView.swift @@ -23,12 +23,41 @@ struct StatusDetailView: View { ScheduleSummary(schedules: schedules) } + private var visibility: BlockedItemVisibility { + BlockedItemVisibility(hideBlocked: allSettings.first?.hideBlockedApps ?? false) + } + + private var appKinds: [SelectedTokenKind] { + selection.applicationTokens.sortedStably.map(SelectedTokenKind.application) + } + + private var websiteKinds: [SelectedTokenKind] { + selection.webDomainTokens.sortedStably.map(SelectedTokenKind.webDomain) + } + + private var categoryKinds: [SelectedTokenKind] { + selection.categoryTokens.sortedStably.map(SelectedTokenKind.category) + } + + // Custom domains are filtered as a group: the shield store tracks them as one + // filter list, so they follow the overall status like their rows already do. + private var areCustomDomainsBlocked: Bool { overallStatus != .none } + + private var visibleCustomDomains: [String] { + visibility.visible(customDomains) { _ in areCustomDomainsBlocked } + } + + private var hiddenCount: Int { + visibility.hiddenCount(appKinds + websiteKinds + categoryKinds) { screenTimeService.isShielded($0) } + + visibility.hiddenCount(customDomains) { _ in areCustomDomainsBlocked } + } + var body: some View { List { overallSection - tokenSection("Apps", kinds: selection.applicationTokens.sortedStably.map(SelectedTokenKind.application)) - tokenSection("Websites", kinds: selection.webDomainTokens.sortedStably.map(SelectedTokenKind.webDomain)) - tokenSection("Categories", kinds: selection.categoryTokens.sortedStably.map(SelectedTokenKind.category)) + tokenSection("Apps", kinds: appKinds) + tokenSection("Websites", kinds: websiteKinds) + tokenSection("Categories", kinds: categoryKinds) customDomainsSection if !schedules.isEmpty { schedulesSection } } @@ -50,14 +79,30 @@ struct StatusDetailView: View { .foregroundStyle(.secondary) } } + if hiddenCount > 0 { hiddenNote } + } + } + + private var hiddenNote: some View { + Label { + if hiddenCount == 1 { + Text("1 blocked item hidden") + } else { + Text("\(hiddenCount) blocked items hidden") + } + } icon: { + Image(systemName: "eye.slash") } + .font(.caption) + .foregroundStyle(.secondary) + .accessibilityIdentifier("status.hiddenNote") } @ViewBuilder private var customDomainsSection: some View { - if !customDomains.isEmpty { + if !visibleCustomDomains.isEmpty { Section("Custom Domains") { - ForEach(customDomains, id: \.self) { domain in + ForEach(visibleCustomDomains, id: \.self) { domain in HStack { Label(domain, systemImage: "globe") .labelStyle(.titleAndIcon) @@ -77,9 +122,10 @@ struct StatusDetailView: View { @ViewBuilder private func tokenSection(_ title: LocalizedStringKey, kinds: [SelectedTokenKind]) -> some View { - if !kinds.isEmpty { + let shown = visibility.visible(kinds) { screenTimeService.isShielded($0) } + if !shown.isEmpty { Section(title) { - ForEach(kinds, id: \.self, content: tokenRow) + ForEach(shown, id: \.self, content: tokenRow) } } } diff --git a/Normal/Views/Settings/GeneralSettingsView.swift b/Normal/Views/Settings/GeneralSettingsView.swift index caaa775..80e0a02 100644 --- a/Normal/Views/Settings/GeneralSettingsView.swift +++ b/Normal/Views/Settings/GeneralSettingsView.swift @@ -100,10 +100,16 @@ struct GeneralSettingsView: View { "Hide Donate Button", isOn: Bindable(settings).hideDonateButton ) + + Toggle( + "Hide Blocked Apps", + isOn: Bindable(settings).hideBlockedApps + ) + .accessibilityIdentifier("settings.hideBlockedAppsToggle") } header: { Text("Navigation & Appearance") } footer: { - Text("Default Page opens when you launch the app. Hiding the Donate button hides it from the main toolbar.") + Text("Default Page opens when you launch the app. Hiding the Donate button hides it from the main toolbar. Hiding blocked apps keeps apps, websites and categories out of the Status list while they are blocked.") } } diff --git a/NormalTests/Models/SettingsTests.swift b/NormalTests/Models/SettingsTests.swift index 6f01f3c..7841ed7 100644 --- a/NormalTests/Models/SettingsTests.swift +++ b/NormalTests/Models/SettingsTests.swift @@ -51,5 +51,6 @@ struct SettingsTests { #expect(s.blockAllPreventsAppDelete == true) #expect(s.hasCompletedOnboarding == false) #expect(s.defaultTab == nil) + #expect(s.hideBlockedApps == false) } } diff --git a/NormalTests/Views/BlockedItemVisibilityTests.swift b/NormalTests/Views/BlockedItemVisibilityTests.swift new file mode 100644 index 0000000..8578603 --- /dev/null +++ b/NormalTests/Views/BlockedItemVisibilityTests.swift @@ -0,0 +1,55 @@ +import Foundation +@testable import Normal +import Testing + +@MainActor +struct BlockedItemVisibilityTests { + private static let blocked: Set = ["mail", "news"] + + private func visible(_ items: [String], hideBlocked: Bool) -> [String] { + BlockedItemVisibility(hideBlocked: hideBlocked).visible(items) { Self.blocked.contains($0) } + } + + private func hiddenCount(_ items: [String], hideBlocked: Bool) -> Int { + BlockedItemVisibility(hideBlocked: hideBlocked).hiddenCount(items) { Self.blocked.contains($0) } + } + + @Test func showsEverythingWhenDisabled() { + let items = ["mail", "maps", "news"] + #expect(visible(items, hideBlocked: false) == items) + } + + @Test func hidesBlockedItemsWhenEnabled() { + #expect(visible(["mail", "maps", "news"], hideBlocked: true) == ["maps"]) + } + + @Test func preservesOrderOfRemainingItems() { + let items = ["maps", "mail", "phone", "news", "photos"] + #expect(visible(items, hideBlocked: true) == ["maps", "phone", "photos"]) + } + + @Test func hidesNothingWhenNoItemIsBlocked() { + let items = ["maps", "phone"] + #expect(visible(items, hideBlocked: true) == items) + #expect(hiddenCount(items, hideBlocked: true) == 0) + } + + @Test func hidesEverythingWhenAllItemsAreBlocked() { + let items = ["mail", "news"] + #expect(visible(items, hideBlocked: true).isEmpty) + #expect(hiddenCount(items, hideBlocked: true) == 2) + } + + @Test func hiddenCountIsZeroWhenDisabled() { + #expect(hiddenCount(["mail", "news"], hideBlocked: false) == 0) + } + + @Test func hiddenCountCountsOnlyBlockedItems() { + #expect(hiddenCount(["mail", "maps", "news"], hideBlocked: true) == 2) + } + + @Test func emptyInputStaysEmpty() { + #expect(visible([], hideBlocked: true).isEmpty) + #expect(hiddenCount([], hideBlocked: true) == 0) + } +}