Skip to content

Commit a41c5d9

Browse files
authored
revert: restore custom domains toggle (#90)
This reverts commit 0ac8e9b (#87), bringing back Settings.enableCustomDomains, its Settings row, the App Group mirror and the call-site gating, and dropping CustomDomainsMigration. #87 never reached the App Store (1.6 is live), so 1.6 users keep their existing toggle state and behaviour.
1 parent b09aeba commit a41c5d9

44 files changed

Lines changed: 268 additions & 252 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Normal/App/AppContainer.swift‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import SwiftData
12
import SwiftUI
23

34
struct AppContainer: View {
5+
@Query private var allSettings: [Settings]
46
@State private var screenTimeService: ScreenTimeService
57
@State private var timedUnblockService: TimedUnblockService
68
@State private var nfcService = NFCService.shared
@@ -37,5 +39,14 @@ struct AppContainer: View {
3739
.environment(emergencyUnblockService)
3840
.environment(donationService)
3941
.environment(usageLimitService)
42+
.task { mirrorCustomDomainsEnabled() }
43+
.onChange(of: allSettings.first?.enableCustomDomains ?? false) { _, enabled in
44+
scheduleService.mirrorCustomDomainsEnabled(enabled)
45+
screenTimeService.reconcile()
46+
}
47+
}
48+
49+
private func mirrorCustomDomainsEnabled() {
50+
scheduleService.mirrorCustomDomainsEnabled(allSettings.first?.enableCustomDomains ?? false)
4051
}
4152
}

‎Normal/App/NormalApp.swift‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@ struct NormalApp: App {
2828
if (try? context.fetchCount(descriptor)) == 0 {
2929
let settings = Settings()
3030
settings.hasCompletedOnboarding = UITestSupport.skipOnboarding
31+
settings.enableCustomDomains = UITestSupport.customDomains
3132
settings.skipBlockWithoutKeyConfirmation = UITestSupport.skipBypassConfirm
3233
settings.customUnblockDurationSeconds = UITestSupport.unblockDurationSeconds
3334
settings.defaultUnblockSeconds = UITestSupport.defaultDurationSeconds
3435
context.insert(settings)
3536
}
3637

37-
if !UITestSupport.isActive, !UITestSupport.isUnitTestHost {
38-
CustomDomainsMigration.run(context: context, sharedStore: SharedStore())
39-
}
40-
4138
if UITestSupport.isActive {
4239
context.insert(SelectedApps(selection: UITestSupport.mainSelection))
4340
if !UITestSupport.noKeys {

‎Normal/App/UITestSupport.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ enum UITestSupport {
1818

1919
static let startBlocked = arguments.contains("-uiTestStartBlocked")
2020

21+
static let customDomains = arguments.contains("-uiTestCustomDomains")
22+
2123
static let seedGroupKey = arguments.contains("-uiTestSeedGroupKey")
2224

2325
static let seedGroupID = UUID(uuidString: "6E0A1C9B-2D4F-4B7A-9C3E-5F8D1A2B3C4D")!

‎Normal/Intents/AppBlockIntentPerformer.swift‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ final class AppBlockIntentPerformer: BlockIntentPerforming {
3838
let settings = try validatedSettings()
3939
guard let mainSelection = try context.fetch(FetchDescriptor<SelectedApps>()).first,
4040
!mainSelection.selection.isEmpty
41-
|| !mainSelection.customDomains.isEmpty
41+
|| (settings.enableCustomDomains && !mainSelection.customDomains.isEmpty)
4242
else { throw BlockIntentError.noAppsSelected }
4343

4444
let status = screenTimeService.blockStatus(
4545
selection: mainSelection.selection,
46-
customDomains: mainSelection.customDomains
46+
customDomains: settings.enableCustomDomains ? mainSelection.customDomains : []
4747
)
4848
let wasAlreadyBlocked = status == .all && timedUnblockService.activeUnblocks.isEmpty
4949

@@ -67,7 +67,7 @@ final class AppBlockIntentPerformer: BlockIntentPerforming {
6767

6868
let status = screenTimeService.blockStatus(
6969
selection: group.selection,
70-
customDomains: group.customDomains
70+
customDomains: settings.enableCustomDomains ? group.customDomains : []
7171
)
7272
let wasAlreadyBlocked = status == .all && !timedUnblockService.isGroupUnblockActive(groupId: id)
7373

‎Normal/Models/Settings.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ final class Settings {
1515
var defaultTab: AppTab?
1616
var hideDonateButton: Bool = false
1717
var showTimedUnblockLiveActivity: Bool = false
18+
var enableCustomDomains: Bool = false
1819
var skipBlockWithoutKeyConfirmation: Bool = false
1920
var dailyLimitResetMinutes: Int = 0
2021

‎Normal/Modifiers/WidgetActionResponder.swift‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ private struct WidgetActionResponder: ViewModifier {
2222
allSettings.first?.unblockDurations ?? TimedUnblockDuration.presets
2323
}
2424

25+
private var customDomainsEnabled: Bool {
26+
allSettings.first?.enableCustomDomains ?? false
27+
}
28+
29+
private func customDomains(for group: AppGroup) -> [String] {
30+
customDomainsEnabled ? group.customDomains : []
31+
}
32+
2533
func body(content: Content) -> some View {
2634
content
2735
.protectedAction(
@@ -94,7 +102,7 @@ private struct WidgetActionResponder: ViewModifier {
94102
duration: duration,
95103
groupId: group.id,
96104
selection: group.selection,
97-
customDomains: group.customDomains,
105+
customDomains: customDomains(for: group),
98106
screenTimeService: screenTimeService
99107
)
100108
} else {

‎Normal/Resources/Localizable.xcstrings‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@
701701
},
702702
"Enable" : {
703703

704+
},
705+
"Enable Custom Websites" : {
706+
"comment" : "A toggle that lets the user enable or disable blocking of custom website domains.",
707+
"isCommentAutoGenerated" : true
704708
},
705709
"Enable location access in Settings to use your current spot. You can still pick anywhere on the map." : {
706710
"comment" : "A message explaining that location access is needed to use the user's current location, and that the user can still pick a location on the map.",
@@ -1559,6 +1563,10 @@
15591563
"comment" : "A footer text that appears when \"Select Apps\" is tapped, explaining that unblocking apps is necessary to edit the selection.",
15601564
"isCommentAutoGenerated" : true
15611565
},
1566+
"Unblock all apps to turn this off." : {
1567+
"comment" : "A footer explaining why the custom websites toggle is disabled while custom domains are blocked.",
1568+
"isCommentAutoGenerated" : true
1569+
},
15621570
"Unblock Durations" : {
15631571
"comment" : "Title of a row that shows the number of unblock durations.",
15641572
"isCommentAutoGenerated" : true

‎Normal/Services/BlockActions.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ enum BlockActions {
1010
timedUnblockService.clearAll()
1111
screenTimeService.blockAll(
1212
selection: mainSelection.selection,
13-
customDomains: mainSelection.customDomains,
13+
customDomains: settings.enableCustomDomains ? mainSelection.customDomains : [],
1414
blockAllPreventsAppDelete: settings.blockAllPreventsAppDelete
1515
)
1616
}
@@ -21,7 +21,7 @@ enum BlockActions {
2121
screenTimeService: any ScreenTimeProviding,
2222
timedUnblockService: TimedUnblockService
2323
) {
24-
let customDomains = group.customDomains
24+
let customDomains = settings.enableCustomDomains ? group.customDomains : []
2525
if timedUnblockService.isGroupUnblockActive(groupId: group.id) {
2626
timedUnblockService.cancelGroup(groupId: group.id)
2727
}

‎Normal/Services/CustomDomainsMigration.swift‎

Lines changed: 0 additions & 69 deletions
This file was deleted.

‎Normal/Services/ScheduleService.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ final class ScheduleService {
6464
.hasSameWindow(as: makeDeviceSchedule(for: schedule)) == true
6565
}
6666

67+
func mirrorCustomDomainsEnabled(_ enabled: Bool) {
68+
sharedStore.setCustomDomainsEnabled(enabled)
69+
}
70+
6771
func remove(
6872
_ schedule: BlockSchedule,
6973
remaining: [BlockSchedule],

0 commit comments

Comments
 (0)