🚧 WIP: shortcut system

This commit is contained in:
PiEgg
2019-09-10 14:38:08 +08:00
parent fe9e19a84d
commit f21940ef23
7 changed files with 149 additions and 40 deletions

View File

@@ -0,0 +1,5 @@
import { EventEmitter } from 'events'
const bus = new EventEmitter()
export default bus

View File

@@ -0,0 +1,32 @@
import bus from '../utils/eventBus'
/**
*
* @param {string} name
*/
const shortKeyHandler = (name) => {
if (name.includes('picgo:')) {
bus.emit(name)
} else if (name.includes('picgo-plugin-')) {
// TODO: 处理插件快捷键
}
}
// 初始化阶段的注册
const initShortKeyRegister = (globalShortcut, shortKeys) => {
let errorList = []
for (let i in shortKeys) {
try {
if (shortKeys[i].enable) {
globalShortcut.register(shortKeys[i].key, () => {
shortKeyHandler(shortKeys[i].name)
})
}
} catch (e) {
errorList.push(shortKeys[i])
}
}
}
export {
initShortKeyRegister
}