Update BdSettingsWrapper.vue

No need to check for platform and return instead of if else. We can also hide settings with Ctrl/Cmd+b
This commit is contained in:
Alexei Stukov 2018-01-20 19:33:53 +02:00 committed by GitHub
parent f21aec5226
commit abda678167
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 14 deletions

View File

@ -10,7 +10,7 @@
const methods = { showSettings, hideSettings };
let keydownEvent;
let globalKeyListener;
export default {
components,
@ -21,24 +21,21 @@
platform: global.process.platform
}
},
created: function() {
window.addEventListener('keydown', keydownEvent = e => {
if (this.active) {
if (e.which === 27)
this.hideSettings();
} else {
if (global.process.platform == 'darwin' && e.metaKey && e.key == 'b')
this.showSettings();
else if (global.process.platform != 'darwin' && e.ctrlKey && e.key == 'b')
this.showSettings();
else return;
created: function () {
window.addEventListener('keyup', globalKeyListener = e => {
if (this.active && e.which === 27) {
this.hideSettings();
return;
}
if (!e.metaKey && !e.ctrlKey && e.key !== 'b') return;
!this.active ? this.showSettings() : this.hideSettings();
e.stopImmediatePropagation();
});
},
destroyed: function() {
window.removeEventListener('keydown', keydownEvent);
destroyed: function () {
if (globalKeyListener) window.removeEventListener('keyup', globalKeyListener);
}
}
</script>