-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathIntents.swift
113 lines (98 loc) · 3.45 KB
/
Intents.swift
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
import AppIntents
import UIKit
@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()
}
}