Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions osdep/mac/input_helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class InputHelper: NSObject {
}
}

@discardableResult @objc func command(_ cmd: String) -> Bool {
@discardableResult func command(_ cmd: String) -> Bool {
lock.withLock {
guard let input = input else { return false }
let cCmd = UnsafePointer<Int8>(strdup(cmd))
Expand All @@ -189,6 +189,15 @@ class InputHelper: NSObject {
}
}

func command(args: [String]) {
lock.withLock {
guard let input = input, !args.isEmpty else { return }
var cArgs: [UnsafePointer<CChar>?] = args.map { UnsafePointer(strdup($0)) } + [nil]
mp_input_run_cmd(input, &cArgs)
cArgs.forEach { free(UnsafeMutablePointer(mutating: $0)) }
}
}

private func mapType(_ type: NSEvent.EventType) -> Int32 {
let typeMapping: [NSEvent.EventType: UInt32] = [
.keyDown: MP_KEY_STATE_DOWN,
Expand Down Expand Up @@ -258,7 +267,7 @@ class InputHelper: NSObject {
(NSEvent.modifierFlags.contains(.shift) ? "append" : "replace")
let fileClean = cleanPath(file: file)

command("loadfile \"\(fileClean)\" \(action)")
command(args: ["loadfile", fileClean, action])
}
}

Expand Down
2 changes: 1 addition & 1 deletion osdep/mac/menu_bar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class MenuBar: Menu, EventSubscriber {

@objc func openPlaylist() {
guard let file = dialog.openPlaylist(path: currentDir) else { return }
input.command("loadlist \"\(file)\"")
input.command(args: ["loadlist", file])
}

@objc func openUrl() {
Expand Down
Loading