From a88e3f4417752cd1243d6e17e41797944ba8ec86 Mon Sep 17 00:00:00 2001 From: dperolio Date: Wed, 2 Mar 2022 12:43:01 -0500 Subject: [PATCH] set developer to false for everyone, change startup initialization to wait on CONNECTION_OPEN dispatch --- renderer/src/index.js | 70 ++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/renderer/src/index.js b/renderer/src/index.js index 5159fcf0..f85e2ef4 100644 --- a/renderer/src/index.js +++ b/renderer/src/index.js @@ -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);