BetterDiscordApp-v2/client/src/ui/components/BdSettingsWrapper.vue

65 lines
2.4 KiB
Vue
Raw Normal View History

/**
* BetterDiscord Settings Wrapper Component
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
2018-01-29 18:56:48 +01:00
<template>
<div class="bd-settings-wrapper" :class="[{active: active}, 'platform-' + this.platform]">
<div class="bd-settings-button" :class="{'bd-active': active}" @click="showSettings">
2018-02-14 21:02:12 +01:00
<div v-if="updating === 0" v-tooltip.right="'Checking for updates'" class="bd-settings-button-btn bd-loading"></div>
<div v-else-if="updating === 2" v-tooltip.right="'Updates available!'" class="bd-settings-button-btn bd-updates"></div>
<div v-else class="bd-settings-button-btn" :class="[{'bd-loading': !loaded}]"></div>
</div>
<BdSettings :active="active" :close="hideSettings" />
</div>
2018-01-29 18:56:48 +01:00
</template>
<script>
// Imports
2018-01-30 14:20:24 +01:00
import { Events } from 'modules';
2018-01-30 10:28:28 +01:00
import BdSettings from './BdSettings.vue';
export default {
data() {
return {
loaded: false,
2018-02-14 21:02:12 +01:00
updating: false,
2018-01-30 10:28:28 +01:00
active: false,
platform: global.process.platform
}
},
components: {
BdSettings
},
methods: {
showSettings() {
if (!this.loaded) return;
this.active = true;
},
hideSettings() { this.active = false },
toggleSettings() { this.active = !this.active },
keyupListener(e) {
2018-02-04 13:19:12 +01:00
if (document.getElementsByClassName('bd-backdrop').length) return;
if (this.active && e.which === 27) return this.hideSettings();
if (!e.metaKey && !e.ctrlKey || e.key !== 'b') return;
this.toggleSettings();
e.stopImmediatePropagation();
}
},
created() {
Events.on('ready', e => this.loaded = true);
2018-02-14 21:02:12 +01:00
Events.on('update-check-start', e => this.updating = 0);
Events.on('update-check-end', e => this.updating = 1);
Events.on('updates-available', e => this.updating = 2);
2018-01-30 10:28:28 +01:00
window.addEventListener('keyup', this.keyupListener);
},
destroyed() {
window.removeEventListener('keyup', this.keyupListener);
}
}
</script>