add community manager, and add community manager initialization and another Vizality startup log

pull/67/head
dperolio 3 years ago
parent 5135c3f6f0
commit 68c086d3b0
No known key found for this signature in database
GPG Key ID: 3E9BBAA710D3DDCE

@ -114,7 +114,29 @@ export default class Vizality extends Updatable {
/**
* Time to start Vizality.
*/
await this.start();
const before = performance.now();
const startVizality = () => {
return new Promise(resolve => {
resolve(this.start());
});
};
await startVizality()
.then(() => {
const after = performance.now();
const time = parseFloat((after - before).toFixed()).toString().replace(/^0+/, '') || 0;
/**
* Let's format the milliseconds to seconds.
*/
let formattedTime = Math.round((time / 1000 + Number.EPSILON) * 100) / 100;
/**
* If it ends up being so fast that it rounds to 0, let's show formatting
* to 3 decimal places, otherwise show 2 decimal places.
*/
if (formattedTime === 0) {
formattedTime = Math.round((time / 1000 + Number.EPSILON) * 1000) / 1000;
}
return this.log(`Vizality loaded. Startup took ${formattedTime} seconds!`);
});
/**
* Get and assign the newly updated git info.
@ -212,10 +234,10 @@ export default class Vizality extends Updatable {
/**
* Initialize builtins, plugins, and themes.
*/
this.manager.themes.initialize();
await this.manager.builtins.initialize();
this.manager.themes.initialize();
this.manager.plugins.initialize();
this.manager.community.initialize();
this._initialized = true;
}

@ -0,0 +1,69 @@
import { toPlural } from '@vizality/util/string';
import { HTTP } from '@vizality/constants';
import { get } from '@vizality/http';
import Events from 'events';
/**
* @extends Events
*/
export default class CommunityManager extends Events {
constructor () {
this.plugins = new Map();
this.themes = new Map();
}
/**
*
*/
get count () {
return this.plugins.size + this.themes.size;
}
/**
*
*/
get pluginsCount () {
return this.plugins.size;
}
/**
*
*/
get themesCount () {
return this.themes.size;
}
/**
*
* @param {string} addonId Addon ID
* @returns
*/
get (addonId, type) {
return this[toPlural(type)].get(addonId);
}
/**
*
* @param {string} addonId Addon ID
* @returns {boolean}
*/
has (addonId, type) {
return this[toPlural(type)].has(addonId);
}
/**
*
* @returns {Promise<void>}
*/
async initialize () {
/**
* Gets all of the addon repos currently active on the addon community organization.
*/
const addons = (await get(`${HTTP.API}/addons`))?.body?.message;
const { plugins, themes } = addons;
Object.values(plugins)
.map(plugin => this.plugins.set(plugin.addonId, plugin));
Object.values(themes)
.map(theme => this.themes.set(theme.addonId, theme));
}
}
Loading…
Cancel
Save