mirror of https://github.com/mpv-player/mpv
mac: fix crash if we can't get an event tap
without assistive-device permissions the event tap can't be create on
10.14 any more which lead to an assertion.
System Preferences > Security & Privacy > Privacy > Accessibility and
add mpv or your terminal App to the list.
(cherry picked from commit ada4f7c600
)
This commit is contained in:
parent
a985e8ed6b
commit
5b9cf1d0a6
|
@ -375,6 +375,7 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx)
|
||||||
|
|
||||||
- (void)restartMediaKeys
|
- (void)restartMediaKeys
|
||||||
{
|
{
|
||||||
|
if (self->_mk_tap_port)
|
||||||
CGEventTapEnable(self->_mk_tap_port, true);
|
CGEventTapEnable(self->_mk_tap_port, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,10 +411,10 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx)
|
||||||
tap_event_callback,
|
tap_event_callback,
|
||||||
self);
|
self);
|
||||||
|
|
||||||
assert(self->_mk_tap_port != nil);
|
if (self->_mk_tap_port) {
|
||||||
|
|
||||||
NSMachPort *port = (NSMachPort *)self->_mk_tap_port;
|
NSMachPort *port = (NSMachPort *)self->_mk_tap_port;
|
||||||
[[NSRunLoop mainRunLoop] addPort:port forMode:NSRunLoopCommonModes];
|
[[NSRunLoop mainRunLoop] addPort:port forMode:NSRunLoopCommonModes];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,10 +422,12 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx)
|
||||||
{
|
{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
NSMachPort *port = (NSMachPort *)self->_mk_tap_port;
|
NSMachPort *port = (NSMachPort *)self->_mk_tap_port;
|
||||||
|
if (port) {
|
||||||
CGEventTapEnable(self->_mk_tap_port, false);
|
CGEventTapEnable(self->_mk_tap_port, false);
|
||||||
[[NSRunLoop mainRunLoop] removePort:port forMode:NSRunLoopCommonModes];
|
[[NSRunLoop mainRunLoop] removePort:port forMode:NSRunLoopCommonModes];
|
||||||
CFRelease(self->_mk_tap_port);
|
CFRelease(self->_mk_tap_port);
|
||||||
self->_mk_tap_port = nil;
|
self->_mk_tap_port = nil;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue