Skip to content

Commit 261b076

Browse files
committed
优化:Hotkey触发方法优化
1 parent 1e3d57d commit 261b076

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

electron/mapi/manager/window/index.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ const removeDetachWindows = (win: BrowserWindow) => {
3737
detachWindows.delete(win.webContents)
3838
}
3939

40+
const checkForHotkey = async (view: PluginContext, input: Electron.Input) => {
41+
if (view._event && view._event['Hotkey']) {
42+
const hotkey = HotKeyUtil.getFromEvent(input)
43+
if (hotkey) {
44+
view._event['Hotkey'].forEach(({id, hotkeys}) => {
45+
if (HotKeyUtil.match(hotkeys, hotkey)) {
46+
executePluginHooks(view as BrowserView, 'Hotkey', {id, hotkey});
47+
}
48+
})
49+
}
50+
}
51+
}
52+
4053
export const ManagerWindow = {
4154
listBrowserViews(): BrowserView[] {
4255
return Array.from(browserViews.values())
@@ -279,16 +292,7 @@ export const ManagerWindow = {
279292
}
280293
}
281294
} else if (input.type === 'keyDown') {
282-
if ((view as PluginContext)._event && (view as PluginContext)._event['Hotkey']) {
283-
const hotkey = HotKeyUtil.getFromEvent(input)
284-
if (hotkey) {
285-
(view as PluginContext)._event['Hotkey'].forEach(({id, hotkeys}) => {
286-
if (HotKeyUtil.match(hotkeys, hotkey)) {
287-
executePluginHooks(view as BrowserView, 'Hotkey', {id, hotkey});
288-
}
289-
})
290-
}
291-
}
295+
checkForHotkey(view as any, input)
292296
}
293297
})
294298
const windowOption = {
@@ -499,16 +503,7 @@ export const ManagerWindow = {
499503
});
500504
win.webContents.on('before-input-event', (event, input) => {
501505
if (input.type === 'keyDown') {
502-
if ((view as PluginContext)._event && (view as PluginContext)._event['Hotkey']) {
503-
const hotkey = HotKeyUtil.getFromEvent(input)
504-
if (hotkey) {
505-
(view as PluginContext)._event['Hotkey'].forEach(({id, hotkeys}) => {
506-
if (HotKeyUtil.match(hotkeys, hotkey)) {
507-
executePluginHooks(view as BrowserView, 'Hotkey', {id, hotkey});
508-
}
509-
})
510-
}
511-
}
506+
checkForHotkey(view as any, input)
512507
}
513508
});
514509
if (isMac) {

0 commit comments

Comments
 (0)