mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +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 jetpack = require('fs-jetpack')
|
||||||
const mainWindow = require('./main-window')
|
const mainWindow = require('./main-window')
|
||||||
const nodeIpc = require('@rokt33r/node-ipc')
|
const nodeIpc = require('@rokt33r/node-ipc')
|
||||||
|
const _ = require('lodash')
|
||||||
|
|
||||||
const OSX = global.process.platform === 'darwin'
|
const OSX = global.process.platform === 'darwin'
|
||||||
|
|
||||||
@@ -73,28 +74,36 @@ function toggleMain () {
|
|||||||
// Init
|
// Init
|
||||||
global.keymap = Object.assign({}, defaultKeymap, getKeymap())
|
global.keymap = Object.assign({}, defaultKeymap, getKeymap())
|
||||||
|
|
||||||
function registerKey (name, callback, broadcast) {
|
function registerKey (name, callback) {
|
||||||
if (broadcast == null) broadcast = true
|
if (_.isString(global.keymap[name]) && global.keymap[name].trim().length > 0) {
|
||||||
|
|
||||||
try {
|
|
||||||
globalShortcut.register(global.keymap[name], callback)
|
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) {
|
function registerAllKeys (broadcast) {
|
||||||
if (broadcast == null) broadcast = true
|
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)
|
registerAllKeys(false)
|
||||||
|
|||||||
Reference in New Issue
Block a user