Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 13 additions & 2 deletions Normal/Services/BlockActions.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import UIKit

enum BlockActions {
static func blockAll(
Expand All @@ -13,6 +14,7 @@ enum BlockActions {
customDomains: settings.enableCustomDomains ? mainSelection.customDomains : [],
blockAllPreventsAppDelete: settings.blockAllPreventsAppDelete
)
playHaptic()
}

static func blockGroup(
Expand All @@ -26,6 +28,7 @@ enum BlockActions {
timedUnblockService.cancelGroup(groupId: group.id)
}
screenTimeService.block(selection: group.selection, customDomains: customDomains)
playHaptic()
}

@discardableResult
Expand All @@ -36,18 +39,21 @@ 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,
screenTimeService: screenTimeService
)
case .permanent:
screenTimeService.unblockPermanently(grant, settings: settings)
return .exact
timing = .exact
}
playHaptic()
return timing
}

static func emergencyUnblock(
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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")
}
Expand Down
5 changes: 2 additions & 3 deletions Normal/Views/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions NormalTests/TestSupport/BlockingHarness.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading