mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-02 12:59:45 +08:00
🚧 WIP: shortcut system
This commit is contained in:
5
src/main/utils/eventBus.js
Normal file
5
src/main/utils/eventBus.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
const bus = new EventEmitter()
|
||||
|
||||
export default bus
|
||||
32
src/main/utils/shortKeyRegister.js
Normal file
32
src/main/utils/shortKeyRegister.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user