2017-11-13 01:23:39 -05:00
|
|
|
'use strict';
|
2015-02-10 01:34:23 -05:00
|
|
|
|
2018-12-03 18:08:32 -05:00
|
|
|
import dayjs from 'dayjs';
|
2018-04-11 17:05:31 -04:00
|
|
|
import RavenLogger from './raven';
|
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
import Logger from 'utilities/logging';
|
|
|
|
import Module from 'utilities/module';
|
2019-06-01 02:11:22 -04:00
|
|
|
import { timeout } from 'utilities/object';
|
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';
|
2019-06-01 02:11:22 -04:00
|
|
|
import AddonManager from './addons';
|
2018-04-10 21:13:34 -04:00
|
|
|
import ExperimentManager from './experiments';
|
2017-11-13 01:23:39 -05:00
|
|
|
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
|
|
|
|
2018-04-11 17:05:31 -04:00
|
|
|
// ========================================================================
|
|
|
|
// Error Reporting and Logging
|
|
|
|
// ========================================================================
|
|
|
|
|
2018-12-03 18:08:32 -05:00
|
|
|
this.inject('raven', RavenLogger);
|
2018-04-11 17:05:31 -04:00
|
|
|
|
|
|
|
this.log = new Logger(null, null, null, this.raven);
|
2018-12-03 18:08:32 -05:00
|
|
|
this.log.init = true;
|
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
this.core_log = this.log.get('core');
|
2015-02-10 01:34:23 -05:00
|
|
|
|
2018-07-21 16:26:10 -04:00
|
|
|
this.log.info(`FrankerFaceZ v${VER} (build ${VER.build}${VER.commit ? ` - commit ${VER.commit}` : ''})`);
|
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);
|
2018-04-10 21:13:34 -04:00
|
|
|
this.inject('experiments', ExperimentManager);
|
2017-11-13 01:23:39 -05:00
|
|
|
this.inject('i18n', TranslationManager);
|
|
|
|
this.inject('socket', SocketClient);
|
|
|
|
this.inject('site', Site);
|
2019-06-01 02:11:22 -04:00
|
|
|
this.inject('addons', AddonManager);
|
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.`);
|
2018-12-03 18:08:32 -05:00
|
|
|
this.log.init = false;
|
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);
|
2018-12-03 18:08:32 -05:00
|
|
|
this.log.init = false;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-03 18:08:32 -05:00
|
|
|
// ========================================================================
|
|
|
|
// Generate Log
|
|
|
|
// ========================================================================
|
|
|
|
|
|
|
|
async generateLog() {
|
|
|
|
const promises = [];
|
|
|
|
for(const key in this.__modules) {
|
|
|
|
const module = this.__modules[key];
|
|
|
|
if ( module instanceof Module && module.generateLog && module != this )
|
|
|
|
promises.push((async () => {
|
|
|
|
try {
|
|
|
|
return [
|
|
|
|
key,
|
|
|
|
await timeout(Promise.resolve(module.generateLog()), 5000)
|
|
|
|
];
|
|
|
|
} catch(err) {
|
|
|
|
return [
|
|
|
|
key,
|
|
|
|
`Error: ${err}`
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})());
|
|
|
|
}
|
|
|
|
|
|
|
|
const out = await Promise.all(promises);
|
|
|
|
|
|
|
|
if ( this.log.captured_init && this.log.captured_init.length > 0 ) {
|
|
|
|
const logs = [];
|
|
|
|
for(const msg of this.log.captured_init) {
|
|
|
|
const time = dayjs(msg.time).locale('en').format('H:mm:ss');
|
|
|
|
logs.push(`[${time}] ${msg.level} | ${msg.category || 'core'}: ${msg.message}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
out.unshift(['initialization', logs.join('\n')]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out.map(x => {
|
|
|
|
return `${x[0]}
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
${typeof x[1] === 'string' ? x[1] : JSON.stringify(x[1], null, 4)}`
|
|
|
|
}).join('\n\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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() {
|
2018-04-01 18:24:08 -04:00
|
|
|
const ctx = require.context('src/modules', true, /(?:^(?:\.\/)?[^/]+|index)\.jsx?$/),
|
2017-11-13 01:23:39 -05:00
|
|
|
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-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 = {
|
2019-06-19 20:57:14 -04:00
|
|
|
major: 4, minor: 5, revision: 3,
|
2018-07-16 13:57:56 -04:00
|
|
|
commit: __git_commit__,
|
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 = {
|
2019-06-01 02:11:22 -04:00
|
|
|
addon: require('utilities/addon'),
|
2017-11-13 01:23:39 -05:00
|
|
|
color: require('utilities/color'),
|
2017-11-13 16:28:17 -05:00
|
|
|
constants: require('utilities/constants'),
|
2019-06-05 00:30:45 -04:00
|
|
|
dialog: require('utilities/dialog'),
|
|
|
|
dom: require('utilities/dom'),
|
|
|
|
events: require('utilities/events'),
|
|
|
|
fontAwesome: require('utilities/font-awesome'),
|
|
|
|
graphql: require('utilities/graphql'),
|
2017-11-13 16:28:17 -05:00
|
|
|
logging: require('utilities/logging'),
|
2019-06-05 00:30:45 -04:00
|
|
|
module: require('utilities/module'),
|
2017-11-13 16:28:17 -05:00
|
|
|
object: require('utilities/object'),
|
|
|
|
time: require('utilities/time'),
|
2019-05-03 19:30:46 -04:00
|
|
|
tooltip: require('utilities/tooltip'),
|
|
|
|
i18n: require('utilities/translation-core'),
|
2019-06-08 17:35:48 -04:00
|
|
|
dayjs: require('dayjs'),
|
|
|
|
popper: require('popper.js').default
|
2015-06-05 03:59:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
window.FrankerFaceZ = FrankerFaceZ;
|
2017-11-16 00:25:51 -05:00
|
|
|
window.ffz = new FrankerFaceZ();
|