From d6c621b03beef1a38e66b33507a13e329e753383 Mon Sep 17 00:00:00 2001 From: der richter Date: Sun, 31 Mar 2024 02:29:31 +0100 Subject: [PATCH] mac/apphub: move opening url into AppHub --- osdep/mac/app_hub.swift | 13 +++++++++++++ osdep/mac/application.swift | 12 +----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/osdep/mac/app_hub.swift b/osdep/mac/app_hub.swift index cbb4e2b6a5..a46bdc87c7 100644 --- a/osdep/mac/app_hub.swift +++ b/osdep/mac/app_hub.swift @@ -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)) diff --git a/osdep/mac/application.swift b/osdep/mac/application.swift index ee5ee8eea2..086b6eff66 100644 --- a/osdep/mac/application.swift +++ b/osdep/mac/application.swift @@ -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?>? @@ -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) {