diff --git a/Normal/Services/BlockActions.swift b/Normal/Services/BlockActions.swift index 0aabe3c..7bbe3e4 100644 --- a/Normal/Services/BlockActions.swift +++ b/Normal/Services/BlockActions.swift @@ -1,4 +1,5 @@ import Foundation +import UIKit enum BlockActions { static func blockAll( @@ -13,6 +14,7 @@ enum BlockActions { customDomains: settings.enableCustomDomains ? mainSelection.customDomains : [], blockAllPreventsAppDelete: settings.blockAllPreventsAppDelete ) + playHaptic() } static func blockGroup( @@ -26,6 +28,7 @@ enum BlockActions { timedUnblockService.cancelGroup(groupId: group.id) } screenTimeService.block(selection: group.selection, customDomains: customDomains) + playHaptic() } @discardableResult @@ -36,9 +39,10 @@ enum BlockActions { screenTimeService: any ScreenTimeProviding, timedUnblockService: TimedUnblockService ) throws -> UnblockTiming { + let timing: UnblockTiming switch length { case let .timed(duration): - return try timedUnblockService.start( + timing = try timedUnblockService.start( grant, duration: duration, settings: settings, @@ -46,8 +50,10 @@ enum BlockActions { ) case .permanent: screenTimeService.unblockPermanently(grant, settings: settings) - return .exact + timing = .exact } + playHaptic() + return timing } static func emergencyUnblock( @@ -61,6 +67,11 @@ enum BlockActions { scheduleService.disableAll(schedules, screenTimeService: screenTimeService) usageLimitService.overrideToday() screenTimeService.removeAllRestrictions() + playHaptic() + } + + private static func playHaptic() { + UIImpactFeedbackGenerator(style: .medium).impactOccurred() } static func validate(isAuthorized: Bool, hasCompletedOnboarding: Bool, keys: [Key]) throws { diff --git a/Normal/Views/BlockUnblockViews/TimedUnlock/TimedUnlockBannerView.swift b/Normal/Views/BlockUnblockViews/TimedUnlock/TimedUnlockBannerView.swift index 2a9203d..0f386df 100644 --- a/Normal/Views/BlockUnblockViews/TimedUnlock/TimedUnlockBannerView.swift +++ b/Normal/Views/BlockUnblockViews/TimedUnlock/TimedUnlockBannerView.swift @@ -1,23 +1,10 @@ -import FamilyControls -import SwiftData import SwiftUI struct TimedUnblockBannerView: View { - @Environment(ScreenTimeService.self) private var screenTimeService @Environment(TimedUnblockService.self) private var timedUnblockService - @Query private var allSettings: [Settings] - let selection: FamilyActivitySelection - var customDomains: [String] = [] @Binding var authAction: ProtectedAction? - - private var settings: Settings { - allSettings.unwrapped - } - - private var effectiveCustomDomains: [String] { - settings.enableCustomDomains ? customDomains : [] - } + let onBlockAllNow: () -> Void var body: some View { if let endDate = timedUnblockService.mainUnblockEndDate, endDate > .now { @@ -41,14 +28,7 @@ struct TimedUnblockBannerView: View { prominent: false, tint: .orange ) { - authAction = .tighten { - timedUnblockService.cancelMain( - selection: selection, - customDomains: effectiveCustomDomains, - screenTimeService: screenTimeService, - blockAllPreventsAppDelete: settings.blockAllPreventsAppDelete - ) - } + authAction = .tighten { onBlockAllNow() } } .accessibilityIdentifier("home.blockAllNow") } diff --git a/Normal/Views/Home/HomeView.swift b/Normal/Views/Home/HomeView.swift index 5fa0efa..b6160c5 100644 --- a/Normal/Views/Home/HomeView.swift +++ b/Normal/Views/Home/HomeView.swift @@ -33,9 +33,8 @@ struct HomeView: View { List { if let mainSelection, mainSelection.hasItemsToBlock(customDomainsEnabled: settings.enableCustomDomains) { TimedUnblockBannerView( - selection: mainSelection.selection, - customDomains: mainSelection.customDomains, - authAction: $authAction + authAction: $authAction, + onBlockAllNow: { blockMain(mainSelection) } ) MainBlockButtonView( mainSelection: mainSelection, diff --git a/NormalTests/TestSupport/BlockingHarness.swift b/NormalTests/TestSupport/BlockingHarness.swift index b6cc8d5..bf64b5f 100644 --- a/NormalTests/TestSupport/BlockingHarness.swift +++ b/NormalTests/TestSupport/BlockingHarness.swift @@ -150,12 +150,7 @@ final class BlockingHarness { } func blockAllNow() { - timedUnblock.cancelMain( - selection: main.selection, - customDomains: main.customDomains, - screenTimeService: screenTime, - blockAllPreventsAppDelete: settings.blockAllPreventsAppDelete - ) + blockAll() } func emergencyUnblock() {