mirror of https://github.com/mpv-player/mpv
mac/apphub: move opening url into AppHub
This commit is contained in:
parent
2c7e4f5935
commit
d6c621b03b
|
@ -36,6 +36,7 @@ class AppHub: NSObject {
|
||||||
var cocoaCb: CocoaCB?
|
var cocoaCb: CocoaCB?
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
let MPV_PROTOCOL: String = "mpv://"
|
||||||
var isApplication: Bool { get { NSApp is Application } }
|
var isApplication: Bool { get { NSApp is Application } }
|
||||||
|
|
||||||
private override init() {
|
private override init() {
|
||||||
|
@ -88,6 +89,18 @@ class AppHub: NSObject {
|
||||||
#endif
|
#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 {
|
func getIcon() -> NSImage {
|
||||||
guard let iconData = app_bridge_icon(), let icon = NSImage(data: iconData) else {
|
guard let iconData = app_bridge_icon(), let icon = NSImage(data: iconData) else {
|
||||||
return NSImage(size: NSSize(width: 1, height: 1))
|
return NSImage(size: NSSize(width: 1, height: 1))
|
||||||
|
|
|
@ -19,8 +19,6 @@ import Cocoa
|
||||||
|
|
||||||
class Application: NSApplication, NSApplicationDelegate {
|
class Application: NSApplication, NSApplicationDelegate {
|
||||||
var appHub: AppHub { get { return AppHub.shared } }
|
var appHub: AppHub { get { return AppHub.shared } }
|
||||||
let MPV_PROTOCOL: String = "mpv://"
|
|
||||||
|
|
||||||
var playbackThreadId: mp_thread!
|
var playbackThreadId: mp_thread!
|
||||||
var argc: Int32?
|
var argc: Int32?
|
||||||
var argv: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?
|
var argv: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?
|
||||||
|
@ -75,15 +73,7 @@ class Application: NSApplication, NSApplicationDelegate {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
func application(_ application: NSApplication, open urls: [URL]) {
|
func application(_ application: NSApplication, open urls: [URL]) {
|
||||||
let files = urls.map {
|
appHub.open(urls: urls)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationWillFinishLaunching(_ notification: Notification) {
|
func applicationWillFinishLaunching(_ notification: Notification) {
|
||||||
|
|
Loading…
Reference in New Issue