@@ -37,7 +37,8 @@ func updateShield(shieldId: String?, triggeredBy: String?, activitySelectionId:
37
37
let shieldId = shieldId ?? " default "
38
38
39
39
if var shieldConfiguration = userDefaults? . dictionary (
40
- forKey: " shieldConfiguration_ \( shieldId) " ) {
40
+ forKey: " shieldConfiguration_ \( shieldId) " )
41
+ {
41
42
42
43
shieldConfiguration [ " shieldId " ] = shieldId
43
44
shieldConfiguration [ " triggeredBy " ] = triggeredBy
@@ -53,7 +54,8 @@ func updateShield(shieldId: String?, triggeredBy: String?, activitySelectionId:
53
54
}
54
55
55
56
if var shieldActions = userDefaults? . dictionary (
56
- forKey: " shieldActions_ \( shieldId) " ) {
57
+ forKey: " shieldActions_ \( shieldId) " )
58
+ {
57
59
58
60
shieldActions [ " shieldId " ] = shieldId
59
61
shieldActions [ " triggeredBy " ] = triggeredBy
@@ -175,7 +177,8 @@ func sendNotification(contents: [String: Any], placeholders: [String: String?])
175
177
176
178
// dataRequest which sends request to given URL and convert to Decodable Object
177
179
func sendHttpRequest( with url: String , config: [ String : Any ] , placeholders: [ String : String ? ] )
178
- -> URLSessionDataTask {
180
+ -> URLSessionDataTask
181
+ {
179
182
// create the URL
180
183
let url = URL ( string: url) ! // change the URL
181
184
@@ -218,7 +221,8 @@ func sendHttpRequest(with url: String, config: [String: Any], placeholders: [Str
218
221
do {
219
222
// create json object from data
220
223
if let json = try JSONSerialization . jsonObject ( with: data, options: . mutableContainers)
221
- as? [ String : Any ] {
224
+ as? [ String : Any ]
225
+ {
222
226
print ( json)
223
227
}
224
228
} catch let error {
@@ -280,9 +284,11 @@ struct TextToReplaceWithOptionalSpecialTreatment {
280
284
}
281
285
282
286
func getTextToReplaceWithOptionalSpecialTreatment( _ stringToReplace: String )
283
- -> TextToReplaceWithOptionalSpecialTreatment {
287
+ -> TextToReplaceWithOptionalSpecialTreatment
288
+ {
284
289
if stringToReplace. starts ( with: " { " ) && stringToReplace. hasSuffix ( " } " )
285
- && stringToReplace. contains ( " : " ) {
290
+ && stringToReplace. contains ( " : " )
291
+ {
286
292
// remove prefix and suffix
287
293
let trimmed = String ( stringToReplace. dropFirst ( ) . dropLast ( ) )
288
294
// split on : and return first part
@@ -309,15 +315,17 @@ func replacePlaceholdersInObject<T: Any>(
309
315
if let specialTreatment = textToReplaceWithOptionalSpecialTreatment. specialTreatment {
310
316
if specialTreatment == " asNumber " {
311
317
if let placeholderValue = placeholders [
312
- textToReplaceWithOptionalSpecialTreatment. textToReplace] as? String {
318
+ textToReplaceWithOptionalSpecialTreatment. textToReplace] as? String
319
+ {
313
320
if let numberValue = Double ( placeholderValue) {
314
321
retVal [ key] = numberValue as? T
315
322
}
316
323
}
317
324
}
318
325
if specialTreatment == " userDefaults " {
319
326
if let value = userDefaults? . string (
320
- forKey: textToReplaceWithOptionalSpecialTreatment. textToReplace) {
327
+ forKey: textToReplaceWithOptionalSpecialTreatment. textToReplace)
328
+ {
321
329
retVal [ key] = value as? T
322
330
}
323
331
}
@@ -355,7 +363,8 @@ func clearAllManagedSettingsStoreSettings() {
355
363
@available ( iOS 15 . 0 , * )
356
364
func getFamilyActivitySelectionIds( ) -> [ FamilyActivitySelectionWithId ] {
357
365
if let familyActivitySelectionIds = userDefaults? . dictionary (
358
- forKey: " familyActivitySelectionIds " ) {
366
+ forKey: " familyActivitySelectionIds " )
367
+ {
359
368
return familyActivitySelectionIds. compactMap { ( key: String , value: Any ) in
360
369
if let familyActivitySelectionStr = value as? String {
361
370
let activitySelection = deserializeFamilyActivitySelection (
@@ -372,7 +381,8 @@ func getFamilyActivitySelectionIds() -> [FamilyActivitySelectionWithId] {
372
381
@available ( iOS 15 . 0 , * )
373
382
func getFamilyActivitySelectionById( id: String ) -> FamilyActivitySelection ? {
374
383
if let familyActivitySelectionIds = userDefaults? . dictionary (
375
- forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY) {
384
+ forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY)
385
+ {
376
386
if let familyActivitySelectionStr = familyActivitySelectionIds [ id] as? String {
377
387
let activitySelection = deserializeFamilyActivitySelection (
378
388
familyActivitySelectionStr: familyActivitySelectionStr
@@ -385,7 +395,8 @@ func getFamilyActivitySelectionById(id: String) -> FamilyActivitySelection? {
385
395
386
396
func removeFamilyActivitySelectionById( id: String ) {
387
397
if var familyActivitySelectionIds = userDefaults? . dictionary (
388
- forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY) {
398
+ forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY)
399
+ {
389
400
familyActivitySelectionIds. removeValue ( forKey: id)
390
401
391
402
userDefaults?
@@ -400,7 +411,8 @@ func setFamilyActivitySelectionById(id: String, activitySelection: FamilyActivit
400
411
)
401
412
402
413
if var familyActivitySelectionIds = userDefaults? . dictionary (
403
- forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY) {
414
+ forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY)
415
+ {
404
416
familyActivitySelectionIds [ id] = serialized
405
417
406
418
userDefaults?
@@ -416,7 +428,8 @@ func setFamilyActivitySelectionById(id: String, activitySelection: FamilyActivit
416
428
@available ( iOS 15 . 0 , * )
417
429
func renameFamilyActivitySelectionId( previousId: String , newId: String ) {
418
430
if var familyActivitySelectionIds = userDefaults? . dictionary (
419
- forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY) {
431
+ forKey: FAMILY_ACTIVITY_SELECTION_ID_KEY)
432
+ {
420
433
familyActivitySelectionIds [ newId] = familyActivitySelectionIds [ previousId]
421
434
familyActivitySelectionIds. removeValue ( forKey: previousId)
422
435
@@ -430,14 +443,16 @@ func tryGetActivitySelectionIdConfigKey(
430
443
keyPrefix: String ,
431
444
applicationToken: ApplicationToken ? = nil ,
432
445
webDomainToken: WebDomainToken ? = nil ,
433
- categoryToken: ActivityCategoryToken ? = nil
446
+ categoryToken: ActivityCategoryToken ? = nil ,
447
+ onlyFamilySelectionIdsContainingMonitoredActivityNames: Bool = true
434
448
) -> String ? {
435
449
let familyActivitySelectionIds = getPossibleFamilyActivitySelectionIds (
436
450
applicationToken: applicationToken,
437
451
webDomainToken: webDomainToken,
438
452
categoryToken: categoryToken,
439
- onlyFamilySelectionIdsContainingMonitoredActivityNames: true ,
440
- sortByGranularity: true
453
+ onlyFamilySelectionIdsContainingMonitoredActivityNames:
454
+ onlyFamilySelectionIdsContainingMonitoredActivityNames,
455
+ sortByGranularity: true ,
441
456
)
442
457
443
458
let activitySelection = familyActivitySelectionIds. first {
@@ -558,7 +573,8 @@ func getPossibleFamilyActivitySelectionIds(
558
573
559
574
@available ( iOS 15 . 0 , * )
560
575
func deserializeFamilyActivitySelection( familyActivitySelectionStr: String )
561
- -> FamilyActivitySelection {
576
+ -> FamilyActivitySelection
577
+ {
562
578
var activitySelection = FamilyActivitySelection ( )
563
579
564
580
let decoder = JSONDecoder ( )
@@ -604,7 +620,8 @@ func disableBlockAllMode(triggeredBy: String) {
604
620
func setsIncludesEntireCategory(
605
621
_ selection1: FamilyActivitySelection , _ selection2: FamilyActivitySelection
606
622
)
607
- -> Bool {
623
+ -> Bool
624
+ {
608
625
if #available( iOS 15 . 2 , * ) {
609
626
let selection1Safe = selection1. includeEntireCategory || selection1. categoryTokens. count == 0
610
627
@@ -618,7 +635,8 @@ func setsIncludesEntireCategory(
618
635
619
636
@available ( iOS 15 . 0 , * )
620
637
func intersection( _ selection1: FamilyActivitySelection , _ selection2: FamilyActivitySelection )
621
- -> FamilyActivitySelection {
638
+ -> FamilyActivitySelection
639
+ {
622
640
let applicationTokens = selection1. applicationTokens. intersection (
623
641
selection2. applicationTokens
624
642
)
@@ -681,7 +699,8 @@ func symmetricDifference(
681
699
682
700
@available ( iOS 15 . 0 , * )
683
701
func difference( _ selection1: FamilyActivitySelection , _ selection2: FamilyActivitySelection )
684
- -> FamilyActivitySelection {
702
+ -> FamilyActivitySelection
703
+ {
685
704
let applicationTokens = selection1. applicationTokens. subtracting (
686
705
selection2. applicationTokens
687
706
)
@@ -712,7 +731,8 @@ func difference(_ selection1: FamilyActivitySelection, _ selection2: FamilyActiv
712
731
713
732
@available ( iOS 15 . 0 , * )
714
733
func union( _ selection1: FamilyActivitySelection , _ selection2: FamilyActivitySelection )
715
- -> FamilyActivitySelection {
734
+ -> FamilyActivitySelection
735
+ {
716
736
let applicationTokens = selection1. applicationTokens. union (
717
737
selection2. applicationTokens
718
738
)
@@ -926,7 +946,7 @@ func updateBlock(triggeredBy: String) {
926
946
" blocklistCategoryCount " : currentBlocklist. categoryTokens. count,
927
947
" whitelistAppCount " : currentWhitelist. applicationTokens. count,
928
948
" whitelistWebDomainCount " : currentWhitelist. webDomainTokens. count,
929
- " whitelistCategoryCount " : currentWhitelist. categoryTokens. count
949
+ " whitelistCategoryCount " : currentWhitelist. categoryTokens. count,
930
950
] , forKey: " lastBlockUpdate " )
931
951
932
952
updateBlockInternal (
@@ -1010,7 +1030,8 @@ func getColor(color: [String: Double]?) -> UIColor? {
1010
1030
}
1011
1031
1012
1032
func userDefaultKeyForEvent( activityName: String , callbackName: String , eventName: String ? = nil )
1013
- -> String {
1033
+ -> String
1034
+ {
1014
1035
1015
1036
let fullEventName =
1016
1037
eventName == nil
@@ -1131,7 +1152,8 @@ func shouldExecuteAction(
1131
1152
eventName: eventName
1132
1153
) {
1133
1154
if lastTriggeredAt >= skipIfAlreadyTriggeredBetweenFromDate
1134
- && lastTriggeredAt <= skipIfAlreadyTriggeredBetweenToDate {
1155
+ && lastTriggeredAt <= skipIfAlreadyTriggeredBetweenToDate
1156
+ {
1135
1157
logger. log (
1136
1158
" skipping executing actions for \( callbackName) \( eventName ?? " " ) because the last triggered time is between \( skipIfAlreadyTriggeredBetweenFromDate) and \( skipIfAlreadyTriggeredBetweenToDate) "
1137
1159
)
@@ -1155,7 +1177,8 @@ func shouldExecuteAction(
1155
1177
}
1156
1178
}
1157
1179
1158
- if let skipIfLargerEventRecordedAfter = skipIfLargerEventRecordedAfter, let eventName = eventName {
1180
+ if let skipIfLargerEventRecordedAfter = skipIfLargerEventRecordedAfter, let eventName = eventName
1181
+ {
1159
1182
if hasHigherTriggeredEvent (
1160
1183
activityName: activityName,
1161
1184
callbackName: callbackName,
@@ -1187,7 +1210,8 @@ func shouldExecuteAction(
1187
1210
}
1188
1211
1189
1212
if let skipIfLargerEventRecordedWithinMS = skipIfLargerEventRecordedWithinMS,
1190
- let eventName = eventName {
1213
+ let eventName = eventName
1214
+ {
1191
1215
let skipIfLargerEventRecordedAfter =
1192
1216
Date ( ) . timeIntervalSince1970 * 1000 - skipIfLargerEventRecordedWithinMS
1193
1217
if hasHigherTriggeredEvent (
@@ -1204,7 +1228,8 @@ func shouldExecuteAction(
1204
1228
}
1205
1229
1206
1230
if let skipIfLargerEventRecordedSinceIntervalStarted =
1207
- skipIfLargerEventRecordedSinceIntervalStarted, let eventName = eventName {
1231
+ skipIfLargerEventRecordedSinceIntervalStarted, let eventName = eventName
1232
+ {
1208
1233
if skipIfLargerEventRecordedSinceIntervalStarted {
1209
1234
if let skipIfLargerEventRecordedAfter = getLastTriggeredTimeFromUserDefaults (
1210
1235
activityName: activityName,
0 commit comments