Skip to content

Commit 2fb9efb

Browse files
authored
Merge pull request #335 from zulip/electron-shortcut-fix
Remove electron-localshortcut completely
2 parents 06ad44b + 7245b6a commit 2fb9efb

File tree

4 files changed

+9
-52
lines changed

4 files changed

+9
-52
lines changed

app/main/index.js

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22
const path = require('path');
33
const electron = require('electron');
4-
const electronLocalshortcut = require('electron-localshortcut');
54
const windowStateKeeper = require('electron-window-state');
5+
const isDev = require('electron-is-dev');
66
const appMenu = require('./menu');
77
const { appUpdater } = require('./autoupdater');
88
const { crashHandler } = require('./crash-reporter');
@@ -14,7 +14,10 @@ const { app, ipcMain } = electron;
1414
const 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
2023
let 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
144128
app.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-
154133
app.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-
259221
app.on('before-quit', () => {
260222
isQuitting = true;
261223
});

app/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
"InstantMessaging"
2828
],
2929
"dependencies": {
30-
"electron-debug": "1.4.0",
3130
"electron-is-dev": "0.3.0",
32-
"electron-localshortcut": "2.0.2",
3331
"electron-log": "2.2.7",
3432
"electron-spellchecker": "1.1.2",
3533
"electron-updater": "2.16.2",

app/renderer/js/main.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class ServerManagerView {
8383
} else {
8484
this.openSettings('Servers');
8585
}
86-
ipcRenderer.send('local-shortcuts', true);
8786
}
8887

8988
initServer(server, index) {
@@ -257,9 +256,6 @@ class ServerManagerView {
257256
// Clear DOM elements
258257
this.$tabsContainer.innerHTML = '';
259258
this.$webviewsContainer.innerHTML = '';
260-
261-
// Destroy shortcuts
262-
ipcRenderer.send('local-shortcuts', false);
263259
}
264260

265261
reloadView() {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@
115115
"chai": "4.1.1",
116116
"spectron": "3.7.2",
117117
"xo": "0.18.2",
118-
"pre-commit": "1.2.2"
118+
"pre-commit": "1.2.2",
119+
"electron-debug": "1.4.0"
119120
},
120121
"xo": {
121122
"parserOptions": {

0 commit comments

Comments
 (0)