Skip to content

Commit 4629d53

Browse files
committed
Dropping the idea of customizing per token
1 parent c324afe commit 4629d53

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

example/App.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ const startMonitoring = (activitySelection: string) => {
142142
},
143143
shieldConfiguration: {
144144
backgroundBlurStyle: UIBlurEffectStyle.prominent,
145-
title: "{appname} Blocked by Zabit",
145+
title: "{applicationOrDomainDisplayName} Blocked by Zabit",
146146
subtitle: "You have reached your limit! {token} {tokenType}",
147+
primaryButtonLabel: "Give me 5 more minutes",
148+
secondaryButtonLabel: "Close",
147149
titleColor: {
148150
red: 255,
149151
green: 0.329 * 255,
@@ -192,9 +194,13 @@ export default function App() {
192194
const [authorizationStatus, setAuthorizationStatus] =
193195
React.useState<AuthorizationStatus | null>(null);
194196

195-
/*console.log(
196-
JSON.stringify(ReactNativeDeviceActivity.userDefaultsAll(), null, 2),
197-
);*/
197+
console.log(
198+
JSON.stringify(
199+
ReactNativeDeviceActivity.userDefaultsGet("shieldActions"),
200+
null,
201+
2,
202+
),
203+
);
198204

199205
const [familyActivitySelection, setFamilyActivitySelection] = React.useState<
200206
string | null

example/targets/ActivityMonitorExtension/DeviceActivityMonitorExtension.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class DeviceActivityMonitorExtension: DeviceActivityMonitor {
9393
// update default shield
9494
userDefaults?.set(shieldConfiguration, forKey: "shieldConfiguration")
9595

96+
/* ok so this does not work, tokens change across executions
9697
activitySelection.applicationTokens.forEach { applicationToken in
9798
userDefaults?.set(shieldConfiguration, forKey: "shieldConfiguration_for_application_\(applicationToken.hashValue)")
9899
}
@@ -104,9 +105,12 @@ class DeviceActivityMonitorExtension: DeviceActivityMonitor {
104105
activitySelection.webDomainTokens.forEach { webDomainToken in
105106
userDefaults?.set(shieldConfiguration, forKey: "shieldConfiguration_for_domain_\(webDomainToken.hashValue)")
106107
}
108+
*/
107109
}
108110

109111
if let shieldActions = action["shieldActions"] as? Dictionary<String, Any> {
112+
userDefaults?.set(shieldActions, forKey: "shieldActions")
113+
/*
110114
activitySelection.applicationTokens.forEach { applicationToken in
111115
userDefaults?.set(shieldActions, forKey: "shieldActions_for_application_\(applicationToken.hashValue)")
112116
}
@@ -118,6 +122,7 @@ class DeviceActivityMonitorExtension: DeviceActivityMonitor {
118122
activitySelection.webDomainTokens.forEach { webDomainToken in
119123
userDefaults?.set(shieldActions, forKey: "shieldActions_for_domain_\(webDomainToken.hashValue)")
120124
}
125+
*/
121126
}
122127
}
123128
}

example/targets/ShieldAction/ShieldActionExtension.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func handleAction(dict: [String: Any]) -> ShieldActionResponse {
6767
class ShieldActionExtension: ShieldActionDelegate {
6868
override func handle(action: ShieldAction, for application: ApplicationToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
6969
logger.log("handle application")
70-
if let obj = userDefaults?.dictionary(forKey: "shieldAction_for_application_\(application.hashValue)") {
70+
if let obj = userDefaults?.dictionary(forKey: "shieldActions") {
7171
if let dict = obj[action == .primaryButtonPressed ? "primary" : "secondary"] as? [String: Any] {
7272
let response = handleAction(dict: dict)
7373
completionHandler(response)
@@ -81,7 +81,7 @@ class ShieldActionExtension: ShieldActionDelegate {
8181

8282
override func handle(action: ShieldAction, for webDomain: WebDomainToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
8383
logger.log("handle domain")
84-
if let obj = userDefaults?.dictionary(forKey: "shieldAction_for_domain_\(webDomain.hashValue)") {
84+
if let obj = userDefaults?.dictionary(forKey: "shieldActions") {
8585
if let dict = obj[action == .primaryButtonPressed ? "primary" : "secondary"] as? [String: Any] {
8686
let response = handleAction(dict: dict)
8787
completionHandler(response)
@@ -97,7 +97,7 @@ class ShieldActionExtension: ShieldActionDelegate {
9797
logger.log("handle category")
9898
// openUrl(urlString: "device-activity://")
9999

100-
if let obj = userDefaults?.dictionary(forKey: "shieldAction_for_category_\(category.hashValue)") {
100+
if let obj = userDefaults?.dictionary(forKey: "shieldActions") {
101101
if let dict = obj[action == .primaryButtonPressed ? "primary" : "secondary"] as? [String: Any] {
102102
let response = handleAction(dict: dict)
103103
completionHandler(response)

targets/ActivityMonitorExtension/DeviceActivityMonitorExtension.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class DeviceActivityMonitorExtension: DeviceActivityMonitor {
9393
// update default shield
9494
userDefaults?.set(shieldConfiguration, forKey: "shieldConfiguration")
9595

96+
/* ok so this does not work, tokens change across executions
9697
activitySelection.applicationTokens.forEach { applicationToken in
9798
userDefaults?.set(shieldConfiguration, forKey: "shieldConfiguration_for_application_\(applicationToken.hashValue)")
9899
}
@@ -104,9 +105,12 @@ class DeviceActivityMonitorExtension: DeviceActivityMonitor {
104105
activitySelection.webDomainTokens.forEach { webDomainToken in
105106
userDefaults?.set(shieldConfiguration, forKey: "shieldConfiguration_for_domain_\(webDomainToken.hashValue)")
106107
}
108+
*/
107109
}
108110

109111
if let shieldActions = action["shieldActions"] as? Dictionary<String, Any> {
112+
userDefaults?.set(shieldActions, forKey: "shieldActions")
113+
/*
110114
activitySelection.applicationTokens.forEach { applicationToken in
111115
userDefaults?.set(shieldActions, forKey: "shieldActions_for_application_\(applicationToken.hashValue)")
112116
}
@@ -118,6 +122,7 @@ class DeviceActivityMonitorExtension: DeviceActivityMonitor {
118122
activitySelection.webDomainTokens.forEach { webDomainToken in
119123
userDefaults?.set(shieldActions, forKey: "shieldActions_for_domain_\(webDomainToken.hashValue)")
120124
}
125+
*/
121126
}
122127
}
123128
}

targets/ShieldAction/ShieldActionExtension.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func handleAction(dict: [String: Any]) -> ShieldActionResponse {
6767
class ShieldActionExtension: ShieldActionDelegate {
6868
override func handle(action: ShieldAction, for application: ApplicationToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
6969
logger.log("handle application")
70-
if let obj = userDefaults?.dictionary(forKey: "shieldAction_for_application_\(application.hashValue)") {
70+
if let obj = userDefaults?.dictionary(forKey: "shieldActions") {
7171
if let dict = obj[action == .primaryButtonPressed ? "primary" : "secondary"] as? [String: Any] {
7272
let response = handleAction(dict: dict)
7373
completionHandler(response)
@@ -81,7 +81,7 @@ class ShieldActionExtension: ShieldActionDelegate {
8181

8282
override func handle(action: ShieldAction, for webDomain: WebDomainToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
8383
logger.log("handle domain")
84-
if let obj = userDefaults?.dictionary(forKey: "shieldAction_for_domain_\(webDomain.hashValue)") {
84+
if let obj = userDefaults?.dictionary(forKey: "shieldActions") {
8585
if let dict = obj[action == .primaryButtonPressed ? "primary" : "secondary"] as? [String: Any] {
8686
let response = handleAction(dict: dict)
8787
completionHandler(response)
@@ -97,7 +97,7 @@ class ShieldActionExtension: ShieldActionDelegate {
9797
logger.log("handle category")
9898
// openUrl(urlString: "device-activity://")
9999

100-
if let obj = userDefaults?.dictionary(forKey: "shieldAction_for_category_\(category.hashValue)") {
100+
if let obj = userDefaults?.dictionary(forKey: "shieldActions") {
101101
if let dict = obj[action == .primaryButtonPressed ? "primary" : "secondary"] as? [String: Any] {
102102
let response = handleAction(dict: dict)
103103
completionHandler(response)

0 commit comments

Comments
 (0)