diff --git a/client/src/builtin/BlockedMessages.js b/client/src/builtin/BlockedMessages.js index c12ebd6f..a267dda3 100644 --- a/client/src/builtin/BlockedMessages.js +++ b/client/src/builtin/BlockedMessages.js @@ -21,7 +21,7 @@ export default new class BlockedMessages extends BuiltinModule { async enabled(e) { const MessageListComponents = Reflection.module.byProps('BlockedMessageGroup'); MessageListComponents.OriginalBlockedMessageGroup = MessageListComponents.BlockedMessageGroup; - MessageListComponents.BlockedMessageGroup = () => { return null; }; + MessageListComponents.BlockedMessageGroup = () => null; this.cancelBlockedMessages = () => { MessageListComponents.BlockedMessageGroup = MessageListComponents.OriginalBlockedMessageGroup; delete MessageListComponents.OriginalBlockedMessageGroup; diff --git a/client/src/builtin/BuiltinModule.js b/client/src/builtin/BuiltinModule.js index 59437f70..922a46c5 100644 --- a/client/src/builtin/BuiltinModule.js +++ b/client/src/builtin/BuiltinModule.js @@ -39,15 +39,14 @@ export default class BuiltinModule { } async _settingUpdated(e) { - const { value } = e; - if (value === true) { + if (e.value) { if (this.enabled) await this.enabled(e); - if (this.applyPatches) this.applyPatches(); - return; - } - if (value === false) { - if (this.disabled) this.disabled(e); + if (this.applyPatches) await this.applyPatches(); + if (this.rerenderPatchedComponents) this.rerenderPatchedComponents(); + } else { + if (this.disabled) await this.disabled(e); this.unpatch(); + if (this.rerenderPatchedComponents) this.rerenderPatchedComponents(); } } diff --git a/client/src/builtin/ColoredText.js b/client/src/builtin/ColoredText.js index f7aef90c..f1002a2b 100644 --- a/client/src/builtin/ColoredText.js +++ b/client/src/builtin/ColoredText.js @@ -42,6 +42,10 @@ export default new class ColoredText extends BuiltinModule { this.intensitySetting.off('setting-updated', this._intensityUpdated); } + rerenderPatchedComponents() { + if (this.MessageContent) this.MessageContent.forceUpdateAll(); + } + /* Methods */ _intensityUpdated() { this.MessageContent.forceUpdateAll(); @@ -52,14 +56,14 @@ export default new class ColoredText extends BuiltinModule { if (this.patches.length) return; this.MessageContent = await ReactComponents.getComponent('MessageContent'); this.patch(this.MessageContent.component.prototype, 'render', this.injectColoredText); - this.MessageContent.forceUpdateAll(); } /** * Set markup text colour to match role colour */ injectColoredText(thisObject, args, originalReturn) { - this.patch(originalReturn.props, 'children', function(obj, args, returnValue) { + const unpatch = this.patch(originalReturn.props, 'children', (obj, args, returnValue) => { + unpatch(); const { TinyColor } = Reflection.modules; const markup = Utils.findInReactTree(returnValue, m => m && m.props && m.props.className && m.props.className.includes('da-markup')); const roleColor = thisObject.props.message.colorString; diff --git a/client/src/builtin/Emotes/EmoteModule.js b/client/src/builtin/Emotes/EmoteModule.js index 3e4c1136..6ca3941b 100644 --- a/client/src/builtin/Emotes/EmoteModule.js +++ b/client/src/builtin/Emotes/EmoteModule.js @@ -363,8 +363,8 @@ export default new class EmoteModule extends BuiltinModule { for (const child of markup) { if (typeof child !== 'string') { if (typeof child === 'object') { - const isEmoji = Utils.findInReactTree(child, 'emojiName'); - if (isEmoji) child.props.children.props.jumboable = jumboable; + const isEmoji = Utils.findInReactTree(child, filter => filter && filter.emojiName); + if (isEmoji) isEmoji.jumboable = jumboable; } newMarkup.push(child); continue; diff --git a/client/src/builtin/Manager.js b/client/src/builtin/Manager.js index 2660532d..fc60374f 100644 --- a/client/src/builtin/Manager.js +++ b/client/src/builtin/Manager.js @@ -1,15 +1,19 @@ import { EmoteModule, EmoteAc } from './Emotes'; -import { default as ReactDevtoolsModule } from './ReactDevtoolsModule'; -import { default as VueDevtoolsModule } from './VueDevToolsModule'; -import { default as TrackingProtection } from './TrackingProtection'; -import { default as E2EE } from './E2EE'; -import { default as ColoredText } from './ColoredText'; -import { default as TwentyFourHour } from './24Hour'; -import { default as KillClyde } from './KillClyde'; -import { default as BlockedMessages } from './BlockedMessages'; -import { default as VoiceDisconnect } from './VoiceDisconnect'; +import ReactDevtoolsModule from './ReactDevtoolsModule'; +import VueDevtoolsModule from './VueDevToolsModule'; +import TrackingProtection from './TrackingProtection'; +import E2EE from './E2EE'; +import ColoredText from './ColoredText'; +import TwentyFourHour from './24Hour'; +import KillClyde from './KillClyde'; +import BlockedMessages from './BlockedMessages'; +import VoiceDisconnect from './VoiceDisconnect'; export default class { + static get modules() { + return require('./builtin'); + } + static initAll() { EmoteModule.init(); ReactDevtoolsModule.init(); diff --git a/client/src/builtin/TrackingProtection.js b/client/src/builtin/TrackingProtection.js index 4f2eab6b..d8e0a539 100644 --- a/client/src/builtin/TrackingProtection.js +++ b/client/src/builtin/TrackingProtection.js @@ -12,7 +12,7 @@ import BuiltinModule from './BuiltinModule'; import { Reflection } from 'modules'; -export default new class E2EE extends BuiltinModule { +export default new class TrackingProtection extends BuiltinModule { /* Getters */ get moduleName() { return 'TrackingProtection' } diff --git a/client/src/index.js b/client/src/index.js index bdeec32c..6e69ce45 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -34,7 +34,7 @@ class BetterDiscord { Vendor, Patcher, MonkeyPatch, ReactComponents, ReactHelpers, ReactAutoPatcher, DiscordApi, - EmoteModule, + BuiltinManager, EmoteModule, BdWebApi, Connectivity, Cache, diff --git a/client/src/modules/reactcomponents.js b/client/src/modules/reactcomponents.js index d642ae0d..202adaf1 100644 --- a/client/src/modules/reactcomponents.js +++ b/client/src/modules/reactcomponents.js @@ -173,9 +173,18 @@ class ReactComponent { this.important = important; } + get elements() { + if (!this.important || !this.important.selector) return []; + + return document.querySelectorAll(this.important.selector); + } + + get stateNodes() { + return [...this.elements].map(e => Reflection.DOM(e).getComponentStateNode(this)); + } + forceUpdateAll() { - if (!this.important || !this.important.selector) return; - for (const e of document.querySelectorAll(this.important.selector)) { + for (const e of this.elements) { Reflection.DOM(e).forceUpdate(this); } } diff --git a/core/src/modules/updater.js b/core/src/modules/updater.js index 4c82f032..786583d1 100644 --- a/core/src/modules/updater.js +++ b/core/src/modules/updater.js @@ -8,7 +8,6 @@ * LICENSE file in the root directory of this source tree. */ - import Module from './modulebase'; import { FileUtils } from './utils'; import semver from 'semver';