2019-06-01 02:11:22 -04:00
|
|
|
import Module from 'utilities/module';
|
|
|
|
|
|
|
|
export class Addon extends Module {
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
|
|
|
|
this.inject('i18n');
|
|
|
|
this.inject('settings');
|
|
|
|
}
|
|
|
|
|
|
|
|
static register(id, info) {
|
2019-06-01 13:58:12 -04:00
|
|
|
if ( typeof id === 'object' ) {
|
|
|
|
info = id;
|
|
|
|
id = info.id || undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! id ) {
|
|
|
|
if ( this.name )
|
|
|
|
id = this.name.toSnakeCase();
|
|
|
|
else
|
|
|
|
throw new Error(`Unable to register module without ID.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! info && this.info )
|
|
|
|
info = this.info;
|
2019-06-01 02:11:22 -04:00
|
|
|
|
2019-06-01 13:58:12 -04:00
|
|
|
const ffz = FrankerFaceZ.get();
|
2019-06-01 02:11:22 -04:00
|
|
|
if ( info ) {
|
|
|
|
info.id = id;
|
|
|
|
ffz.addons.addAddon(info);
|
|
|
|
}
|
2019-06-01 13:58:12 -04:00
|
|
|
|
|
|
|
try {
|
|
|
|
ffz.register(`addon.${id}`, this);
|
|
|
|
} catch(err) {
|
|
|
|
if ( err.message && err.message.includes('Name Collision for Module') ) {
|
|
|
|
const module = ffz.resolve(`addon.${id}`);
|
|
|
|
if ( module )
|
|
|
|
module.external = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
}
|
2019-06-01 02:11:22 -04:00
|
|
|
}
|
|
|
|
}
|