Move all component selectors + filters to ReactAutoPatcher

This commit is contained in:
Samuel Elliott 2019-03-10 16:58:24 +00:00
parent 285ae34b50
commit fcfee53928
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
8 changed files with 36 additions and 17 deletions

View File

@ -50,7 +50,7 @@ export default new class ColoredText extends BuiltinModule {
/* Patches */ /* Patches */
async applyPatches() { async applyPatches() {
if (this.patches.length) return; if (this.patches.length) return;
this.MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector }, m => m.defaultProps && m.defaultProps.hasOwnProperty('disableButtons')); this.MessageContent = await ReactComponents.getComponent('MessageContent');
this.patch(this.MessageContent.component.prototype, 'render', this.injectColoredText); this.patch(this.MessageContent.component.prototype, 'render', this.injectColoredText);
this.MessageContent.forceUpdateAll(); this.MessageContent.forceUpdateAll();
} }

View File

@ -172,7 +172,7 @@ export default new class E2EE extends BuiltinModule {
this.patch(Dispatcher, 'dispatch', this.dispatcherPatch, 'before'); this.patch(Dispatcher, 'dispatch', this.dispatcherPatch, 'before');
this.patchMessageContent(); this.patchMessageContent();
const ChannelTextArea = await ReactComponents.getComponent('ChannelTextArea', { selector: Reflection.resolve('channelTextArea', 'emojiButton').selector }); const ChannelTextArea = await ReactComponents.getComponent('ChannelTextArea');
this.patchChannelTextArea(ChannelTextArea); this.patchChannelTextArea(ChannelTextArea);
this.patchChannelTextAreaSubmit(ChannelTextArea); this.patchChannelTextAreaSubmit(ChannelTextArea);
ChannelTextArea.forceUpdateAll(); ChannelTextArea.forceUpdateAll();
@ -236,11 +236,11 @@ export default new class E2EE extends BuiltinModule {
} }
async patchMessageContent() { async patchMessageContent() {
const MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector }, m => m.defaultProps && m.defaultProps.hasOwnProperty('disableButtons')); const MessageContent = await ReactComponents.getComponent('MessageContent');
this.patch(MessageContent.component.prototype, 'render', this.beforeRenderMessageContent, 'before'); this.patch(MessageContent.component.prototype, 'render', this.beforeRenderMessageContent, 'before');
this.patch(MessageContent.component.prototype, 'render', this.afterRenderMessageContent); this.patch(MessageContent.component.prototype, 'render', this.afterRenderMessageContent);
const ImageWrapper = await ReactComponents.getComponent('ImageWrapper', { selector: Reflection.resolve('imageWrapper').selector }); const ImageWrapper = await ReactComponents.getComponent('ImageWrapper');
this.patch(ImageWrapper.component.prototype, 'render', this.beforeRenderImageWrapper, 'before'); this.patch(ImageWrapper.component.prototype, 'render', this.beforeRenderImageWrapper, 'before');
} }

View File

@ -218,7 +218,7 @@ export default new class EmoteModule extends BuiltinModule {
async applyPatches() { async applyPatches() {
this.patchMessageContent(); this.patchMessageContent();
this.patchSendAndEdit(); this.patchSendAndEdit();
const ImageWrapper = await ReactComponents.getComponent('ImageWrapper', { selector: Reflection.resolve('imageWrapper').selector }); const ImageWrapper = await ReactComponents.getComponent('ImageWrapper');
this.patch(ImageWrapper.component.prototype, 'render', this.beforeRenderImageWrapper, 'before'); this.patch(ImageWrapper.component.prototype, 'render', this.beforeRenderImageWrapper, 'before');
} }
@ -226,7 +226,7 @@ export default new class EmoteModule extends BuiltinModule {
* Patches MessageContent render method * Patches MessageContent render method
*/ */
async patchMessageContent() { async patchMessageContent() {
const MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector }, m => m.defaultProps && m.defaultProps.hasOwnProperty('disableButtons')); const MessageContent = await ReactComponents.getComponent('MessageContent');
this.childPatch(MessageContent.component.prototype, 'render', ['props', 'children'], this.afterRenderMessageContent); this.childPatch(MessageContent.component.prototype, 'render', ['props', 'children'], this.afterRenderMessageContent);
MessageContent.forceUpdateAll(); MessageContent.forceUpdateAll();
} }

View File

@ -10,7 +10,6 @@ import { Utils } from 'common';
import PluginManager from './pluginmanager'; import PluginManager from './pluginmanager';
import Globals from './globals'; import Globals from './globals';
import Security from './security'; import Security from './security';
import { ReactComponents } from './reactcomponents';
import Reflection from './reflection'; import Reflection from './reflection';
import DiscordApi from './discordapi'; import DiscordApi from './discordapi';
import ThemeManager from './thememanager'; import ThemeManager from './thememanager';
@ -136,12 +135,10 @@ export default class PackageInstaller {
/** /**
* Patches Discord upload area for .bd files * Patches Discord upload area for .bd files
*/ */
static async uploadAreaPatch() { static async uploadAreaPatch(UploadArea) {
const { selector } = Reflection.resolve('uploadArea'); const reflect = Reflection.DOM(UploadArea.important.selector);
this.UploadArea = await ReactComponents.getComponent('UploadArea', { selector }); const stateNode = reflect.getComponentStateNode(UploadArea);
const reflect = Reflection.DOM(selector);
const stateNode = reflect.getComponentStateNode(this.UploadArea);
const callback = async function (e) { const callback = async function (e) {
if (!e.dataTransfer.files.length || !e.dataTransfer.files[0].name.endsWith('.bd')) return; if (!e.dataTransfer.files.length || !e.dataTransfer.files[0].name.endsWith('.bd')) return;
e.preventDefault(); e.preventDefault();

View File

@ -373,6 +373,11 @@ export class ReactAutoPatcher {
this.Message.forceUpdateAll(); this.Message.forceUpdateAll();
} }
static async patchMessageContent() {
const { selector } = Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited');
this.MessageContent = await ReactComponents.getComponent('MessageContent', {selector}, c => c.defaultProps && c.defaultProps.hasOwnProperty('disableButtons'));
}
static async patchMessageGroup() { static async patchMessageGroup() {
const { selector } = Reflection.resolve('container', 'message', 'messageCozy'); const { selector } = Reflection.resolve('container', 'message', 'messageCozy');
this.MessageGroup = await ReactComponents.getComponent('MessageGroup', {selector}); this.MessageGroup = await ReactComponents.getComponent('MessageGroup', {selector});
@ -391,6 +396,11 @@ export class ReactAutoPatcher {
this.MessageGroup.forceUpdateAll(); this.MessageGroup.forceUpdateAll();
} }
static async patchImageWrapper() {
const { selector } = Reflection.resolve('imageWrapper');
this.ImageWrapper = await ReactComponents.getComponent('ImageWrapper', {selector});
}
static async patchChannelMember() { static async patchChannelMember() {
ReactComponents.componentAliases.ChannelMember = 'MemberListItem'; ReactComponents.componentAliases.ChannelMember = 'MemberListItem';
@ -409,6 +419,11 @@ export class ReactAutoPatcher {
this.ChannelMember.forceUpdateAll(); this.ChannelMember.forceUpdateAll();
} }
static async patchNameTag() {
const { selector } = Reflection.resolve('nameTag', 'username', 'discriminator', 'ownerIcon');
this.NameTag = await ReactComponents.getComponent('NameTag', {selector});
}
static async patchGuild() { static async patchGuild() {
const selector = `div.${Reflection.resolve('container', 'guildIcon', 'selected', 'unread').className}:not(:first-child)`; const selector = `div.${Reflection.resolve('container', 'guildIcon', 'selected', 'unread').className}:not(:first-child)`;
this.Guild = await ReactComponents.getComponent('Guild', {selector}, m => m.prototype.renderBadge); this.Guild = await ReactComponents.getComponent('Guild', {selector}, m => m.prototype.renderBadge);
@ -443,6 +458,11 @@ export class ReactAutoPatcher {
this.Channel.forceUpdateAll(); this.Channel.forceUpdateAll();
} }
static async patchChannelTextArea() {
const { selector } = Reflection.resolve('channelTextArea', 'emojiButton');
this.ChannelTextArea = await ReactComponents.getComponent('ChannelTextArea', {selector});
}
/** /**
* The GuildTextChannel component represents a text channel in the guild channel list. * The GuildTextChannel component represents a text channel in the guild channel list.
*/ */
@ -538,6 +558,9 @@ export class ReactAutoPatcher {
} }
static async patchUploadArea() { static async patchUploadArea() {
PackageInstaller.uploadAreaPatch(); const { selector } = Reflection.resolve('uploadArea');
this.UploadArea = await ReactComponents.getComponent('UploadArea', {selector});
PackageInstaller.uploadAreaPatch(this.UploadArea);
} }
} }

View File

@ -11,7 +11,7 @@ export default new class Autocomplete {
} }
async init() { async init() {
this.cta = await ReactComponents.getComponent('ChannelTextArea', { selector: Reflection.resolve('channelTextArea', 'emojiButton').selector }); this.cta = await ReactComponents.getComponent('ChannelTextArea');
MonkeyPatch('BD:Autocomplete', this.cta.component.prototype).after('render', this.channelTextAreaAfterRender.bind(this)); MonkeyPatch('BD:Autocomplete', this.cta.component.prototype).after('render', this.channelTextAreaAfterRender.bind(this));
this.initialized = true; this.initialized = true;
} }

View File

@ -9,7 +9,7 @@
*/ */
import { Utils, ClientLogger as Logger } from 'common'; import { Utils, ClientLogger as Logger } from 'common';
import { ReactComponents, Reflection, MonkeyPatch } from 'modules'; import { Reflection, MonkeyPatch } from 'modules';
import { VueInjector, Toasts } from 'ui'; import { VueInjector, Toasts } from 'ui';
import CMGroup from './components/contextmenu/Group.vue'; import CMGroup from './components/contextmenu/Group.vue';

View File

@ -87,8 +87,7 @@ export default class extends Module {
async patchNameTag() { async patchNameTag() {
if (this.PatchedNameTag) return this.PatchedNameTag; if (this.PatchedNameTag) return this.PatchedNameTag;
const selector = Reflection.resolve('nameTag', 'username', 'discriminator', 'ownerIcon').selector; const NameTag = await ReactComponents.getComponent('NameTag');
const NameTag = await ReactComponents.getComponent('NameTag', {selector});
this.PatchedNameTag = class extends NameTag.component { this.PatchedNameTag = class extends NameTag.component {
render() { render() {