remove global shortcuts (#1740)
* remove global shortcuts * Add global shortcuts only when the app is in focus Co-authored-by: Devin Binnie <devin.binnie@mattermost.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import fs from 'fs';
|
||||
|
||||
import path from 'path';
|
||||
|
||||
import electron, {BrowserWindow, globalShortcut, IpcMainEvent, IpcMainInvokeEvent, Rectangle} from 'electron';
|
||||
import electron, {BrowserWindow, IpcMainEvent, IpcMainInvokeEvent, Rectangle} from 'electron';
|
||||
import isDev from 'electron-is-dev';
|
||||
import installExtension, {REACT_DEVELOPER_TOOLS} from 'electron-devtools-installer';
|
||||
import log from 'electron-log';
|
||||
@@ -41,7 +41,6 @@ import {
|
||||
SHOW_EDIT_SERVER_MODAL,
|
||||
SHOW_REMOVE_SERVER_MODAL,
|
||||
UPDATE_SHORTCUT_MENU,
|
||||
OPEN_TEAMS_DROPDOWN,
|
||||
UPDATE_LAST_ACTIVE,
|
||||
GET_AVAILABLE_SPELL_CHECKER_LANGUAGES,
|
||||
} from 'common/communication';
|
||||
@@ -798,16 +797,6 @@ function initializeAfterAppReady() {
|
||||
// is the requesting url trusted?
|
||||
callback(urlUtils.isTrustedURL(requestingURL, config.teams));
|
||||
});
|
||||
|
||||
globalShortcut.register(`${process.platform === 'darwin' ? 'Cmd+Ctrl' : 'Ctrl+Shift'}+S`, () => {
|
||||
ipcMain.emit(OPEN_TEAMS_DROPDOWN);
|
||||
});
|
||||
|
||||
if (process.platform === 'linux') {
|
||||
globalShortcut.registerAll(['Alt+F', 'Alt+E', 'Alt+V', 'Alt+H', 'Alt+W', 'Alt+P'], () => {
|
||||
// do nothing because we want to supress the menu popping up
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
@@ -6,13 +6,13 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
|
||||
import {app, BrowserWindow, BrowserWindowConstructorOptions, ipcMain} from 'electron';
|
||||
import {app, BrowserWindow, BrowserWindowConstructorOptions, globalShortcut, ipcMain} from 'electron';
|
||||
import log from 'electron-log';
|
||||
|
||||
import {CombinedConfig} from 'types/config';
|
||||
import {SavedWindowState} from 'types/mainWindow';
|
||||
|
||||
import {SELECT_NEXT_TAB, SELECT_PREVIOUS_TAB, GET_FULL_SCREEN_STATUS} from 'common/communication';
|
||||
import {SELECT_NEXT_TAB, SELECT_PREVIOUS_TAB, GET_FULL_SCREEN_STATUS, OPEN_TEAMS_DROPDOWN} from 'common/communication';
|
||||
import {DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH, MINIMUM_WINDOW_HEIGHT, MINIMUM_WINDOW_WIDTH} from 'common/utils/constants';
|
||||
|
||||
import * as Validator from '../Validator';
|
||||
@@ -174,6 +174,21 @@ function createMainWindow(config: CombinedConfig, options: {linuxAppIcon: string
|
||||
}
|
||||
});
|
||||
|
||||
// Only add shortcuts when window is in focus
|
||||
mainWindow.on('focus', () => {
|
||||
if (process.platform === 'linux') {
|
||||
globalShortcut.registerAll(['Alt+F', 'Alt+E', 'Alt+V', 'Alt+H', 'Alt+W', 'Alt+P'], () => {
|
||||
// do nothing because we want to supress the menu popping up
|
||||
});
|
||||
}
|
||||
globalShortcut.register(`${process.platform === 'darwin' ? 'Cmd+Ctrl' : 'Ctrl+Shift'}+S`, () => {
|
||||
ipcMain.emit(OPEN_TEAMS_DROPDOWN);
|
||||
});
|
||||
});
|
||||
mainWindow.on('blur', () => {
|
||||
globalShortcut.unregisterAll();
|
||||
});
|
||||
|
||||
const contextMenu = new ContextMenu({}, mainWindow);
|
||||
contextMenu.reload();
|
||||
|
||||
|
Reference in New Issue
Block a user