diff --git a/app/main/index.js b/app/main/index.js index 75fb69d6..f066aca9 100644 --- a/app/main/index.js +++ b/app/main/index.js @@ -224,6 +224,13 @@ app.on('ready', () => { console.log(listener, ...params); page.send(listener); }); + + ipc.on('register-server-tab-shortcut', (event, index) => { + electronLocalshortcut.register(mainWindow, `CommandOrControl+${index}`, () => { + // Array index == Shown index - 1 + page.send('switch-server-tab', index - 1); + }); + }); }); app.on('will-quit', () => { diff --git a/app/renderer/css/main.css b/app/renderer/css/main.css index febab7b1..fda3ebe5 100644 --- a/app/renderer/css/main.css +++ b/app/renderer/css/main.css @@ -81,7 +81,7 @@ html, body { .tab { position: relative; - margin: 5px 0; + margin: 2px 0; cursor: pointer; } @@ -168,6 +168,13 @@ html, body { flex-direction: column; } +.tab .server-tab-shortcut { + color: #eee; + font-size: 12px; + text-align: center; + font-family: sans-serif; +} + /******************* * Webview Area * *******************/ diff --git a/app/renderer/js/components/server-tab.js b/app/renderer/js/components/server-tab.js index 320a89aa..94d0f9e2 100644 --- a/app/renderer/js/components/server-tab.js +++ b/app/renderer/js/components/server-tab.js @@ -1,12 +1,16 @@ 'use strict'; const Tab = require(__dirname + '/../components/tab.js'); +const SystemUtil = require(__dirname + '/../utils/system-util.js'); + +const {ipcRenderer} = require('electron'); class ServerTab extends Tab { template() { return `
+
${this.generateShortcutText()}
`; } @@ -26,6 +30,27 @@ class ServerTab extends Tab { this.$badge.classList.remove('active'); } } + + generateShortcutText() { + // Only provide shortcuts for server [0..10] + if (this.props.index >= 10) { + return ''; + } + + const shownIndex = this.props.index + 1; + + let cmdKey = ''; + + if (SystemUtil.getOS() === 'Mac') { + cmdKey = '⌘'; + } else { + cmdKey = '⌃'; + } + + ipcRenderer.send('register-server-tab-shortcut', shownIndex); + + return `${cmdKey} ${shownIndex}`; + } } module.exports = ServerTab; diff --git a/app/renderer/js/main.js b/app/renderer/js/main.js index 7ed17ad3..af6a7dbc 100644 --- a/app/renderer/js/main.js +++ b/app/renderer/js/main.js @@ -46,6 +46,7 @@ class ServerManagerView { icon: server.icon, $root: this.$tabsContainer, onClick: this.activateTab.bind(this, index), + index, webview: new WebView({ $root: this.$content, index, @@ -203,6 +204,9 @@ class ServerManagerView { this.openSettings(settingNav); }); ipcRenderer.on('open-about', this.openAbout.bind(this)); + ipcRenderer.on('switch-server-tab', (event, index) => { + this.activateTab(index); + }); } }