11'use strict' ;
22const path = require ( 'path' ) ;
33const electron = require ( 'electron' ) ;
4- const electronLocalshortcut = require ( 'electron-localshortcut' ) ;
54const windowStateKeeper = require ( 'electron-window-state' ) ;
5+ const isDev = require ( 'electron-is-dev' ) ;
66const appMenu = require ( './menu' ) ;
77const { appUpdater } = require ( './autoupdater' ) ;
88const { crashHandler } = require ( './crash-reporter' ) ;
@@ -14,7 +14,10 @@ const { app, ipcMain } = electron;
1414const BadgeSettings = require ( './../renderer/js/pages/preference/badge-settings.js' ) ;
1515
1616// Adds debug features like hotkeys for triggering dev tools and reload
17- require ( 'electron-debug' ) ( ) ;
17+ // in development mode
18+ if ( isDev ) {
19+ require ( 'electron-debug' ) ( ) ;
20+ }
1821
1922// Prevent window being garbage collected
2023let mainWindow ;
@@ -94,9 +97,6 @@ function createMainWindow() {
9497 win . hide ( ) ;
9598 }
9699 }
97-
98- // Unregister all the shortcuts so that they don't interfare with other apps
99- electronLocalshortcut . unregisterAll ( mainWindow ) ;
100100 } ) ;
101101
102102 win . setTitle ( 'Zulip' ) ;
@@ -124,33 +124,12 @@ function createMainWindow() {
124124 return win ;
125125}
126126
127- function registerLocalShortcuts ( page ) {
128- // Somehow, reload action cannot be overwritten by the menu item
129- electronLocalshortcut . register ( mainWindow , 'CommandOrControl+R' , ( ) => {
130- page . send ( 'reload-current-viewer' ) ;
131- } ) ;
132-
133- // Also adding these shortcuts because some users might want to use it instead of CMD/Left-Right
134- electronLocalshortcut . register ( mainWindow , 'CommandOrControl+[' , ( ) => {
135- page . send ( 'back' ) ;
136- } ) ;
137-
138- electronLocalshortcut . register ( mainWindow , 'CommandOrControl+]' , ( ) => {
139- page . send ( 'forward' ) ;
140- } ) ;
141- }
142-
143127// eslint-disable-next-line max-params
144128app . on ( 'certificate-error' , ( event , webContents , url , error , certificate , callback ) => {
145129 event . preventDefault ( ) ;
146130 callback ( true ) ;
147131} ) ;
148132
149- app . on ( 'window-all-closed' , ( ) => {
150- // Unregister all the shortcuts so that they don't interfare with other apps
151- electronLocalshortcut . unregisterAll ( mainWindow ) ;
152- } ) ;
153-
154133app . on ( 'activate' , ( ) => {
155134 if ( ! mainWindow ) {
156135 mainWindow = createMainWindow ( ) ;
@@ -165,8 +144,6 @@ app.on('ready', () => {
165144
166145 const page = mainWindow . webContents ;
167146
168- registerLocalShortcuts ( page ) ;
169-
170147 page . on ( 'dom-ready' , ( ) => {
171148 mainWindow . show ( ) ;
172149 } ) ;
@@ -232,30 +209,15 @@ app.on('ready', () => {
232209 } ) ;
233210
234211 ipcMain . on ( 'register-server-tab-shortcut' , ( event , index ) => {
235- electronLocalshortcut . register ( mainWindow , `CommandOrControl+${ index } ` , ( ) => {
236- // Array index == Shown index - 1
237- page . send ( 'switch-server-tab' , index - 1 ) ;
238- } ) ;
239- } ) ;
240-
241- ipcMain . on ( 'local-shortcuts' , ( event , enable ) => {
242- if ( enable ) {
243- registerLocalShortcuts ( page ) ;
244- } else {
245- electronLocalshortcut . unregisterAll ( mainWindow ) ;
246- }
212+ // Array index == Shown index - 1
213+ page . send ( 'switch-server-tab' , index - 1 ) ;
247214 } ) ;
248215
249216 ipcMain . on ( 'toggleAutoLauncher' , ( event , AutoLaunchValue ) => {
250217 setAutoLaunch ( AutoLaunchValue ) ;
251218 } ) ;
252219} ) ;
253220
254- app . on ( 'will-quit' , ( ) => {
255- // Unregister all the shortcuts so that they don't interfare with other apps
256- electronLocalshortcut . unregisterAll ( mainWindow ) ;
257- } ) ;
258-
259221app . on ( 'before-quit' , ( ) => {
260222 isQuitting = true ;
261223} ) ;
0 commit comments