Skip to content

Commit

Permalink
Don't use API from macOS 14
Browse files Browse the repository at this point in the history
asyncAndWait that returns T is from macOS 14

This commit fixes GH actions
  • Loading branch information
nikitabobko committed Dec 1, 2023
1 parent 96522bc commit d1c07c5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ name: Build

on:
push:
branches: [ "main" ]
tags: [ "v**" ]
branches:
- 'main'
- 'bobko/**'
pull_request:
branches: [ "main" ]
schedule:
Expand Down
19 changes: 11 additions & 8 deletions src/server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func startServer() {
DispatchQueue.global().async {
while true {
guard let connection = try? socket.acceptClientConnection() else { continue }
DispatchQueue.global().async { newConnection(connection) }
Task { await newConnection(connection) }
}
}
}
Expand All @@ -27,7 +27,7 @@ func sendCommandToReleaseServer(command: String) {
_ = try? Socket.wait(for: [socket], timeout: 0, waitForever: true)
}

private func newConnection(_ socket: Socket) { // todo add exit codes
private func newConnection(_ socket: Socket) async { // todo add exit codes
defer {
debug("Close connection")
socket.close()
Expand All @@ -37,8 +37,11 @@ private func newConnection(_ socket: Socket) { // todo add exit codes
guard let string = (try? socket.readString()) else { return }
let (action, error1) = parseCommand(string).getOrNils()
let (query, error2) = parseQueryCommand(string).getOrNils()
if DispatchQueue.main.asyncAndWait(execute: { !TrayMenuModel.shared.isEnabled }) &&
!isAllowedToRunWhenDisabled(query, action) {
guard let isEnabled = await Task(operation: { @MainActor in TrayMenuModel.shared.isEnabled }).result.getOrNil() else {
_ = try? socket.write(from: "Unknown failure during isEnabled server state access")
continue
}
if !isEnabled && !isAllowedToRunWhenDisabled(query, action) {
_ = try? socket.write(from: "\(Bundle.appName) server is disabled and doesn't accept commands. " +
"You can use 'aerospace enable on' to enable the server")
continue
Expand All @@ -52,22 +55,22 @@ private func newConnection(_ socket: Socket) { // todo add exit codes
continue
}
if let action {
DispatchQueue.main.asyncAndWait {
_ = await Task { @MainActor in
refreshSession {
var focused = CommandSubject.focused // todo restore subject from "exec session"
action.run(&focused)
}
}
}.result
_ = try? socket.write(from: "PASS")
continue
}
if let query {
DispatchQueue.main.asyncAndWait {
await Task { @MainActor in
refreshSession {
let result = query.run()
_ = try? socket.write(from: result)
}
}
}.result
continue
}
error("Unreachable")
Expand Down
9 changes: 9 additions & 0 deletions src/util/ResultEx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ extension Result {
}
}

func getOrNil() -> Success? {
switch self {
case .success(let success):
return success
case .failure:
return nil
}
}

func getOrNils() -> (Success?, Failure?) {
switch self {
case .success(let success):
Expand Down

0 comments on commit d1c07c5

Please sign in to comment.