mirror of https://github.com/mpv-player/mpv
mac/event: only initialise an EventHelper when necessary
This commit is contained in:
parent
b77d5386c3
commit
a46ce9e28c
|
@ -39,8 +39,9 @@ class AppHub: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func initMpv(_ mpv: OpaquePointer) {
|
@objc func initMpv(_ mpv: OpaquePointer) {
|
||||||
self.mpv = mpv
|
event = EventHelper(self, mpv)
|
||||||
event = EventHelper(mpv)
|
self.mpv = event?.mpv
|
||||||
|
|
||||||
#if HAVE_MACOS_MEDIA_PLAYER
|
#if HAVE_MACOS_MEDIA_PLAYER
|
||||||
remote?.registerEvents()
|
remote?.registerEvents()
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,7 +55,7 @@ class AppHub: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func initCocoaCb() {
|
@objc func initCocoaCb() {
|
||||||
guard let app = NSApp as? Application else { return }
|
guard let app = NSApp as? Application, let mpv = mpv else { return }
|
||||||
DispatchQueue.main.sync { app.initCocoaCb(mpv) }
|
DispatchQueue.main.sync { app.initCocoaCb(mpv) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,17 @@ extension EventHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EventHelper: NSObject {
|
public class EventHelper: NSObject {
|
||||||
|
unowned let appHub: AppHub
|
||||||
var mpv: OpaquePointer?
|
var mpv: OpaquePointer?
|
||||||
var events: [String:[Int:EventSubscriber]] = [:]
|
var events: [String:[Int:EventSubscriber]] = [:]
|
||||||
|
|
||||||
@objc init(_ mpvHandle: OpaquePointer) {
|
@objc init?(_ appHub: AppHub, _ mpvHandle: OpaquePointer) {
|
||||||
|
if !appHub.isApplication {
|
||||||
|
mpv_destroy(mpvHandle)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
self.appHub = appHub
|
||||||
self.mpv = mpvHandle
|
self.mpv = mpvHandle
|
||||||
super.init()
|
super.init()
|
||||||
mpv_set_wakeup_callback(mpvHandle, wakeup, TypeHelper.bridge(obj: self))
|
mpv_set_wakeup_callback(mpvHandle, wakeup, TypeHelper.bridge(obj: self))
|
||||||
|
|
Loading…
Reference in New Issue