|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { toKebabCase, toTitleCase, toHash, toPlural } from '@vizality/util/string';
|
|
|
|
@ -41,67 +41,67 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
get count () {
|
|
|
|
|
return this._items.size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
get values () {
|
|
|
|
|
return this._items.values();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
get keys () {
|
|
|
|
|
return [ ...this._items.keys() ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
has (addonId) {
|
|
|
|
|
return this._items.has(addonId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
get (addonId) {
|
|
|
|
|
return this._items.get(addonId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
getAll () {
|
|
|
|
|
return this._items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
isInstalled (addonId) {
|
|
|
|
|
return this.has(addonId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
isEnabled (addonId) {
|
|
|
|
|
return !vizality.settings.get(`disabled${toTitleCase(toPlural(this.type))}`, [])
|
|
|
|
|
.filter(addon => this.isInstalled(addon))
|
|
|
|
@ -109,18 +109,18 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
isDisabled (addonId) {
|
|
|
|
|
return !this.isEnabled(addonId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
hasSettings (addonId) {
|
|
|
|
|
try {
|
|
|
|
@ -132,9 +132,9 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
hasScreenshots (addonId) {
|
|
|
|
|
try {
|
|
|
|
@ -146,9 +146,9 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
hasReadme (addonId) {
|
|
|
|
|
try {
|
|
|
|
@ -160,9 +160,9 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
hasChangelog (addonId) {
|
|
|
|
|
try {
|
|
|
|
@ -174,8 +174,8 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
getEnabledKeys () {
|
|
|
|
|
const addons = this.keys;
|
|
|
|
@ -183,8 +183,8 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
getEnabled () {
|
|
|
|
|
const enabled = new Map();
|
|
|
|
@ -197,8 +197,8 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
getDisabledKeys () {
|
|
|
|
|
const addons = this.keys;
|
|
|
|
@ -206,8 +206,8 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
getDisabled () {
|
|
|
|
|
const disabled = new Map();
|
|
|
|
@ -399,39 +399,39 @@ export default class AddonManager extends Events {
|
|
|
|
|
* Toggles an addon with a given ID.
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
*/
|
|
|
|
|
async toggle (addonId, sendEvent = true) {
|
|
|
|
|
try {
|
|
|
|
|
const addon = this.get(addonId);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
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.
|
|
|
|
@ -569,7 +569,7 @@ export default class AddonManager extends Events {
|
|
|
|
|
* The addonId supplied might be a GitHub repository URL
|
|
|
|
|
*/
|
|
|
|
|
if (!git) {
|
|
|
|
|
git = addonId
|
|
|
|
|
git = addonId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -791,7 +791,7 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @param {AddonManifest} manifest Addon manifest
|
|
|
|
|
* @returns {void}
|
|
|
|
@ -890,17 +890,17 @@ export default class AddonManager extends Events {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
this._watcher
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
.on('addDir', (path, stat) => {
|
|
|
|
|
setTimeout(checkAddDirComplete, 2000, path, stat);
|
|
|
|
|
})
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
.on('unlinkDir', path => {
|
|
|
|
|
const addonId = path.replace(this.dir + sep, '');
|
|
|
|
@ -914,7 +914,7 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {string} addonId Addon ID
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
@ -948,7 +948,7 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_warn (...message) {
|
|
|
|
@ -961,7 +961,7 @@ export default class AddonManager extends Events {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_error (...message) {
|
|
|
|
|