-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
CommandViewModel.swift
167 lines (146 loc) · 4.75 KB
/
CommandViewModel.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
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
156
157
158
159
160
161
162
163
164
165
166
167
import Apps
import Bonzai
import CoreTransferable
import Foundation
struct CommandViewModel: Codable, Hashable, Identifiable, Transferable {
static var transferRepresentation: some TransferRepresentation {
CodableRepresentation(contentType: .command)
}
struct MetaData: Identifiable, Codable, Hashable, Sendable {
var id: String
var delay: Double?
var name: String
var namePlaceholder: String
var isEnabled: Bool
var notification: Command.Notification?
var icon: Icon?
var variableName: String
init(id: String = UUID().uuidString,
delay: Double? = nil,
name: String,
namePlaceholder: String,
isEnabled: Bool = true,
notification: Command.Notification? = nil,
icon: Icon? = nil,
variableName: String = "") {
self.id = id
self.delay = delay
self.name = name
self.namePlaceholder = namePlaceholder
self.isEnabled = isEnabled
self.notification = notification
self.icon = icon
self.variableName = variableName
}
}
var id: String { meta.id }
var meta: MetaData
var kind: Kind
enum Kind: Codable, Hashable, Identifiable, Sendable {
var id: String { (self as (any Identifiable<String>)).id }
case application(ApplicationModel)
case builtIn(BuiltInModel)
case open(OpenModel)
case keyboard(KeyboardModel)
case script(ScriptModel)
case plain
case shortcut(ShortcutModel)
case text(TextModel)
case systemCommand(SystemModel)
case menuBar(MenuBarModel)
case mouse(MouseModel)
case uiElement(UIElementCommand)
case windowManagement(WindowManagementModel)
struct ApplicationModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var placheolder: String { "Open/Close/Switch to Application …" }
var action: String
var inBackground: Bool
var hideWhenRunning: Bool
var ifNotRunning: Bool
var addToStage: Bool
}
struct BuiltInModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var name: String
var placheolder: String { "Run Built-In Action …" }
var kind: BuiltInCommand.Kind
}
struct OpenModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var placheolder: String { "Open …" }
var path: String
var applicationPath: String?
var appName: String?
var applications: [Application]
}
struct KeyboardModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var placeholder: String { "Invoke Keyboard Shortcut …" }
var keys: [KeyShortcut]
}
struct MouseModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var placeholder: String { "Control Mouse …" }
var kind: MouseCommand.Kind
}
struct MenuBarModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var placeholder: String { "Click MenuBar Item …" }
var application: Application?
var tokens: [MenuBarCommand.Token]
init(id: String, application: Application? = nil, tokens: [MenuBarCommand.Token]) {
self.id = id
self.application = application
self.tokens = tokens
}
}
struct ScriptModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var placeholder: String { "Run Script …" }
var source: ScriptCommand.Source
var scriptExtension: ScriptCommand.Kind
var variableName: String
var execution: Workflow.Execution
}
struct ShortcutModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var placeholder: String { "Run Shortcut …" }
var shortcutIdentifier: String
}
struct SystemModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var placeholder: String { "Run System Shortcut …" }
var kind: SystemCommand.Kind
}
struct TypeModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var mode: TextCommand.TypeCommand.Mode
var placeholder: String { "Type input …" }
var input: String
}
struct TextModel: Codable, Hashable, Identifiable, Sendable {
var id: String { kind.id }
var placeholder: String {
switch kind {
case .type(let model): model.placeholder
}
}
let kind: Kind
enum Kind: Codable, Hashable, Identifiable, Sendable {
var id: String {
switch self {
case .type(let model): model.id
}
}
case type(TypeModel)
}
}
struct WindowManagementModel: Codable, Hashable, Identifiable, Sendable {
let id: String
var placeholder: String { "Control Window…" }
var kind: WindowCommand.Kind
var animationDuration: Double
}
}
}