-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathIntents.swift
More file actions
155 lines (134 loc) · 5 KB
/
Intents.swift
File metadata and controls
155 lines (134 loc) · 5 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import AppIntents
import UIKit
import CoreTransferable
@available(iOS 16.0, *)
struct AmberOnIntent: AppIntent {
static let title: LocalizedStringResource = "Amber On"
static let description = IntentDescription(
"Turn on all amber LEDs",
categoryName: "Device"
)
static let openAppWhenRun: Bool = true
func perform() async throws -> some IntentResult {
if let url = URL(string: "leds://com.ps.TrollLEDs.AmberOn") {
if await UIApplication.shared.canOpenURL(url) {
await UIApplication.shared.open(url)
}
}
return .result()
}
}
@available(iOS 16.0, *)
struct WhiteOnIntent: AppIntent {
static let title: LocalizedStringResource = "White On"
static let description = IntentDescription(
"Turn on all white LEDs",
categoryName: "Device"
)
static let openAppWhenRun: Bool = true
func perform() async throws -> some IntentResult {
if let url = URL(string: "leds://com.ps.TrollLEDs.WhiteOn") {
if await UIApplication.shared.canOpenURL(url) {
await UIApplication.shared.open(url)
}
}
return .result()
}
}
@available(iOS 16.0, *)
struct AllOnIntent: AppIntent {
static let title: LocalizedStringResource = "All On"
static let description = IntentDescription(
"Turn on all LEDs",
categoryName: "Device"
)
static let openAppWhenRun: Bool = true
func perform() async throws -> some IntentResult {
if let url = URL(string: "leds://com.ps.TrollLEDs.AllOn") {
if await UIApplication.shared.canOpenURL(url) {
await UIApplication.shared.open(url)
}
}
return .result()
}
}
@available(iOS 16.0, *)
struct AllOffIntent: AppIntent {
static let title: LocalizedStringResource = "All Off"
static let description = IntentDescription(
"Turn off all LEDs",
categoryName: "Device"
)
static let openAppWhenRun: Bool = true
func perform() async throws -> some IntentResult {
if let url = URL(string: "leds://com.ps.TrollLEDs.AllOff") {
if await UIApplication.shared.canOpenURL(url) {
await UIApplication.shared.open(url)
}
}
return .result()
}
}
@available(iOS 16.0, *)
struct ManualIntent: AppIntent {
static let title: LocalizedStringResource = "Manual"
static let description = IntentDescription(
"Configure LEDs levels manually (0 - 255) (For Quad-LEDs devices only)",
categoryName: "Device"
)
static let openAppWhenRun: Bool = true
@Parameter(title: "Cool LED 0", inclusiveRange: (0, 255))
var coolLED0: Int
@Parameter(title: "Cool LED 1", inclusiveRange: (0, 255))
var coolLED1: Int
@Parameter(title: "Warm LED 0", inclusiveRange: (0, 255))
var warmLED0: Int
@Parameter(title: "Warm LED 1", inclusiveRange: (0, 255))
var warmLED1: Int
static var parameterSummary: some ParameterSummary {
Summary("Configure LEDs levels to (\(\.$coolLED0), \(\.$coolLED1), \(\.$warmLED0), \(\.$warmLED1))")
}
func perform() async throws -> some IntentResult {
if let url = URL(string: "leds://com.ps.TrollLEDs.Manual?coolLED0=\(coolLED0)&coolLED1=\(coolLED1)&warmLED0=\(warmLED0)&warmLED1=\(warmLED1)") {
if await UIApplication.shared.canOpenURL(url) {
await UIApplication.shared.open(url)
}
}
return .result()
}
}
@available(iOS 16.0, *)
struct GetLEDLevelsIntent: AppIntent {
static let title: LocalizedStringResource = "Get LED Levels"
static let description = IntentDescription(
"Get current LED brightness levels from hardware or saved state",
categoryName: "Device"
)
static let openAppWhenRun: Bool = false
func perform() async throws -> some IntentResult & ProvidesDialog {
// Read current values using the LED reader
guard let levels = TLLEDReader.getCurrentLEDLevels() else {
return .result(dialog: IntentDialog("Unable to read LED levels"))
}
let coolLED0 = levels["coolLED0"] as? Int ?? 0
let coolLED1 = levels["coolLED1"] as? Int ?? 0
let warmLED0 = levels["warmLED0"] as? Int ?? 0
let warmLED1 = levels["warmLED1"] as? Int ?? 0
let torchLevel = levels["torchLevel"] as? Double ?? 0.0
let warmth = levels["warmth"] as? Int ?? 0
let isLocked = levels["isLocked"] as? Bool ?? false
let source = levels["source"] as? String ?? "unknown"
let sourceText = source == "hardware" ? "from hardware" : "from saved state"
let message = """
LED Levels (\(sourceText)):
Cool LED 0: \(coolLED0)
Cool LED 1: \(coolLED1)
Warm LED 0: \(warmLED0)
Warm LED 1: \(warmLED1)
Torch Level: \(Int(torchLevel * 100))%
Warmth: \(warmth)%
Lock State: \(isLocked ? "Locked" : "Unlocked")
"""
return .result(dialog: IntentDialog(stringLiteral: message))
}
}