set developer to false for everyone, change startup initialization to wait on CONNECTION_OPEN dispatch

pull/98/head
dperolio 2 years ago
parent 8a32ab32c1
commit a88e3f4417
No known key found for this signature in database
GPG Key ID: 4191689562D51409

@ -5,8 +5,8 @@
*/
import { log as _log, warn as _warn, error as _error, deprecate as _deprecate } from '@vizality/util/logger';
import { initialize as initializeWebpackModules, getModule } from '@vizality/webpack';
import { Directories, Events, Protocols } from '@vizality/constants';
import { initialize as initializeWebpackModules, getModule, FluxDispatcher, getAllModules } from '@vizality/webpack';
import { Directories, Events, Protocols, Developers } from '@vizality/constants';
import { resolveCompiler } from '@vizality/compilers';
import { createElement } from '@vizality/util/dom';
import { toPlural } from '@vizality/util/string';
@ -55,27 +55,21 @@ export default class Vizality extends Updatable {
*/
this._labels = [ 'Vizality', 'Core' ];
/**
* Wait for the document to be loaded and then initialize Vizality.
* @todo There should be a better way to do this, look into it more in the future.
*/
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => this.initialize());
} else {
this.initialize();
}
this.initialize();
}
/**
* Initialize Vizality.
*/
async initialize () {
try {
/**
* Get rid of Discord's "Hold Up" dev tools warning.
*/
DiscordNative?.window?.setDevtoolsCallbacks(null, null);
async handleConnectionOpen () {
return new Promise(resolve => {
console.log(getAllModules()?.length);
if (getAllModules()?.length > 7000) {
return resolve();
}
FluxDispatcher.subscribe('CONNECTION_OPEN', () => resolve());
});
}
async ensureWebpackModules () {
try {
/**
* Initialize the webpack modules.
*/
@ -92,6 +86,24 @@ export default class Vizality extends Updatable {
return Flux.connectStores(awaitedStores, props => fn(awaitedStores, props))(Component);
})());
await this.handleConnectionOpen();
} catch (err) {
this.error(`Something went wrong while initializing webpack modules: ${err}`);
}
}
/**
* Initialize Vizality.
*/
async initialize () {
try {
await this.ensureWebpackModules();
/**
* Get rid of Discord's "Hold Up" dev tools warning.
*/
DiscordNative?.window?.setDevtoolsCallbacks(null, null);
/**
* Instantiate the managers.
* @note We're doing this down here so that we can utilize webpack modules and
@ -189,13 +201,19 @@ export default class Vizality extends Updatable {
/**
* Set up a shorthand vizality global object with the namespace $vz.
*/
window.$vz = Object.assign({}, this.manager, this.api, this.modules);
window.$vz = Object.assign({}, this.manager, this.modules);
window.$vz.api = this.api;
/**
* Set up and initialize Vizality's core settings.
*/
this.settings = this.api.settings._buildCategoryObject('settings');
window.$vz.settings = this.settings;
this.settings.set('developer', false);
/**
* Check if the current user is a Vizality Developer.
* @note This is going before the settings ready event below, because we check this in
@ -203,16 +221,8 @@ export default class Vizality extends Updatable {
*/
/*
* while (!$discord.users.getCurrentUser()?.id) {
* sleep(1);
* }
*/
this.settings.set('developer', true);
/*
* console.log($discord.users.getCurrentUser()?.id);
* if (Developers.some(developer => developer.id === $discord.users.getCurrentUser()?.id)) {
* console.log('okay');
* console.log('yes');
* this.settings.set('developer', true);
* } else {
* this.settings.set('developer', false);

Loading…
Cancel
Save