Provide keyboard shortcut to switch between servers.

This commit is contained in:
Zhongyi Tong
2017-07-10 14:34:40 +08:00
parent 45e7993d0c
commit 890d7caea5
4 changed files with 44 additions and 1 deletions

View File

@@ -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 `<div class="tab">
<div class="server-tab-badge"></div>
<div class="server-tab" style="background-image: url(${this.props.icon});"></div>
<div class="server-tab-shortcut">${this.generateShortcutText()}</div>
</div>`;
}
@@ -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;