-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
WorkflowKeyboardTriggerView.swift
86 lines (79 loc) · 3.04 KB
/
WorkflowKeyboardTriggerView.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
import Bonzai
import Combine
import Inject
import SwiftUI
struct WorkflowKeyboardTriggerView: View {
@ObserveInjection var inject
@State private var holdDurationText = ""
@State private var passthrough: Bool
@State private var trigger: DetailViewModel.KeyboardTrigger
private let keyboardShortcutSelectionManager: SelectionManager<KeyShortcut>
private let namespace: Namespace.ID
private let onAction: (SingleDetailView.Action) -> Void
private let workflowId: String
private var focus: FocusState<AppFocus?>.Binding
init(namespace: Namespace.ID,
workflowId: String,
focus: FocusState<AppFocus?>.Binding,
trigger: DetailViewModel.KeyboardTrigger,
keyboardShortcutSelectionManager: SelectionManager<KeyShortcut>,
onAction: @escaping (SingleDetailView.Action) -> Void) {
self.namespace = namespace
self.workflowId = workflowId
self.focus = focus
_trigger = .init(initialValue: trigger)
if let holdDuration = trigger.holdDuration {
_holdDurationText = .init(initialValue: String(Double(holdDuration)))
}
_passthrough = .init(initialValue: trigger.passthrough)
self.onAction = onAction
self.keyboardShortcutSelectionManager = keyboardShortcutSelectionManager
}
var body: some View {
VStack(spacing: 8) {
WorkflowShortcutsView(focus, data: $trigger.shortcuts, selectionManager: keyboardShortcutSelectionManager) { keyboardShortcuts in
onAction(.updateKeyboardShortcuts(workflowId: workflowId,
passthrough: passthrough,
holdDuration: Double(holdDurationText),
keyboardShortcuts: keyboardShortcuts))
}
HStack {
ZenCheckbox("Passthrough", style: .small, isOn: $passthrough) { newValue in
onAction(.togglePassthrough(workflowId: workflowId, newValue: newValue))
}
.font(.caption)
Spacer()
if trigger.shortcuts.count == 1 {
Text("Hold for")
NumberTextField(text: $holdDurationText) {
onAction(.updateHoldDuration(workflowId: workflowId, holdDuration: Double($0)))
}
.textFieldStyle(.zen(.init(backgroundColor: Color(nsColor: .controlColor).opacity(0.5), font: .caption, padding: .small)))
.frame(maxWidth: 32)
Text("seconds")
}
}
.font(.caption2)
}
.padding(.horizontal, 8)
.enableInjection()
}
}
struct KeyboardTriggerView_Previews: PreviewProvider {
@Namespace static var namespace
@FocusState static var focus: AppFocus?
static var previews: some View {
WorkflowKeyboardTriggerView(namespace: namespace,
workflowId: UUID().uuidString,
focus: $focus,
trigger: .init(passthrough: false, shortcuts: [
.empty()
]),
keyboardShortcutSelectionManager: .init(),
onAction: {
_ in
})
.designTime()
.padding()
}
}