mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
show proper error when hotkey updated
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user