2017-11-13 01:23:39 -05:00
|
|
|
'use strict';
|
2015-02-10 01:34:23 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
import Logger from 'utilities/logging';
|
|
|
|
import Module from 'utilities/module';
|
2017-02-14 00:07:55 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
import {DEBUG} from 'utilities/constants';
|
2015-01-20 01:53:18 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
import SettingsManager from './settings/index';
|
|
|
|
import {TranslationManager} from './i18n';
|
|
|
|
import SocketClient from './socket';
|
|
|
|
import Site from 'site';
|
|
|
|
import Vue from 'utilities/vue';
|
2017-02-14 00:07:55 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
class FrankerFaceZ extends Module {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
const start_time = performance.now(),
|
|
|
|
VER = FrankerFaceZ.version_info;
|
2015-02-10 01:34:23 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
FrankerFaceZ.instance = this;
|
2015-02-10 01:34:23 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
this.name = 'frankerfacez';
|
|
|
|
this.__state = 0;
|
|
|
|
this.__modules.core = this;
|
2016-10-13 23:05:54 -04:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
this.log = new Logger(this);
|
|
|
|
this.core_log = this.log.get('core');
|
2015-02-10 01:34:23 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
this.log.info(`FrankerFaceZ v${VER} (build ${VER.build})`);
|
2015-02-10 01:34:23 -05:00
|
|
|
|
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
// ========================================================================
|
|
|
|
// Core Systems
|
|
|
|
// ========================================================================
|
2015-02-10 01:34:23 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
this.inject('settings', SettingsManager);
|
|
|
|
this.inject('i18n', TranslationManager);
|
|
|
|
this.inject('socket', SocketClient);
|
|
|
|
this.inject('site', Site);
|
2017-04-06 17:55:14 -04:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
this.register('vue', Vue);
|
2017-04-06 17:55:14 -04:00
|
|
|
|
2015-11-14 23:52:49 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
// ========================================================================
|
|
|
|
// Startup
|
|
|
|
// ========================================================================
|
2015-11-14 23:52:49 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
this.discoverModules();
|
2015-01-20 01:53:18 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
this.enable().then(() => this.enableInitialModules()).then(() => {
|
|
|
|
const duration = performance.now() - start_time;
|
|
|
|
this.core_log.info(`Initialization complete in ${duration.toFixed(5)}ms.`);
|
2015-01-20 01:53:18 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
}).catch(err => {
|
|
|
|
this.core_log.error('An error occurred during initialization.', err);
|
2016-05-24 19:24:45 -04:00
|
|
|
});
|
2016-11-20 13:43:12 -05:00
|
|
|
}
|
2016-05-20 17:30:34 -04:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
static get() {
|
|
|
|
return FrankerFaceZ.instance;
|
2015-01-20 01:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
// ========================================================================
|
|
|
|
// Modules
|
|
|
|
// ========================================================================
|
2015-05-17 19:02:57 -04:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
discoverModules() {
|
|
|
|
const ctx = require.context('src/modules', true, /(?:^(?:\.\/)?[^/]+|index)\.js$/),
|
|
|
|
modules = this.populate(ctx, this.core_log);
|
2015-05-17 19:02:57 -04:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
this.core_log.info(`Loaded descriptions of ${Object.keys(modules).length} modules.`);
|
2015-11-19 02:45:56 -05:00
|
|
|
}
|
2015-07-13 21:52:44 -04:00
|
|
|
|
2015-05-17 19:02:57 -04:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
async enableInitialModules() {
|
|
|
|
const promises = [];
|
|
|
|
/* eslint guard-for-in: off */
|
|
|
|
for(const key in this.__modules) {
|
|
|
|
const module = this.__modules[key];
|
|
|
|
if ( module instanceof Module && module.should_enable )
|
|
|
|
promises.push(module.enable());
|
2016-09-09 17:34:20 -04:00
|
|
|
}
|
2015-01-20 01:53:18 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
await Promise.all(promises);
|
|
|
|
}
|
2016-08-09 20:45:28 -04:00
|
|
|
|
2015-01-20 01:53:18 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
/* eslint class-methods-use-this: off */
|
|
|
|
api() {
|
|
|
|
throw new Error('Not Implemented');
|
|
|
|
}
|
|
|
|
}
|
2016-10-20 02:34:55 -04:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
FrankerFaceZ.Logger = Logger;
|
2015-01-20 01:53:18 -05:00
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
const VER = FrankerFaceZ.version_info = {
|
2017-11-13 16:28:17 -05:00
|
|
|
major: 4, minor: 0, revision: 0, extra: '-beta1.1',
|
2017-11-13 01:23:39 -05:00
|
|
|
build: __webpack_hash__,
|
|
|
|
toString: () =>
|
|
|
|
`${VER.major}.${VER.minor}.${VER.revision}${VER.extra || ''}${DEBUG ? '-dev' : ''}`
|
2015-06-05 03:59:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
FrankerFaceZ.utilities = {
|
|
|
|
dom: require('utilities/dom'),
|
|
|
|
color: require('utilities/color'),
|
2017-11-13 16:28:17 -05:00
|
|
|
events: require('utilities/events'),
|
|
|
|
module: require('utilities/module'),
|
|
|
|
constants: require('utilities/constants'),
|
|
|
|
logging: require('utilities/logging'),
|
|
|
|
object: require('utilities/object'),
|
|
|
|
time: require('utilities/time'),
|
|
|
|
tooltip: require('utilities/tooltip')
|
2015-06-05 03:59:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
window.FrankerFaceZ = FrankerFaceZ;
|
|
|
|
window.ffz = new FrankerFaceZ();
|