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