在Electron中注册全局快捷方式时发生致命错误

lhc*_*chc 2 keyboard-shortcuts electron

根据文档页面,我尝试使用Electron的global-shortcut模块注册全局键盘快捷键。(https://github.com/atom/electron/blob/master/docs/api/global-shortcut.md

但是,当我运行电子版时,在控制台中收到以下错误:

[20097:0608/181936:FATAL:global_shortcut_listener_x11.cc(49)] Check failed: BrowserThread::CurrentlyOn(BrowserThread::UI). 
Run Code Online (Sandbox Code Playgroud)

我在Ubuntu 14.04 LTS上运行Electron。我想问这个错误是否是特定于平台的。我从文档页面错过了任何步骤吗?如果没有,是否有任何方法可以解决此错误?谢谢。

小智 5

在注册快捷方式之前,您的应用程序应该已经准备就绪。这是一个例子:

var app = require('app');  
var globalShortcut = require('global-shortcut');

// Your app must be ready before the registration
app.on('ready', function() {
    console.log('Your app is ready!');

    // You can now register your shortcuts
    globalShortcut.register('ctrl+alt+j', function() {
        console.log('You fired ctrl+alt+j !!!');
    });
});
Run Code Online (Sandbox Code Playgroud)