Skip to content

Commit 24dbbfa

Browse files
authored
Merge pull request element-hq#13133 from vector-im/t3chguy/electron-forward-back
Add riot-desktop shortcuts for forward/back matching browsers&slack
2 parents 4354c50 + 2346829 commit 24dbbfa

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

‎electron_app/src/electron-main.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ ipcMain.on('ipcCall', async function(ev, payload) {
233233
case 'getConfig':
234234
ret = vectorConfig;
235235
break;
236+
case 'navigateBack':
237+
if (mainWindow.webContents.canGoBack()) {
238+
mainWindow.webContents.goBack();
239+
}
240+
break;
241+
case 'navigateForward':
242+
if (mainWindow.webContents.canGoForward()) {
243+
mainWindow.webContents.goForward();
244+
}
245+
break;
236246

237247
default:
238248
mainWindow.webContents.send('ipcReply', {

‎src/i18n/strings/en_EN.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"Unable to load config file: please refresh the page to try again.": "Unable to load config file: please refresh the page to try again.",
1010
"Unexpected error preparing the app. See console for details.": "Unexpected error preparing the app. See console for details.",
1111
"Open user settings": "Open user settings",
12+
"Previous/next recently visited room or community": "Previous/next recently visited room or community",
1213
"Riot Desktop on %(platformName)s": "Riot Desktop on %(platformName)s",
1314
"Go to your browser to complete Sign In": "Go to your browser to complete Sign In",
1415
"Unknown device": "Unknown device",

‎src/vector/platform/ElectronPlatform.js‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
218218
this.startUpdateCheck = this.startUpdateCheck.bind(this);
219219
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
220220

221-
// register Mac specific shortcuts
221+
// register OS-specific shortcuts
222222
if (isMac) {
223223
registerShortcut(Categories.NAVIGATION, {
224224
keybinds: [{
@@ -227,6 +227,28 @@ export default class ElectronPlatform extends VectorBasePlatform {
227227
}],
228228
description: _td("Open user settings"),
229229
});
230+
231+
registerShortcut(Categories.NAVIGATION, {
232+
keybinds: [{
233+
modifiers: [Modifiers.COMMAND],
234+
key: Key.SQUARE_BRACKET_LEFT,
235+
}, {
236+
modifiers: [Modifiers.COMMAND],
237+
key: Key.SQUARE_BRACKET_RIGHT,
238+
}],
239+
description: _td("Previous/next recently visited room or community"),
240+
});
241+
} else {
242+
registerShortcut(Categories.NAVIGATION, {
243+
keybinds: [{
244+
modifiers: [Modifiers.ALT],
245+
key: Key.ARROW_LEFT,
246+
}, {
247+
modifiers: [Modifiers.ALT],
248+
key: Key.ARROW_RIGHT,
249+
}],
250+
description: _td("Previous/next recently visited room or community"),
251+
});
230252
}
231253
}
232254

@@ -434,4 +456,32 @@ export default class ElectronPlatform extends VectorBasePlatform {
434456
description: <Spinner />,
435457
});
436458
}
459+
460+
_navigateForwardBack(back: boolean) {
461+
this._ipcCall(back ? "navigateBack" : "navigateForward");
462+
}
463+
464+
onKeyDown(ev: KeyboardEvent): boolean {
465+
let handled = false;
466+
467+
switch (ev.key) {
468+
case Key.SQUARE_BRACKET_LEFT:
469+
case Key.SQUARE_BRACKET_RIGHT:
470+
if (isMac && ev.metaKey && !ev.altKey && !ev.ctrlKey && !ev.shiftKey) {
471+
this._navigateForwardBack(ev.key === Key.SQUARE_BRACKET_LEFT);
472+
handled = true;
473+
}
474+
break;
475+
476+
case Key.ARROW_LEFT:
477+
case Key.ARROW_RIGHT:
478+
if (!isMac && ev.altKey && !ev.metaKey && !ev.ctrlKey && !ev.shiftKey) {
479+
this._navigateForwardBack(ev.key === Key.ARROW_LEFT);
480+
handled = true;
481+
}
482+
break;
483+
}
484+
485+
return handled;
486+
}
437487
}

0 commit comments

Comments
 (0)