@@ -8,6 +8,7 @@ import * as _ from "lodash";
8
8
import * as assert from "assert" ;
9
9
import { app , Menu } from "electron" ;
10
10
import * as shell from "./shell" ;
11
+ import * as electronLocalshortcut from "electron-localshortcut" ;
11
12
12
13
const menuTemplate : MenuItemOptions [ ] = [ ] ;
13
14
@@ -20,27 +21,21 @@ app.on("browser-window-blur", function () {
20
21
_refreshMenu ( ) ;
21
22
} ) ;
22
23
23
- // const systemShortcuts = ["Ctrl+Z", "Ctrl+Y", "Ctrl+X", "Ctrl+C", "Ctrl+V", "Ctrl+A"];
24
-
25
- function registerShortcuts ( menuItem : MenuItemOptions ) {
26
- /* this shouldn't be used
24
+ function registerShortcuts ( win : Electron . BrowserWindow , menuItem : MenuItemOptions ) {
27
25
if ( menuItem . accelerator ) {
28
- if (null == systemShortcuts.find((x) => x === menuItem.accelerator)) {
29
- globalShortcut.register(menuItem.accelerator, menuItem.click as Function);
30
- }
26
+ electronLocalshortcut . register ( win , menuItem . accelerator , menuItem . click as Function ) ;
31
27
}
32
- */
33
28
if ( Array . isArray ( menuItem . submenu ) ) {
34
- menuItem . submenu . forEach ( ( i ) => registerShortcuts ( i ) ) ;
29
+ menuItem . submenu . forEach ( ( i ) => registerShortcuts ( win , i ) ) ;
35
30
}
36
31
}
37
32
38
33
const __refreshMenu = _ . debounce ( function ( ) {
39
34
Menu . setApplicationMenu ( Menu . buildFromTemplate ( _ . cloneDeep ( menuTemplate ) ) ) ;
40
- // globalShortcut.unregisterAll();
41
35
const mainWindow = shell . getMainWindow ( ) ;
36
+ electronLocalshortcut . unregisterAll ( mainWindow ) ;
42
37
if ( mainWindow . isFocused ( ) ) {
43
- menuTemplate . forEach ( ( menuItem ) => registerShortcuts ( menuItem ) ) ;
38
+ menuTemplate . forEach ( ( menuItem ) => registerShortcuts ( mainWindow , menuItem ) ) ;
44
39
}
45
40
} , 100 ) ;
46
41
0 commit comments