mac/event: only initialise an EventHelper when necessary

This commit is contained in:
der richter 2024-03-24 14:11:13 +01:00
parent b77d5386c3
commit a46ce9e28c
2 changed files with 12 additions and 4 deletions

View File

@ -39,8 +39,9 @@ class AppHub: NSObject {
}
@objc func initMpv(_ mpv: OpaquePointer) {
self.mpv = mpv
event = EventHelper(mpv)
event = EventHelper(self, mpv)
self.mpv = event?.mpv
#if HAVE_MACOS_MEDIA_PLAYER
remote?.registerEvents()
#endif
@ -54,7 +55,7 @@ class AppHub: NSObject {
}
@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) }
}

View File

@ -58,10 +58,17 @@ extension EventHelper {
}
public class EventHelper: NSObject {
unowned let appHub: AppHub
var mpv: OpaquePointer?
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
super.init()
mpv_set_wakeup_callback(mpvHandle, wakeup, TypeHelper.bridge(obj: self))