Make menu keybind customisable

This commit is contained in:
Samuel Elliott 2018-03-08 02:42:06 +00:00
parent dfd0208394
commit 68c0133381
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 14 additions and 6 deletions

View File

@ -30,6 +30,12 @@
"hint": "Disconnect from voice server when Discord closes", "hint": "Disconnect from voice server when Discord closes",
"value": false, "value": false,
"disabled": true "disabled": true
},
{
"id": "menu-keybind",
"type": "keybind",
"text": "Menu keybind",
"value": "mod+b"
} }
] ]
}, },

View File

@ -20,7 +20,8 @@
</template> </template>
<script> <script>
// Imports // Imports
import { Events } from 'modules'; import { Events, Settings } from 'modules';
import { Modals } from 'ui';
import BdSettings from './BdSettings.vue'; import BdSettings from './BdSettings.vue';
export default { export default {
@ -45,11 +46,9 @@
hideSettings() { this.active = false }, hideSettings() { this.active = false },
toggleSettings() { this.active = !this.active }, toggleSettings() { this.active = !this.active },
keyupListener(e) { keyupListener(e) {
if (document.getElementsByClassName('bd-backdrop').length) return; if (Modals.stack.length || !this.active || e.which !== 27) return;
if (this.$refs.settings.activeIndex !== -1 && e.which === 27) return this.$refs.settings.closeContent(); if (this.$refs.settings.activeIndex !== -1) this.$refs.settings.closeContent();
if (this.active && e.which === 27) return this.hideSettings(); else this.hideSettings();
if (!e.metaKey && !e.ctrlKey || e.key !== 'b') return;
this.toggleSettings();
e.stopImmediatePropagation(); e.stopImmediatePropagation();
} }
}, },
@ -69,6 +68,9 @@
Events.on('update-check-end', e => this.updating = 1); Events.on('update-check-end', e => this.updating = 1);
Events.on('updates-available', e => this.updating = 2); Events.on('updates-available', e => this.updating = 2);
window.addEventListener('keyup', this.keyupListener); window.addEventListener('keyup', this.keyupListener);
const menuKeybind = Settings.getSetting('core', 'default', 'menu-keybind');
menuKeybind.on('keybind-activated', () => this.active = !this.active);
}, },
destroyed() { destroyed() {
window.removeEventListener('keyup', this.keyupListener); window.removeEventListener('keyup', this.keyupListener);