Don’t load emotes unless they’re enabled

This commit is contained in:
Samuel Elliott 2018-06-12 20:56:40 +01:00
parent bbcc36647d
commit a2367299b7
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
1 changed files with 8 additions and 3 deletions

View File

@ -25,17 +25,22 @@ export default new class EmoteModule {
}
async init() {
const dataPath = Globals.getPath('data');
this.enabledSetting = Settings.getSetting('emotes', 'default', 'enable');
this.enabledSetting.on('setting-updated', event => {
this.enabledSetting.on('setting-updated', async event => {
// Load emotes if we haven't already
if (event.value && !this.emotes.size) await this.load(path.join(dataPath, 'emotes.json'));
// Rerender all messages (or if we're disabling emotes, those that have emotes)
for (const message of document.querySelectorAll(event.value ? '.message' : '.bd-emotewrapper')) {
Reflection(event.value ? message : message.closest('.message')).forceUpdate();
}
});
const dataPath = Globals.getPath('data');
try {
await this.load(path.join(dataPath, 'emotes.json'));
if (this.enabledSetting.value) await this.load(path.join(dataPath, 'emotes.json'));
else Logger.info('EmoteModule', ['Not loading emotes as they\'re disabled.']);
} catch (err) {
Logger.err('EmoteModule', [`Failed to load emote data. Make sure you've downloaded the emote data and placed it in ${dataPath}:`, err]);
return;