diff options
author | der richter <der.richter@gmx.de> | 2024-04-03 20:12:31 +0200 |
---|---|---|
committer | der richter <der.richter@gmx.de> | 2024-04-04 19:39:27 +0200 |
commit | 70eba5e83191d82660dda1ac327057d4504d0b15 (patch) | |
tree | d20799f0d024e759260c7c0fcff17a321d6df1f6 | |
parent | c555cfccfeb6ad658c328873b250a0f0409eb906 (diff) | |
download | mpv-70eba5e83191d82660dda1ac327057d4504d0b15.tar.bz2 mpv-70eba5e83191d82660dda1ac327057d4504d0b15.tar.xz |
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.
-rw-r--r-- | osdep/mac/app_hub.swift | 7 | ||||
-rw-r--r-- | osdep/mac/input_helper.swift | 11 |
2 files changed, 12 insertions, 6 deletions
diff --git a/osdep/mac/app_hub.swift b/osdep/mac/app_hub.swift index 44373b17a6..e86e707dd3 100644 --- a/osdep/mac/app_hub.swift +++ b/osdep/mac/app_hub.swift @@ -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 { diff --git a/osdep/mac/input_helper.swift b/osdep/mac/input_helper.swift index 52a5404f0a..0e4ec1f55c 100644 --- a/osdep/mac/input_helper.swift +++ b/osdep/mac/input_helper.swift @@ -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 } |