From c3d4313b8e03444e7d7dfa0ffce8ef1d17197ad5 Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Mon, 10 Oct 2022 14:33:36 -0400 Subject: [PATCH] Fix an issue with public servers and documentation --- renderer/src/modules/api/contextmenu.js | 35 +++- renderer/src/modules/api/data.js | 1 - renderer/src/modules/api/dom.js | 14 +- renderer/src/modules/api/legacy.js | 250 +++++++++++++++--------- renderer/src/modules/api/patcher.js | 6 +- renderer/src/modules/api/reactutils.js | 9 +- renderer/src/modules/api/ui.js | 11 +- renderer/src/modules/api/utils.js | 4 +- renderer/src/modules/api/webpack.js | 23 ++- renderer/src/structs/psconnection.js | 2 +- 10 files changed, 229 insertions(+), 126 deletions(-) diff --git a/renderer/src/modules/api/contextmenu.js b/renderer/src/modules/api/contextmenu.js index 2ae64f7a..9e0bd2c5 100644 --- a/renderer/src/modules/api/contextmenu.js +++ b/renderer/src/modules/api/contextmenu.js @@ -35,7 +35,8 @@ const ContextMenuActions = (() => { for (const key of Object.keys(ActionsModule)) { if (ActionsModule[key].toString().includes("CONTEXT_MENU_CLOSE")) { out.closeContextMenu = ActionsModule[key]; - } else if (ActionsModule[key].toString().includes("renderLazy")) { + } + else if (ActionsModule[key].toString().includes("renderLazy")) { out.openContextMenu = ActionsModule[key]; } } @@ -66,7 +67,8 @@ class MenuPatcher { if (res?.props.navId) { MenuPatcher.runPatches(res.props.navId, res, props); - } else if (typeof res?.type === "function") { + } + else if (typeof res?.type === "function") { MenuPatcher.patchRecursive(res, "type"); } @@ -87,8 +89,9 @@ class MenuPatcher { if (!res) return res; if (res.props?.navId) { - MenuPatcher.runPatches(res.props.navId, res, arguments[0]) - } else { + MenuPatcher.runPatches(res.props.navId, res, arguments[0]); + } + else { const layer = res.props.children ? res.props.children : res; if (typeof layer?.type == "function") { @@ -115,7 +118,8 @@ class MenuPatcher { for (const patch of this.patches[id]) { try { patch(res, props); - } catch (error) { + } + catch (error) { Logger.error("ContextMenu~runPatches", `Could not run ${id} patch for`, patch, error); } } @@ -131,13 +135,33 @@ class MenuPatcher { } } +/** + * `ContextMenu` is a module to help patch and create context menus. Instance is accessible through the {@link BdApi}. + * @type ContextMenu + * @summary {@link ContextMenu} is a utility class for interacting with React internals. + * @name ContextMenu + */ class ContextMenu { + + /** + * Allows you to patch a given context menu. Acts as a wrapper around the `Patcher`. + * + * @param {string} navId Discord's internal navId used to identify context menus + * @param {function} callback callback function that accepts the react render tree + * @returns {function} a function that automatically unpatches + */ patch(navId, callback) { MenuPatcher.patch(navId, callback); return () => MenuPatcher.unpatch(navId, callback); } + /** + * Allows you to remove the patch added to a given context menu. + * + * @param {string} navId the original navId from patching + * @param {function} callback the original callback from patching + */ unpatch(navId, callback) { MenuPatcher.unpatch(navId, callback); } @@ -258,6 +282,7 @@ class ContextMenu { } /** + * Function that allows you to open an entire context menu. Recommended to build the menu with this module. * * @param {MouseEvent} event - The context menu event. This can be emulated, requires target, and all X, Y locations. * @param {function} menuComponent - Component to render. This can be any react component or output of {@link ContextMenu.buildMenu} diff --git a/renderer/src/modules/api/data.js b/renderer/src/modules/api/data.js index 00734d45..1a048d20 100644 --- a/renderer/src/modules/api/data.js +++ b/renderer/src/modules/api/data.js @@ -21,7 +21,6 @@ class Data { * @param {string} pluginName Name of the plugin saving data * @param {string} key Which piece of data to store * @param {any} data The data to be saved - * @returns */ save(pluginName, key, data) { if (this.#callerName) { diff --git a/renderer/src/modules/api/dom.js b/renderer/src/modules/api/dom.js index b30f1351..cc285433 100644 --- a/renderer/src/modules/api/dom.js +++ b/renderer/src/modules/api/dom.js @@ -8,10 +8,16 @@ import DOMManager from "../dommanager"; */ class DOM { - /** Document/window width */ + /** + * Current width of the user's screen. + * @type {number} + */ get screenWidth() {return Math.max(document.documentElement.clientWidth, window.innerWidth || 0);} - /** Document/window height */ + /** + * Current height of the user's screen. + * @type {number} + */ get screenHeight() {return Math.max(document.documentElement.clientHeight, window.innerHeight || 0);} #callerName = ""; @@ -67,17 +73,19 @@ class DOM { } /** + * Utility to help smoothly animate using JavaScript * * @param {function} update render function indicating the style should be updates * @param {number} duration duration in ms to animate for * @param {object} [options] option to customize the animation - * @returns */ animate(update, duration, options = {}) { return DOMManager.animate({update, duration, timing: options.timing}); } /** + * Utility function to make creating DOM elements easier. Acts similarly + * to `React.createElement` * * @param {string} tag HTML tag name to create * @param {object} [options] options object to customize the element diff --git a/renderer/src/modules/api/legacy.js b/renderer/src/modules/api/legacy.js index e72959ad..a5791d14 100644 --- a/renderer/src/modules/api/legacy.js +++ b/renderer/src/modules/api/legacy.js @@ -15,28 +15,32 @@ import ipc from "../ipc"; /** * The React module being used inside Discord. * @type React + * @memberof BdApi */ -export const React = DiscordModules.React; +const React = DiscordModules.React; /** * The ReactDOM module being used inside Discord. * @type ReactDOM + * @memberof BdApi */ -export const ReactDOM = DiscordModules.ReactDOM; +const ReactDOM = DiscordModules.ReactDOM; /** * A reference object to get BD's settings. * @type object * @deprecated + * @memberof BdApi */ -export const settings = Settings.collections; +const settings = Settings.collections; /** * A reference object for BD's emotes. * @type object * @deprecated + * @memberof BdApi */ -export const emotes = new Proxy(Emotes.Emotes, { +const emotes = new Proxy(Emotes.Emotes, { get(obj, category) { if (category === "blocklist") return Emotes.blocklist; const group = Emotes.Emotes[category]; @@ -52,28 +56,33 @@ export const emotes = new Proxy(Emotes.Emotes, { /** * A reference string for BD's version. * @type string + * @memberof BdApi */ -export const version = Config.version; +const version = Config.version; /** * Adds a `