@@ -41,15 +41,15 @@ func sendNotification(){
41
41
UNUserNotificationCenter . current ( ) . add ( request, withCompletionHandler: nil )
42
42
}
43
43
44
- func handleAction( dict : [ String : Any ] ) -> ShieldActionResponse {
44
+ func handleAction( configForSelectedAction : [ String : Any ] ) -> ShieldActionResponse {
45
45
logger. log ( " handleAction " )
46
- if let type = dict [ " type " ] as? String {
46
+ if let type = configForSelectedAction [ " type " ] as? String {
47
47
if ( type == " unblockAll " ) {
48
48
unblockAllApps ( )
49
49
}
50
50
}
51
51
52
- if let behaviour = dict [ " behavior " ] as? String {
52
+ if let behaviour = configForSelectedAction [ " behavior " ] as? String {
53
53
if ( behaviour == " defer " ) {
54
54
return . defer
55
55
}
@@ -58,52 +58,37 @@ func handleAction(dict: [String: Any]) -> ShieldActionResponse {
58
58
return . close
59
59
}
60
60
61
+ func handleAction( action: ShieldAction , completionHandler: @escaping ( ShieldActionResponse ) -> Void ) {
62
+ if let shieldActionConfig = userDefaults? . dictionary ( forKey: " shieldActions " ) {
63
+ if let configForSelectedAction = shieldActionConfig [ action == . primaryButtonPressed ? " primary " : " secondary " ] as? [ String : Any ] {
64
+ let response = handleAction ( configForSelectedAction: configForSelectedAction)
65
+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 1 ) {
66
+ completionHandler ( response) ;
67
+ }
68
+ } else {
69
+ completionHandler ( . close)
70
+ }
71
+ } else {
72
+ completionHandler ( . close)
73
+ }
74
+ }
75
+
61
76
// Override the functions below to customize the shield actions used in various situations.
62
77
// The system provides a default response for any functions that your subclass doesn't override.
63
78
// Make sure that your class name matches the NSExtensionPrincipalClass in your Info.plist.
64
79
class ShieldActionExtension : ShieldActionDelegate {
65
80
override func handle( action: ShieldAction , for application: ApplicationToken , completionHandler: @escaping ( ShieldActionResponse ) -> Void ) {
66
81
logger. log ( " handle application " )
67
- if let obj = userDefaults? . dictionary ( forKey: " shieldActions " ) {
68
- if let dict = obj [ action == . primaryButtonPressed ? " primary " : " secondary " ] as? [ String : Any ] {
69
- let response = handleAction ( dict: dict)
70
- completionHandler ( response)
71
- } else {
72
- completionHandler ( . close)
73
- }
74
- } else {
75
- completionHandler ( . close)
76
- }
82
+ handleAction ( action: action, completionHandler: completionHandler)
77
83
}
78
84
79
85
override func handle( action: ShieldAction , for webDomain: WebDomainToken , completionHandler: @escaping ( ShieldActionResponse ) -> Void ) {
80
86
logger. log ( " handle domain " )
81
- if let obj = userDefaults? . dictionary ( forKey: " shieldActions " ) {
82
- if let dict = obj [ action == . primaryButtonPressed ? " primary " : " secondary " ] as? [ String : Any ] {
83
- let response = handleAction ( dict: dict)
84
- completionHandler ( response)
85
- } else {
86
- completionHandler ( . close)
87
- }
88
- } else {
89
- completionHandler ( . close)
90
- }
87
+ handleAction ( action: action, completionHandler: completionHandler)
91
88
}
92
89
93
90
override func handle( action: ShieldAction , for category: ActivityCategoryToken , completionHandler: @escaping ( ShieldActionResponse ) -> Void ) {
94
91
logger. log ( " handle category " )
95
- // openUrl(urlString: "device-activity://")
96
-
97
- if let obj = userDefaults? . dictionary ( forKey: " shieldActions " ) {
98
- if let dict = obj [ action == . primaryButtonPressed ? " primary " : " secondary " ] as? [ String : Any ] {
99
- let response = handleAction ( dict: dict)
100
- completionHandler ( response)
101
- } else {
102
- completionHandler ( . close)
103
- }
104
- } else {
105
- completionHandler ( . close)
106
- }
107
- // sendNotification()
92
+ handleAction ( action: action, completionHandler: completionHandler)
108
93
}
109
94
}
0 commit comments