From fb8a2eb2e06e2cf5be14975b3be37874d68ef4bc Mon Sep 17 00:00:00 2001 From: Rokt33r Date: Tue, 19 Jan 2016 18:47:35 +0900 Subject: [PATCH] show proper error when hotkey updated --- lib/hotkey.js | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/hotkey.js b/lib/hotkey.js index 631f7dde..0940fe91 100644 --- a/lib/hotkey.js +++ b/lib/hotkey.js @@ -6,6 +6,7 @@ const globalShortcut = electron.globalShortcut const jetpack = require('fs-jetpack') const mainWindow = require('./main-window') const nodeIpc = require('@rokt33r/node-ipc') +const _ = require('lodash') const OSX = global.process.platform === 'darwin' @@ -73,28 +74,36 @@ function toggleMain () { // Init global.keymap = Object.assign({}, defaultKeymap, getKeymap()) -function registerKey (name, callback, broadcast) { - if (broadcast == null) broadcast = true - - try { +function registerKey (name, callback) { + if (_.isString(global.keymap[name]) && global.keymap[name].trim().length > 0) { globalShortcut.register(global.keymap[name], callback) - if (broadcast) { - mainWindow.webContents.send('APP_SETTING_DONE', {}) - } - } catch (err) { - console.log(err) - if (broadcast) { - mainWindow.webContents.send('APP_SETTING_ERROR', { - message: 'Failed to apply hotkey: Invalid format' - }) - } } } function registerAllKeys (broadcast) { if (broadcast == null) broadcast = true - registerKey('toggleFinder', toggleFinder, broadcast) - registerKey('toggleMain', toggleMain, broadcast) + + var errors = [] + try { + registerKey('toggleFinder', toggleFinder) + } catch (err) { + errors.push('toggleFinder') + } + try { + registerKey('toggleMain', toggleMain) + } catch (err) { + errors.push('toggleMain') + } + + if (broadcast) { + if (errors.length === 0) { + mainWindow.webContents.send('APP_SETTING_DONE', {}) + } else { + mainWindow.webContents.send('APP_SETTING_ERROR', { + message: 'Failed to apply hotkey: ' + errors.join(' ') + }) + } + } } registerAllKeys(false)