Skip to content

Commit 28e016b

Browse files
committed
Make keyboard command runner main actor
1 parent 96492f5 commit 28e016b

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

App/Sources/Core/Runners/CommandRunner.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,10 @@ final class CommandRunner: CommandRunning, @unchecked Sendable {
389389
output = command.name
390390
}
391391
case .keyboard(let keyboardCommand):
392-
try runners.keyboard.run(keyboardCommand.keyboardShortcuts,
393-
originalEvent: nil,
394-
iterations: keyboardCommand.iterations,
395-
with: eventSource)
392+
try await runners.keyboard.run(keyboardCommand.keyboardShortcuts,
393+
originalEvent: nil,
394+
iterations: keyboardCommand.iterations,
395+
with: eventSource)
396396
try await Task.sleep(for: .milliseconds(1))
397397
output = command.name
398398
case .menuBar(let menuBarCommand):

App/Sources/Core/Runners/KeyboardCommandRunner.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ final class KeyboardCommandRunner: @unchecked Sendable {
2323
}
2424

2525
@discardableResult
26+
@MainActor
2627
func run(_ keyboardShortcuts: [KeyShortcut],
2728
originalEvent: CGEvent? = nil,
2829
iterations: Int,

App/Sources/Core/Runners/MacroCoordinator.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ final class MacroCoordinator: @unchecked Sendable {
8080

8181
state = .running
8282

83-
task = Task.detached { @MainActor [machPort, workflowRunner, keyboardRunner, weak self] in
83+
task = Task.detached { [machPort, workflowRunner, keyboardRunner, weak self] in
8484
do {
8585
for _ in 0..<iterations {
8686
let specialKeys: [Int] = [kVK_Return, kVK_Escape]
@@ -101,11 +101,11 @@ final class MacroCoordinator: @unchecked Sendable {
101101
for command in workflow.commands {
102102
try Task.checkCancellation()
103103
if case .keyboard(let command) = command {
104-
_ = try keyboardRunner.run(command.keyboardShortcuts,
105-
originalEvent: nil,
106-
iterations: command.iterations,
107-
isRepeating: false,
108-
with: machPortEvent.eventSource)
104+
_ = try await keyboardRunner.run(command.keyboardShortcuts,
105+
originalEvent: nil,
106+
iterations: command.iterations,
107+
isRepeating: false,
108+
with: machPortEvent.eventSource)
109109
try await Task.sleep(for: .milliseconds(5))
110110
}
111111
}
@@ -116,11 +116,11 @@ final class MacroCoordinator: @unchecked Sendable {
116116
}
117117
}
118118
}
119-
await MainActor.run {
119+
await MainActor.run { [weak self] in
120120
self?.state = .idle
121121
}
122122
} catch {
123-
await MainActor.run {
123+
await MainActor.run { [weak self] in
124124
self?.state = .idle
125125
}
126126
}

App/Sources/Core/UserSpace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ final class UserSpace: @unchecked Sendable {
139139
return interpolatedString
140140
}
141141

142-
func terminalEnvironment() -> [String: String] {
142+
func terminalEnvironment() async -> [String: String] {
143143
var environment = ProcessInfo.processInfo.environment
144144
environment["TERM"] = "xterm-256color"
145145
environment[.selectedText] = selectedText

0 commit comments

Comments
 (0)