-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
SystemCommand.swift
108 lines (99 loc) · 5.69 KB
/
SystemCommand.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
import Foundation
struct SystemCommand: MetaDataProviding {
enum Kind: String, Identifiable, Codable, CaseIterable {
var id: String { rawValue }
var displayValue: String {
switch self {
case .activateLastApplication: "Activate Last Application"
case .applicationWindows: "Application Windows"
case .minimizeAllOpenWindows: "Minimize All Open Windows"
case .missionControl: "Mission Control"
case .showDesktop: "Show Desktop"
case .moveFocusToNextWindowGlobal: "Move Focus to Next Window (All Windows)"
case .moveFocusToPreviousWindowGlobal: "Move Focus to Previous window (All Windows)"
case .moveFocusToNextWindow: "Move Focus to Next Window"
case .moveFocusToPreviousWindow: "Move Focus to Previous Window"
case .moveFocusToNextWindowFront: "Move Focus to Next Window of Active Application"
case .moveFocusToPreviousWindowFront: "Move Focus to Previous Window of Active Application"
case .moveFocusToNextWindowUpwards: "Move Focus to Window Upwards"
case .moveFocusToNextWindowOnLeft: "Move Focus to Window on Left"
case .moveFocusToNextWindowOnRight: "Move Focus to Window on Right"
case .moveFocusToNextWindowDownwards: "Move Focus to Window Downwards"
}
}
var symbol: String {
switch self {
case .activateLastApplication: "arrow.counterclockwise.circle"
case .applicationWindows: "rectangle.on.rectangle"
case .minimizeAllOpenWindows: "arrow.down.right.and.arrow.up.left"
case .missionControl: "square.grid.3x3"
case .showDesktop: "desktopcomputer"
case .moveFocusToNextWindowOnLeft: "arrow.left.circle"
case .moveFocusToNextWindowOnRight: "arrow.right.circle"
case .moveFocusToNextWindowUpwards: "arrow.up.circle"
case .moveFocusToNextWindowDownwards: "arrow.down.circle"
case .moveFocusToNextWindowGlobal: "arrow.right.circle"
case .moveFocusToPreviousWindowGlobal: "arrow.left.circle"
case .moveFocusToNextWindow: "arrow.right.to.line.alt"
case .moveFocusToPreviousWindow: "arrow.left.to.line.alt"
case .moveFocusToNextWindowFront: "arrow.forward.circle"
case .moveFocusToPreviousWindowFront: "arrow.backward.circle"
}
}
var iconPath: String {
switch self {
case .activateLastApplication: "/System/Library/CoreServices/Family.app"
case .applicationWindows: "/System/Applications/Mission Control.app/Contents/Resources/AppIcon.icns"
case .moveFocusToNextWindowFront: "/System/Library/CoreServices/WidgetKit Simulator.app/Contents/Resources/AppIcon.icns"
case .moveFocusToPreviousWindowFront: "/System/Library/CoreServices/WidgetKit Simulator.app/Contents/Resources/AppIcon.icns"
case .moveFocusToNextWindow, .moveFocusToNextWindowGlobal: "/System/Library/CoreServices/WidgetKit Simulator.app/Contents/Resources/AppIcon.icns"
case .moveFocusToPreviousWindow, .moveFocusToPreviousWindowGlobal: "/System/Library/CoreServices/WidgetKit Simulator.app/Contents/Resources/AppIcon.icns"
case .minimizeAllOpenWindows: "/System/Applications/Mission Control.app/Contents/Resources/AppIcon.icns"
case .missionControl: "/System/Applications/Mission Control.app/Contents/Resources/AppIcon.icns"
case .showDesktop: "/System/Library/CoreServices/Dock.app/Contents/Resources/Dock.icns"
case .moveFocusToNextWindowOnLeft: "/System/Library/CoreServices/WidgetKit Simulator.app/Contents/Resources/AppIcon.icns"
case .moveFocusToNextWindowOnRight: "/System/Library/CoreServices/WidgetKit Simulator.app/Contents/Resources/AppIcon.icns"
case .moveFocusToNextWindowUpwards: "/System/Library/CoreServices/WidgetKit Simulator.app/Contents/Resources/AppIcon.icns"
case .moveFocusToNextWindowDownwards: "/System/Library/CoreServices/WidgetKit Simulator.app/Contents/Resources/AppIcon.icns"
}
}
case activateLastApplication
case applicationWindows
case minimizeAllOpenWindows
case missionControl
case moveFocusToNextWindowOnLeft
case moveFocusToNextWindowOnRight
case moveFocusToNextWindowUpwards
case moveFocusToNextWindowDownwards
case moveFocusToNextWindowFront
case moveFocusToPreviousWindowFront
case moveFocusToNextWindow
case moveFocusToPreviousWindow
case moveFocusToNextWindowGlobal
case moveFocusToPreviousWindowGlobal
case showDesktop
}
var kind: Kind
var meta: Command.MetaData
init(id: String = UUID().uuidString, name: String, kind: Kind,
notification: Command.Notification? = nil) {
self.kind = kind
self.meta = Command.MetaData(id: id, name: name, isEnabled: true, notification: notification)
}
init(kind: Kind, meta: Command.MetaData) {
self.kind = kind
self.meta = meta
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.kind = try container.decode(Kind.self, forKey: .kind)
do {
self.meta = try container.decode(Command.MetaData.self, forKey: .meta)
} catch {
self.meta = try MetaDataMigrator.migrate(decoder)
}
}
func copy() -> SystemCommand {
SystemCommand(kind: kind, meta: meta.copy())
}
}