-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
BuildInCommand.swift
57 lines (50 loc) · 1.46 KB
/
BuildInCommand.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
import Foundation
struct BuiltInCommand: MetaDataProviding {
var meta: Command.MetaData
var name: String {
switch kind {
case .quickRun:
return "Open Quick Run"
case .repeatLastKeystroke:
return "Repeat last keystroke"
case .recordSequence:
return "Record sequence"
}
}
let kind: Kind
enum Kind: String, Codable, Hashable, CaseIterable, Identifiable, Sendable {
public var id: String { return self.rawValue }
case quickRun
case repeatLastKeystroke
case recordSequence
public var displayValue: String {
switch self {
case .quickRun:
return "Open Quick Run dialog"
case .repeatLastKeystroke:
return "Repeat last keystroke"
case .recordSequence:
return "Record sequence"
}
}
}
enum MigrationCodingKeys: String, CodingKey {
case id, kind
case isEnabled = "enabled"
case notification
}
init(id: String = UUID().uuidString,
kind: Kind, notification: Bool) {
self.kind = kind
self.meta = .init(id: id, name: kind.displayValue, isEnabled: true, notification: notification)
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
do {
self.meta = try container.decode(Command.MetaData.self, forKey: .meta)
} catch {
self.meta = try MetaDataMigrator.migrate(decoder)
}
self.kind = try container.decode(BuiltInCommand.Kind.self, forKey: .kind)
}
}