Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Dec 16, 2023
1 parent cc84a40 commit bc66614
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
5 changes: 2 additions & 3 deletions src/AeroSpaceApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import SwiftUI

@main
struct AeroSpaceApp: App {
var hotKeys: [HotKey] = [] // Keep hotkeys in memory
@StateObject var viewModel = TrayMenuModel.shared

init() {
Expand All @@ -26,9 +25,9 @@ struct AeroSpaceApp: App {
refreshSession {
var focused = CommandSubject.focused
if startedAtLogin {
config.afterLoginCommand.run(&focused)
_ = config.afterLoginCommand.run(&focused)
}
config.afterStartupCommand.run(&focused)
_ = config.afterStartupCommand.run(&focused)
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/command/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ extension Command {
return [self].run(&subject, &stdout)
}

func run(_ subject: inout CommandSubject) -> Bool {
check(Thread.current.isMainThread)
var devNull = ""
return run(&subject, &devNull)
}

func runOnFocusedSubject() {
check(Thread.current.isMainThread)
var focused = CommandSubject.focused
_ = run(&focused)
var devNull = ""
_ = run(&focused, &devNull)
}

var isExec: Bool { self is ExecAndWaitCommand || self is ExecAndForgetCommand }
Expand Down
15 changes: 15 additions & 0 deletions src/command/parse/parseCmdArgsUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ enum ParsedCmd<T> {
return .failure(fail)
}
}

func unwrap() -> (T?, String?, String?) {
var command: T? = nil
var error: String? = nil
var help: String? = nil
switch self {
case .cmd(let _command):
command = _command
case .help(let _help):
help = _help
case .failure(let _error):
error = _error
}
return (command, help, error)
}
}

func parseRawCmdArgs<T : RawCmdArgs>(_ raw: T, _ args: [String]) -> ParsedCmd<T> {
Expand Down
18 changes: 1 addition & 17 deletions src/server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,7 @@ private func newConnection(_ socket: Socket) async { // todo add exit codes
while true {
_ = try? Socket.wait(for: [socket], timeout: 0, waitForever: true)
guard let string = (try? socket.readString()) else { return }
let command: Command?
let err: String?
let help: String?
switch parseCommand(string) {
case .cmd(let _command):
command = _command
help = nil
err = nil
case .help(let _help):
command = nil
help = _help
err = nil
case .failure(let _error):
command = nil
help = nil
err = _error
}
let (command, help, err) = parseCommand(string).unwrap()
guard let isEnabled = await Task(operation: { @MainActor in TrayMenuModel.shared.isEnabled }).result.getOrNil() else {
_ = try? socket.write(from: "1Unknown failure during isEnabled server state access")
continue
Expand Down

0 comments on commit bc66614

Please sign in to comment.