diff --git a/package.json b/package.json index 147194f6..467ade17 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "frankerfacez", "author": "Dan Salvato LLC", - "version": "4.20.60", + "version": "4.20.61", "description": "FrankerFaceZ is a Twitch enhancement suite.", "license": "Apache-2.0", "scripts": { diff --git a/src/bridge.js b/src/bridge.js index 02a9fd6a..3e6e036d 100644 --- a/src/bridge.js +++ b/src/bridge.js @@ -6,6 +6,7 @@ import Logger from 'utilities/logging'; import Module from 'utilities/module'; import {DEBUG} from 'utilities/constants'; +import {serializeBlob, deserializeBlob} from 'utilities/blobs'; import SettingsManager from './settings/index'; @@ -28,6 +29,7 @@ class FFZBridge extends Module { this.inject('raven', RavenLogger); this.log = new Logger(null, null, null, this.raven); + this.log.label = 'FFZBridge'; this.log.init = true; this.core_log = this.log.get('core'); @@ -60,15 +62,21 @@ class FFZBridge extends Module { return FFZBridge.instance; } - onEnable() { + async onEnable() { window.addEventListener('message', this.onMessage.bind(this)); this.settings.provider.on('changed', this.onProviderChange, this); + this.settings.provider.on('changed-blob', this.onProviderBlobChange, this); + this.settings.provider.on('clear-blobs', this.onProviderClearBlobs, this); + + await this.settings.awaitProvider(); + await this.settings.provider.awaitReady(); + this.send({ ffz_type: 'ready' }); } - onMessage(event) { + async onMessage(event) { const msg = event.data; if ( ! msg || ! msg.ffz_type ) return; @@ -83,13 +91,86 @@ class FFZBridge extends Module { data: out }); - } else if ( msg.ffz_type === 'change' ) + return; + + } else if ( msg.ffz_type === 'change' ) { this.onChange(msg); + return; + } + + if ( ! msg.id ) + return this.log.warn('Received command with no reply ID'); + + let reply, transfer; + + try { + if ( msg.ffz_type === 'init-load' ) { + reply = { + blobs: this.settings.provider.supportsBlobs, + values: {} + }; + + for(const [key,value] of this.settings.provider.entries()) + reply.values[key] = value; + + } else if ( msg.ffz_type === 'set' ) + this.settings.provider.set(msg.key, msg.value); + + else if ( msg.ffz_type === 'delete' ) + this.settings.provider.delete(msg.key); + + else if ( msg.ffz_type === 'clear' ) + this.settings.provider.clear(); + + else if ( msg.ffz_type === 'get-blob' ) { + reply = await serializeBlob(await this.settings.provider.getBlob(msg.key)); + if ( reply ) + transfer = reply.buffer; + + } else if ( msg.ffz_type === 'set-blob' ) { + const blob = deserializeBlob(msg.value); + await this.settings.provider.setBlob(msg.key, blob); + + } else if ( msg.ffz_type === 'delete-blob' ) + await this.settings.provider.deleteBlob(msg.key); + + else if ( msg.ffz_type === 'has-blob' ) + reply = await this.settings.provider.hasBlob(msg.key); + + else if ( msg.ffz_type === 'clear-blobs' ) + await this.settings.provider.clearBlobs(); + + else if ( msg.ffz_type === 'blob-keys' ) + reply = await this.settings.provider.blobKeys(); + + else if ( msg.ffz_type === 'flush' ) + await this.settings.provider.flush(); + + else + return this.send({ + ffz_type: 'reply-error', + id: msg.id, + error: 'bad-command' + }); + + this.send({ + ffz_type: 'reply', + id: msg.id, + reply + }, transfer); + + } catch(err) { + this.log.error('Error handling command.', err); + this.send({ + ffz_type: 'reply-error', + id: msg.id + }); + } } - send(msg) { // eslint-disable-line class-methods-use-this + send(msg, blob) { // eslint-disable-line class-methods-use-this try { - window.parent.postMessage(msg, '*') + window.parent.postMessage(msg, '*', blob ? [blob] : undefined) } catch(err) { this.log.error('send error', err); /* no-op */ } } @@ -112,6 +193,20 @@ class FFZBridge extends Module { deleted }); } + + onProviderBlobChange(key, deleted) { + this.send({ + ffz_type: 'change-blob', + key, + deleted + }); + } + + onProviderClearBlobs() { + this.send({ + ffz_type: 'clear-blobs' + }); + } } FFZBridge.Logger = Logger; diff --git a/src/main.js b/src/main.js index 75be9dcb..d50cebc5 100644 --- a/src/main.js +++ b/src/main.js @@ -68,17 +68,17 @@ class FrankerFaceZ extends Module { // Startup // ======================================================================== - this.discoverModules(); + this.discoverModules() + .then(() => this.enable()) + .then(() => this.enableInitialModules()).then(() => { + const duration = performance.now() - start_time; + this.core_log.info(`Initialization complete in ${duration.toFixed(5)}ms.`); + this.log.init = false; - this.enable().then(() => this.enableInitialModules()).then(() => { - const duration = performance.now() - start_time; - this.core_log.info(`Initialization complete in ${duration.toFixed(5)}ms.`); - this.log.init = false; - - }).catch(err => { - this.core_log.error('An error occurred during initialization.', err); - this.log.init = false; - }); + }).catch(err => { + this.core_log.error('An error occurred during initialization.', err); + this.log.init = false; + }); } static get() { @@ -132,9 +132,10 @@ ${typeof x[1] === 'string' ? x[1] : JSON.stringify(x[1], null, 4)}`).join('\n\n' // Modules // ======================================================================== - discoverModules() { - const ctx = require.context('src/modules', true, /(?:^(?:\.\/)?[^/]+|index)\.jsx?$/), - modules = this.populate(ctx, this.core_log); + async discoverModules() { + // TODO: Actually do async modules. + const ctx = await require.context('src/modules', true, /(?:^(?:\.\/)?[^/]+|index)\.jsx?$/ /*, 'lazy-once' */); + const modules = this.populate(ctx, this.core_log); this.core_log.info(`Loaded descriptions of ${Object.keys(modules).length} modules.`); } diff --git a/src/modules/chat/actions/components/edit-ban.vue b/src/modules/chat/actions/components/edit-ban.vue index c37ec6ca..e92aeceb 100644 --- a/src/modules/chat/actions/components/edit-ban.vue +++ b/src/modules/chat/actions/components/edit-ban.vue @@ -8,7 +8,7 @@ diff --git a/src/modules/chat/actions/components/edit-chat.vue b/src/modules/chat/actions/components/edit-chat.vue index b5ed980a..b14f7c64 100644 --- a/src/modules/chat/actions/components/edit-chat.vue +++ b/src/modules/chat/actions/components/edit-chat.vue @@ -9,7 +9,7 @@ :id="'edit_chat$' + id" v-model="value.command" :placeholder="defaults.command" - class="tw-border-radius-medium tw-font-size-6 tw-full-width tw-input tw-pd-x-1 tw-pd-y-05 tw-mg-y-05" + class="tw-border-radius-medium tw-font-size-6 tw-full-width ffz-input tw-pd-x-1 tw-pd-y-05 tw-mg-y-05" @input="$emit('input', value)" > @@ -17,16 +17,16 @@ {{ t('setting.actions.variables', 'Available Variables: {vars}', {vars}) }} -