-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathShieldConfigurationExtension.swift.sample
More file actions
55 lines (49 loc) · 1.77 KB
/
Copy pathShieldConfigurationExtension.swift.sample
File metadata and controls
55 lines (49 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import ManagedSettings
import ManagedSettingsUI
import UIKit
final class ShieldConfigurationExtension: ShieldConfigurationDataSource {
private let suiteName = "group.your.app"
override func configuration(
shielding application: Application
) -> ShieldConfiguration {
let defaults = UserDefaults(suiteName: suiteName)
let config = defaults?.dictionary(forKey: "flutter_screentime.blockScreenConfig")
let title = config?["title"] as? String ?? "Blocked"
let message = config?["message"] as? String ?? "Come back later."
let backgroundHex = config?["backgroundColorHex"] as? String ?? "#111827"
let textHex = config?["textColorHex"] as? String ?? "#FFFFFF"
return ShieldConfiguration(
backgroundBlurStyle: .systemUltraThinMaterialDark,
backgroundColor: UIColor(hex: backgroundHex),
title: ShieldConfiguration.Label(
text: title,
color: UIColor(hex: textHex)
),
subtitle: ShieldConfiguration.Label(
text: message,
color: UIColor(hex: textHex)
),
primaryButtonLabel: ShieldConfiguration.Label(
text: config?["primaryButtonLabel"] as? String ?? "Open app",
color: UIColor(hex: textHex)
),
primaryButtonBackgroundColor: UIColor(hex: textHex)
)
}
}
private extension UIColor {
convenience init(hex: String) {
var sanitized = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
if sanitized.count == 6 {
sanitized = "FF" + sanitized
}
var value: UInt64 = 0
Scanner(string: sanitized).scanHexInt64(&value)
self.init(
red: CGFloat((value >> 16) & 0xFF) / 255.0,
green: CGFloat((value >> 8) & 0xFF) / 255.0,
blue: CGFloat(value & 0xFF) / 255.0,
alpha: CGFloat((value >> 24) & 0xFF) / 255.0
)
}
}