From 7b19b6b4f2dc72c03aa9be4a3a279b7d6a617dd7 Mon Sep 17 00:00:00 2001 From: Hank Bao Date: Thu, 9 Jul 2015 12:30:37 +0800 Subject: [PATCH 1/3] Update global-shortcut.md Make it clear that the `global-shortcut` module should not be used until the ready event of app module gets emitted. --- docs/api/global-shortcut.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index 871357f89f9f6..95fd5caf1fe8f 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -3,6 +3,7 @@ The `global-shortcut` module can register/unregister a global keyboard shortcut in operating system, so that you can customize the operations for various shortcuts. Note that the shortcut is global, even if the app does not get focused, it will still work. +You should not use this module until the ready event of app module gets emitted. ```javascript var globalShortcut = require('global-shortcut'); From fb99bfac526e7dbbd085d223787841ad714715e1 Mon Sep 17 00:00:00 2001 From: Hank Bao Date: Thu, 9 Jul 2015 17:03:58 +0800 Subject: [PATCH 2/3] Update sample code in global-shortcut.md --- docs/api/global-shortcut.md | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index 95fd5caf1fe8f..d9a77ce6ce309 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -6,23 +6,30 @@ Note that the shortcut is global, even if the app does not get focused, it will You should not use this module until the ready event of app module gets emitted. ```javascript +var app = require('app'); var globalShortcut = require('global-shortcut'); -// Register a 'ctrl+x' shortcut listener. -var ret = globalShortcut.register('ctrl+x', function() { console.log('ctrl+x is pressed'); }) +app.on('ready', function() { + // Register a 'ctrl+x' shortcut listener. + var ret = globalShortcut.register('ctrl+x', function() { + console.log('ctrl+x is pressed'); + }) -if (!ret) { - console.log('registration failed'); -} + if (!ret) { + console.log('registration failed'); + } -// Check whether a shortcut is registered. -console.log(globalShortcut.isRegistered('ctrl+x')); + // Check whether a shortcut is registered. + console.log(globalShortcut.isRegistered('ctrl+x')); +}); -// Unregister a shortcut. -globalShortcut.unregister('ctrl+x'); +app.on('will-quit', function() { + // Unregister a shortcut. + globalShortcut.unregister('ctrl+x'); -// Unregister all shortcuts. -globalShortcut.unregisterAll(); + // Unregister all shortcuts. + globalShortcut.unregisterAll(); +}); ``` ## globalShortcut.register(accelerator, callback) From fc9612a5ed7e71dd02433b9a5ee8e16936356fe4 Mon Sep 17 00:00:00 2001 From: Hank Bao Date: Thu, 9 Jul 2015 22:49:16 +0800 Subject: [PATCH 3/3] Fix sample code indention --- docs/api/global-shortcut.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index d9a77ce6ce309..16399cfbfe49b 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -10,25 +10,25 @@ var app = require('app'); var globalShortcut = require('global-shortcut'); app.on('ready', function() { - // Register a 'ctrl+x' shortcut listener. - var ret = globalShortcut.register('ctrl+x', function() { - console.log('ctrl+x is pressed'); - }) + // Register a 'ctrl+x' shortcut listener. + var ret = globalShortcut.register('ctrl+x', function() { + console.log('ctrl+x is pressed'); + }) - if (!ret) { - console.log('registration failed'); - } + if (!ret) { + console.log('registration failed'); + } - // Check whether a shortcut is registered. - console.log(globalShortcut.isRegistered('ctrl+x')); + // Check whether a shortcut is registered. + console.log(globalShortcut.isRegistered('ctrl+x')); }); app.on('will-quit', function() { - // Unregister a shortcut. - globalShortcut.unregister('ctrl+x'); + // Unregister a shortcut. + globalShortcut.unregister('ctrl+x'); - // Unregister all shortcuts. - globalShortcut.unregisterAll(); + // Unregister all shortcuts. + globalShortcut.unregisterAll(); }); ```