diff --git a/renderer/src/modules/api/contextmenu.js b/renderer/src/modules/api/contextmenu.js index 4a086b4e..b1ae6a06 100644 --- a/renderer/src/modules/api/contextmenu.js +++ b/renderer/src/modules/api/contextmenu.js @@ -89,8 +89,8 @@ class MenuPatcher { if (!res) return res; - if (res.props?.navId) { - MenuPatcher.runPatches(res.props.navId, res, arguments[0]); + if (res.props?.navId ?? res.props?.children?.props?.navId) { + MenuPatcher.runPatches(res.props.navId ?? res.props?.children?.props?.navId, res, arguments[0]); } else { const layer = res.props.children ? res.props.children : res; @@ -136,6 +136,7 @@ class MenuPatcher { } } + /** * `ContextMenu` is a module to help patch and create context menus. Instance is accessible through the {@link BdApi}. * @type ContextMenu @@ -212,6 +213,17 @@ class ContextMenu { if (props.danger) props.color = "colorDanger"; if (props.onClick && !props.action) props.action = props.onClick; props.extended = true; + + // This is done to make sure the UI actually displays the on/off correctly + if (type === "toggle") { + const [active, doToggle] = React.useState(props.checked || false); + const originalAction = props.action; + props.checked = active; + props.action = function(ev) { + originalAction(ev); + doToggle(!active); + }; + } return React.createElement(Component, props); } diff --git a/renderer/src/modules/api/dom.js b/renderer/src/modules/api/dom.js index cc285433..e7114740 100644 --- a/renderer/src/modules/api/dom.js +++ b/renderer/src/modules/api/dom.js @@ -35,8 +35,8 @@ class DOM { */ addStyle(id, css) { if (this.#callerName && arguments.length === 2) { - id = arguments[1]; - css = arguments[2]; + id = arguments[0]; + css = arguments[1]; } else if (this.#callerName) { css = id; @@ -53,7 +53,7 @@ class DOM { */ removeStyle(id) { if (this.#callerName && arguments.length === 1) { - id = arguments[1]; + id = arguments[0]; } else if (this.#callerName) { id = this.#callerName; diff --git a/renderer/src/modules/api/patcher.js b/renderer/src/modules/api/patcher.js index de14cbe8..4868978f 100644 --- a/renderer/src/modules/api/patcher.js +++ b/renderer/src/modules/api/patcher.js @@ -37,7 +37,7 @@ class Patcher { /** * This method patches onto another function, allowing your code to run instead. - * Using this, you are also able to modify the return value, using the return of your code instead. + * Using this, you are able to replace the original completely. You can still call the original manually if needed. * @param {string} caller Name of the caller of the patch function. * @param {object} moduleToPatch Object with the function to be patched. Can also be an object's prototype. * @param {string} functionName Name of the function to be patched. @@ -55,8 +55,8 @@ class Patcher { } /** - * This method patches onto another function, allowing your code to run instead. - * Using this, you are also able to modify the return value, using the return of your code instead. + * This method patches onto another function, allowing your code to run afterwards. + * Using this, you are able to modify the return value after the original method is run. * @param {string} caller Name of the caller of the patch function. * @param {object} moduleToPatch Object with the function to be patched. Can also be an object's prototype. * @param {string} functionName Name of the function to be patched. diff --git a/renderer/src/modules/api/reactutils.js b/renderer/src/modules/api/reactutils.js index 7ecc7ae3..58561c63 100644 --- a/renderer/src/modules/api/reactutils.js +++ b/renderer/src/modules/api/reactutils.js @@ -47,7 +47,7 @@ const ReactUtils = { return (name !== null && !!(nameFilter.includes(name) ^ excluding)); } - let curr = ReactUtils.getReactInstance(node); + let curr = ReactUtils.getInternalInstance(node); for (curr = curr && curr.return; !Utilities.isNil(curr); curr = curr.return) { if (Utilities.isNil(curr)) continue; const owner = curr.stateNode;