mac/apphub: fix opening several files at once via Finder or App icon

when dropping more than one file on the App icon or opening via Finder
the open(urls:) event might not pass all files at once in the array, but
may consecutivly call open(urls:) for each of the files or batched in
several arrays.

to fix this append any file passed to the open(urls:) event within 0.1
seconds of each other to the current playlist. the first event uses the
default behaviour.
This commit is contained in:
der richter 2024-04-03 20:12:31 +02:00
parent c555cfccfe
commit 70eba5e831
2 changed files with 12 additions and 6 deletions

View File

@ -38,6 +38,7 @@ class AppHub: NSObject {
let MPV_PROTOCOL: String = "mpv://"
var isApplication: Bool { get { NSApp is Application } }
var openEvents: Int = 0
private override init() {
input = InputHelper()
@ -106,8 +107,10 @@ class AppHub: NSObject {
}.sorted { (strL: String, strR: String) -> Bool in
return strL.localizedStandardCompare(strR) == .orderedAscending
}
log.verbose("Opening dropped files: \(files)")
input.open(files: files)
log.verbose("\(openEvents > 0 ? "Appending" : "Opening") dropped files: \(files)")
input.open(files: files, append: openEvents > 0)
openEvents += 1
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { self.openEvents -= 1 }
}
func getIcon() -> NSImage {

View File

@ -230,14 +230,17 @@ class InputHelper: NSObject {
return Int32(buttonMapping[button] ?? SWIFT_MBTN9 + Int32(button - 5));
}
@objc func open(files: [String]) {
@objc func open(files: [String], append: Bool = false) {
lock.withLock {
guard let input = input else { return }
if (option?.vo.drag_and_drop ?? -1) == -2 { return }
var action = NSEvent.modifierFlags.contains(.shift) ? DND_APPEND : DND_REPLACE
if (option?.vo.drag_and_drop ?? -1) >= 0 {
action = mp_dnd_action(UInt32(option?.vo.drag_and_drop ?? Int32(DND_REPLACE.rawValue)))
var action = DND_APPEND
if !append {
action = NSEvent.modifierFlags.contains(.shift) ? DND_APPEND : DND_REPLACE
if (option?.vo.drag_and_drop ?? -1) >= 0 {
action = mp_dnd_action(UInt32(option?.vo.drag_and_drop ?? Int32(DND_REPLACE.rawValue)))
}
}
let filesClean = files.map{ $0.hasPrefix("file:///.file/id=") ? (URL(string: $0)?.path ?? $0) : $0 }