mac/apphub: move opening url into AppHub

This commit is contained in:
der richter 2024-03-31 02:29:31 +01:00
parent 2c7e4f5935
commit d6c621b03b
2 changed files with 14 additions and 11 deletions

View File

@ -36,6 +36,7 @@ class AppHub: NSObject {
var cocoaCb: CocoaCB?
#endif
let MPV_PROTOCOL: String = "mpv://"
var isApplication: Bool { get { NSApp is Application } }
private override init() {
@ -88,6 +89,18 @@ class AppHub: NSObject {
#endif
}
func open(urls: [URL]) {
let files = urls.map {
if $0.isFileURL { return $0.path }
var path = $0.absoluteString
if path.hasPrefix(MPV_PROTOCOL) { path.removeFirst(MPV_PROTOCOL.count) }
return path.removingPercentEncoding ?? path
}.sorted { (strL: String, strR: String) -> Bool in
return strL.localizedStandardCompare(strR) == .orderedAscending
}
input.open(files: files)
}
func getIcon() -> NSImage {
guard let iconData = app_bridge_icon(), let icon = NSImage(data: iconData) else {
return NSImage(size: NSSize(width: 1, height: 1))

View File

@ -19,8 +19,6 @@ import Cocoa
class Application: NSApplication, NSApplicationDelegate {
var appHub: AppHub { get { return AppHub.shared } }
let MPV_PROTOCOL: String = "mpv://"
var playbackThreadId: mp_thread!
var argc: Int32?
var argv: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?
@ -75,15 +73,7 @@ class Application: NSApplication, NSApplicationDelegate {
#endif
func application(_ application: NSApplication, open urls: [URL]) {
let files = urls.map {
if $0.isFileURL { return $0.path }
var path = $0.absoluteString
if path.hasPrefix(MPV_PROTOCOL) { path.removeFirst(MPV_PROTOCOL.count) }
return path.removingPercentEncoding ?? path
}.sorted { (strL: String, strR: String) -> Bool in
return strL.localizedStandardCompare(strR) == .orderedAscending
}
appHub.input.open(files: files)
appHub.open(urls: urls)
}
func applicationWillFinishLaunching(_ notification: Notification) {