From 2346829055336c33abbc47bcc9972677a511a061 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 11 Apr 2020 18:58:00 +0100 Subject: [PATCH] Add riot-desktop shortcuts for forward/back matching browsers&slack Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- electron_app/src/electron-main.js | 10 +++++ src/i18n/strings/en_EN.json | 1 + src/vector/platform/ElectronPlatform.js | 52 ++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index 91258c6cfd..f9619285c0 100644 --- a/electron_app/src/electron-main.js +++ b/electron_app/src/electron-main.js @@ -233,6 +233,16 @@ ipcMain.on('ipcCall', async function(ev, payload) { case 'getConfig': ret = vectorConfig; break; + case 'navigateBack': + if (mainWindow.webContents.canGoBack()) { + mainWindow.webContents.goBack(); + } + break; + case 'navigateForward': + if (mainWindow.webContents.canGoForward()) { + mainWindow.webContents.goForward(); + } + break; default: mainWindow.webContents.send('ipcReply', { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index a7f2f40cce..a10e48ac1f 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -9,6 +9,7 @@ "Unable to load config file: please refresh the page to try again.": "Unable to load config file: please refresh the page to try again.", "Unexpected error preparing the app. See console for details.": "Unexpected error preparing the app. See console for details.", "Open user settings": "Open user settings", + "Previous/next recently visited room or community": "Previous/next recently visited room or community", "Riot Desktop on %(platformName)s": "Riot Desktop on %(platformName)s", "Go to your browser to complete Sign In": "Go to your browser to complete Sign In", "Unknown device": "Unknown device", diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js index 6b75c1eea9..172718c825 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -218,7 +218,7 @@ export default class ElectronPlatform extends VectorBasePlatform { this.startUpdateCheck = this.startUpdateCheck.bind(this); this.stopUpdateCheck = this.stopUpdateCheck.bind(this); - // register Mac specific shortcuts + // register OS-specific shortcuts if (isMac) { registerShortcut(Categories.NAVIGATION, { keybinds: [{ @@ -227,6 +227,28 @@ export default class ElectronPlatform extends VectorBasePlatform { }], description: _td("Open user settings"), }); + + registerShortcut(Categories.NAVIGATION, { + keybinds: [{ + modifiers: [Modifiers.COMMAND], + key: Key.SQUARE_BRACKET_LEFT, + }, { + modifiers: [Modifiers.COMMAND], + key: Key.SQUARE_BRACKET_RIGHT, + }], + description: _td("Previous/next recently visited room or community"), + }); + } else { + registerShortcut(Categories.NAVIGATION, { + keybinds: [{ + modifiers: [Modifiers.ALT], + key: Key.ARROW_LEFT, + }, { + modifiers: [Modifiers.ALT], + key: Key.ARROW_RIGHT, + }], + description: _td("Previous/next recently visited room or community"), + }); } } @@ -434,4 +456,32 @@ export default class ElectronPlatform extends VectorBasePlatform { description: , }); } + + _navigateForwardBack(back: boolean) { + this._ipcCall(back ? "navigateBack" : "navigateForward"); + } + + onKeyDown(ev: KeyboardEvent): boolean { + let handled = false; + + switch (ev.key) { + case Key.SQUARE_BRACKET_LEFT: + case Key.SQUARE_BRACKET_RIGHT: + if (isMac && ev.metaKey && !ev.altKey && !ev.ctrlKey && !ev.shiftKey) { + this._navigateForwardBack(ev.key === Key.SQUARE_BRACKET_LEFT); + handled = true; + } + break; + + case Key.ARROW_LEFT: + case Key.ARROW_RIGHT: + if (!isMac && ev.altKey && !ev.metaKey && !ev.ctrlKey && !ev.shiftKey) { + this._navigateForwardBack(ev.key === Key.ARROW_LEFT); + handled = true; + } + break; + } + + return handled; + } }