|
|
|
@ -387,11 +387,49 @@ export default class AddonManager extends Events {
|
|
|
|
|
return this._log(`All ${toPlural(this.type)} have been unloaded!`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Toggles an addon with a given ID.
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
*/
|
|
|
|
|
async toggle (addonId, sendEvent = true) {
|
|
|
|
|
try {
|
|
|
|
|
const addon = this.get(addonId);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make sure the addon is installed.
|
|
|
|
|
*/
|
|
|
|
|
if (!addon) {
|
|
|
|
|
throw new Error(`Tried to toggle a non-installed ${this.type}: "${addonId}"!`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Toggle the addon.
|
|
|
|
|
*/
|
|
|
|
|
let enabled;
|
|
|
|
|
if (this.isEnabled(addonId)) {
|
|
|
|
|
await this.disable(addonId, false);
|
|
|
|
|
enabled = false;
|
|
|
|
|
} else if (this.isDisabled(addonId, false)) {
|
|
|
|
|
await this.enable(addonId);
|
|
|
|
|
enabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if we should send the event.
|
|
|
|
|
*/
|
|
|
|
|
if (sendEvent) {
|
|
|
|
|
this.emit(_Events.VIZALITY_ADDON_TOGGLE, { addonId, type: this.type, enabled });
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return this._error(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Enables an addon with a given ID.
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
*/
|
|
|
|
|
async enable (addonId) {
|
|
|
|
|
async enable (addonId, sendEvent = true) {
|
|
|
|
|
try {
|
|
|
|
|
const addon = this.get(addonId);
|
|
|
|
|
|
|
|
|
@ -408,7 +446,13 @@ export default class AddonManager extends Events {
|
|
|
|
|
.filter(addon => addon !== addonId));
|
|
|
|
|
|
|
|
|
|
await addon._load(true);
|
|
|
|
|
this.emit(_Events.VIZALITY_ADDON_ENABLE, { addonId, type: this.type });
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if we should send the event.
|
|
|
|
|
*/
|
|
|
|
|
if (sendEvent) {
|
|
|
|
|
this.emit(_Events.VIZALITY_ADDON_ENABLE, { addonId, type: this.type });
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return this._error(err);
|
|
|
|
|
}
|
|
|
|
|