mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-07-05 18:48:31 +00:00
* Added: Setting to force the tags/metadata bar to the top of information pane beneath the player. * Fixed: Some users, somehow, have their emote menu sorting setting set to an invalid value, breaking the player when it tries to sort. Fall back to the default if there's no valid sorting setting. * Changed: Make the changelog properly handle commits with versions starting with a `v`.
175 lines
4.8 KiB
JavaScript
175 lines
4.8 KiB
JavaScript
'use strict';
|
|
|
|
import dayjs from 'dayjs';
|
|
import RavenLogger from './raven';
|
|
|
|
import Logger from 'utilities/logging';
|
|
import Module from 'utilities/module';
|
|
|
|
import {DEBUG} from 'utilities/constants';
|
|
|
|
import SettingsManager from './settings/index';
|
|
import ExperimentManager from './experiments';
|
|
import {TranslationManager} from './i18n';
|
|
import SocketClient from './socket';
|
|
import Site from 'site';
|
|
import Vue from 'utilities/vue';
|
|
import { timeout } from './utilities/object';
|
|
|
|
class FrankerFaceZ extends Module {
|
|
constructor() {
|
|
super();
|
|
const start_time = performance.now(),
|
|
VER = FrankerFaceZ.version_info;
|
|
|
|
FrankerFaceZ.instance = this;
|
|
|
|
this.name = 'frankerfacez';
|
|
this.__state = 0;
|
|
this.__modules.core = this;
|
|
|
|
// ========================================================================
|
|
// Error Reporting and Logging
|
|
// ========================================================================
|
|
|
|
this.inject('raven', RavenLogger);
|
|
|
|
this.log = new Logger(null, null, null, this.raven);
|
|
this.log.init = true;
|
|
|
|
this.core_log = this.log.get('core');
|
|
|
|
this.log.info(`FrankerFaceZ v${VER} (build ${VER.build}${VER.commit ? ` - commit ${VER.commit}` : ''})`);
|
|
|
|
|
|
// ========================================================================
|
|
// Core Systems
|
|
// ========================================================================
|
|
|
|
this.inject('settings', SettingsManager);
|
|
this.inject('experiments', ExperimentManager);
|
|
this.inject('i18n', TranslationManager);
|
|
this.inject('socket', SocketClient);
|
|
this.inject('site', Site);
|
|
|
|
this.register('vue', Vue);
|
|
|
|
|
|
// ========================================================================
|
|
// Startup
|
|
// ========================================================================
|
|
|
|
this.discoverModules();
|
|
|
|
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;
|
|
});
|
|
}
|
|
|
|
static get() {
|
|
return FrankerFaceZ.instance;
|
|
}
|
|
|
|
|
|
// ========================================================================
|
|
// 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');
|
|
}
|
|
|
|
|
|
// ========================================================================
|
|
// Modules
|
|
// ========================================================================
|
|
|
|
discoverModules() {
|
|
const ctx = require.context('src/modules', true, /(?:^(?:\.\/)?[^/]+|index)\.jsx?$/),
|
|
modules = this.populate(ctx, this.core_log);
|
|
|
|
this.core_log.info(`Loaded descriptions of ${Object.keys(modules).length} modules.`);
|
|
}
|
|
|
|
|
|
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());
|
|
}
|
|
|
|
await Promise.all(promises);
|
|
}
|
|
}
|
|
|
|
FrankerFaceZ.Logger = Logger;
|
|
|
|
const VER = FrankerFaceZ.version_info = {
|
|
major: 4, minor: 0, revision: 0, extra: '-rc13.13',
|
|
commit: __git_commit__,
|
|
build: __webpack_hash__,
|
|
toString: () =>
|
|
`${VER.major}.${VER.minor}.${VER.revision}${VER.extra || ''}${DEBUG ? '-dev' : ''}`
|
|
}
|
|
|
|
|
|
FrankerFaceZ.utilities = {
|
|
dom: require('utilities/dom'),
|
|
color: require('utilities/color'),
|
|
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')
|
|
}
|
|
|
|
|
|
|
|
window.FrankerFaceZ = FrankerFaceZ;
|
|
window.ffz = new FrankerFaceZ();
|