在 NPAPI 插件中处理 CGEventTaps
我正在尝试创建一个 NPAPI 插件来监听 macbook 上的媒体键并将其传递给 javascript 来控制 pandora 或 soundcloud 等内容。我正在使用 Spotify 的 SPMediaKeyTap 库,它只是包装在单独线程上运行的 CGEventTap。
我的问题是我使用 npn_invoke 回调 JavaScript。这正常工作,但是当它从 CGEventTap 回调触发时,它会使插件崩溃。我意识到这需要从插件线程运行,并且我尝试通过使用 [NSObject PerformSelectorOnMainThread] 和 [NSObject PerformSelector:onThread] 以及我存储在主线程中的线程将其传递回主线程插件线程创建方法。这两种解决方案在任何 npn 调用上仍然会崩溃。处理 CGEventTap 事件时是否还有其他原因导致状态对于 NPN 浏览器交互调用无效?
I'm trying to create an NPAPI plugin to listen to the Media Keys on a macbook and pass that to javascript to control things like pandora or soundcloud. I'm using Spotify's SPMediaKeyTap library, which just wraps CGEventTap running on a separate thread.
My problem is that I use npn_invoke to call back to javascript. This works normally, but when it's triggered from the CGEventTap callback, it crashes the plugin. I realize this needs to be run from the plugin thread, and I've tried to pass it back to the main thread both by using [NSObject performSelectorOnMainThread] and [NSObject performSelector:onThread] with the thread i've stored away in the main plugin threads create method. Both of these solutions still crash on any npn call. Is there anything else that goes on when handling a CGEventTap event that causes state to be invalid for NPN browser interaction calls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要尝试通过像现在这样保存线程来再次猜测线程模型;只需使用performSelectorOnMainThread 来调用NPN 方法。我一直这样做,而且效果很好,所以我猜测您的跨线程编组方法的某些内容没有按其需要的方式工作。
Don't try to second guess the threading model by saving the thread like you are; just use performSelectorOnMainThread to call NPN methods. I do this all the time and it works fine, so I'm guessing that something with your method of cross-thread marshalling isn't working the way it needs to.