Merge pull request #93 from doggybootsy/stable

Add 'wrapInHooks' and fixes for modules and css
pull/95/head
dperolio 2 years ago committed by GitHub
commit df56ba62f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

BIN
.DS_Store vendored

Binary file not shown.

@ -11,7 +11,7 @@ import { getModule } from '@vizality/webpack';
export const labels = [ 'Chat', 'BlockedMessageGroup' ];
export default builtin => {
const BlockMessages = getModule(m => m.type?.displayName === 'BlockedMessages');
const BlockMessages = getModule(m => m.type?.displayName === 'CollapsedMessages');
patch('vz-attributes-blocked-messages', BlockMessages, 'type', (_, res) => {
try {
const props = findInReactTree(res, r => r.count);

@ -9,22 +9,24 @@ import { patch, unpatch } from '@vizality/patcher';
export const labels = [ 'Components', 'ContextMenu' ];
// Not a fix but i dont think its exported anymore
export default builtin => {
const ContextMenu = getModuleByDisplayName('FluxContainer(ContextMenus)');
patch('vz-attributes-context-menu', ContextMenu?.prototype, 'render', (_, res) => {
try {
if (!res.props) return;
const root = document.documentElement;
/**
* If a context menu is opened, add an attribute to <html>
* If not, remove the attribute from <html> if it's currently there.
*/
res.props.isOpen
? root.setAttribute('vz-context-menu-active', '')
: root.removeAttribute('vz-context-menu-active');
} catch (err) {
return builtin.error(builtin._labels.concat(labels), err);
}
});
return () => unpatch('vz-attributes-context-menu');
// const ContextMenu = getModuleByDisplayName('FluxContainer(ContextMenus)');
// patch('vz-attributes-context-menu', ContextMenu?.prototype, 'render', (_, res) => {
// try {
// if (!res.props) return;
// const root = document.documentElement;
// /**
// * If a context menu is opened, add an attribute to <html>
// * If not, remove the attribute from <html> if it's currently there.
// */
// res.props.isOpen
// ? root.setAttribute('vz-context-menu-active', '')
// : root.removeAttribute('vz-context-menu-active');
// } catch (err) {
// return builtin.error(builtin._labels.concat(labels), err);
// }
// });
// return () => unpatch('vz-attributes-context-menu');
};

@ -11,21 +11,23 @@ import { findInTree } from '@vizality/util/react';
export const labels = [ 'Components', 'Modals', 'ImageCarousel' ];
export default builtin => {
const ModalCarousel = getModuleByDisplayName('componentDispatchSubscriber(ModalCarousel)');
patch('vz-attributes-modal-image-carousel', ModalCarousel?.prototype, 'render', (_, res) => {
try {
const ogRef = res.ref;
res.ref = elem => {
const r = ogRef(elem);
if (elem?._reactInternals) {
const container = findInTree(elem._reactInternals?.return, el => el?.stateNode?.setAttribute, { walkable: [ 'return' ] });
container?.stateNode?.parentElement?.setAttribute('vz-modal', 'image-carousel');
}
return r;
};
} catch (err) {
return builtin.error(builtin._labels.concat(labels), err);
}
});
(async () => {
const ModalCarousel = await getModuleByDisplayName('ModalCarousel', true)
patch('vz-attributes-modal-image-carousel', ModalCarousel?.prototype, 'render', (_, res) => {
try {
const ogRef = res.ref;
res.ref = elem => {
const r = ogRef(elem);
if (elem?._reactInternals) {
const container = findInTree(elem._reactInternals?.return, el => el?.stateNode?.setAttribute, { walkable: [ 'return' ] });
container?.stateNode?.parentElement?.setAttribute('vz-modal', 'image-carousel');
}
return r;
};
} catch (err) {
return builtin.error(builtin._labels.concat(labels), err);
}
});
})()
return () => unpatch('vz-attributes-modal-image-carousel');
};

@ -10,21 +10,31 @@ import { findInTree } from '@vizality/util/react';
export const labels = [ 'Components', 'Modals', 'User' ];
const sleep = (time) => new Promise(resolve => setTimeout(resolve, time))
async function waitUntil(condition) {
let item
while (!(item = condition())) await sleep(1)
return item
}
export default builtin => {
const UserProfile = getModule(m => m.default?.displayName === 'UserProfileModal');
patch('vz-attributes-modal-user', UserProfile, 'default', ([ props ], res) => {
try {
res.ref = elem => {
if (elem?._reactInternals) {
const container = findInTree(elem._reactInternals.return, el => el.stateNode?.setAttribute, { walkable: [ 'return' ] });
container?.stateNode?.children[0]?.setAttribute('vz-user-id', props?.user?.id);
container?.stateNode?.children[0]?.setAttribute('vz-guild-id', props?.guildId);
container?.stateNode?.parentElement?.setAttribute('vz-modal', 'user');
}
};
} catch (err) {
return builtin.error(builtin._labels.concat(labels), err);
}
});
(async () => {
const UserProfile = await waitUntil(() => getModule(m => m.default?.displayName === 'UserProfileModal'));
console.log(UserProfile);
patch('vz-attributes-modal-user', UserProfile, 'default', ([ props ], res) => {
try {
res.ref = elem => {
if (elem?._reactInternals) {
const container = findInTree(elem._reactInternals.return, el => el.stateNode?.setAttribute, { walkable: [ 'return' ] });
container?.stateNode?.children[0]?.setAttribute('vz-user-id', props?.user?.id);
container?.stateNode?.children[0]?.setAttribute('vz-guild-id', props?.guildId);
container?.stateNode?.parentElement?.setAttribute('vz-modal', 'user');
}
};
} catch (err) {
return builtin.error(builtin._labels.concat(labels), err);
}
});
})()
return () => unpatch('vz-attributes-modal-user');
};

@ -13,16 +13,18 @@ import { patch, unpatch } from '@vizality/patcher';
export const labels = [ 'Global', 'TransitionGroup' ];
export default builtin => {
const TransitionGroup = getModuleByDisplayName('TransitionGroup');
const { contentRegion } = getModule('contentRegion');
patch('vz-attributes-transition-group', TransitionGroup?.prototype, 'render', (_, res) => {
try {
if (!res.props?.className?.includes(contentRegion)) return;
const section = findInReactTree(res, c => c.section)?.section;
section && (res.props['vz-section'] = toKebabCase(section));
} catch (err) {
return builtin.error(builtin._labels.concat(labels), err);
}
});
(async () => {
const TransitionGroup = getModuleByDisplayName('TransitionGroup');
const { contentRegion } = await getModule('contentRegion', true);
patch('vz-attributes-transition-group', TransitionGroup?.prototype, 'render', (_, res) => {
try {
if (!res.props?.className?.includes(contentRegion)) return;
const section = findInReactTree(res, c => c.section)?.section;
section && (res.props['vz-section'] = toKebabCase(section));
} catch (err) {
return builtin.error(builtin._labels.concat(labels), err);
}
});
})()
return () => unpatch('vz-attributes-transition-group');
};

@ -76,12 +76,12 @@
flex-direction: column;
align-items: center;
}
.discoverHeader-3th5O9 {
#{$base}-header > :first-child {
width: 0;
visibility: hidden;
margin-left: 0;
}
.content-3QAtGj {
.content-66wMin {
display: none;
}
/**
@ -97,12 +97,12 @@
/**
* Voice connected panel.
*/
.actionButtons-14eAc_,
.inner-tyMogq,
.button-14-BFJ:first-of-type {
.actionButtons-2vEOUh,
.inner-llGtyq,
.button-1EGGcP:first-of-type {
display: none;
}
.inner-tyMogq {
.inner-llGtyq {
+ div {
margin: 0;
}
@ -113,20 +113,20 @@
/**
* Account panel.
*/
.avatarWrapper-2yR4wp {
.avatarWrapper-1B9FTW {
margin: 0;
}
.container-3baos1 {
.container-YkUktl {
justify-content: center;
}
.nameTag-3uD-yy {
.nameTag-sc-gpq {
&,
& + div {
display: none;
}
}
}
.panels-j1Uci_ {
.panels-3wFtMD {
width: var(--vz-dashboard-sidebar-width);
}
// MacOs drag zone

@ -1,5 +1,5 @@
import { open as openModal, close as closeModal } from '@vizality/modal';
import { getModuleByDisplayName, getModule } from '@vizality/webpack';
import { getModuleByDisplayName, getModule, instance } from '@vizality/webpack';
import { SettingsContextMenu } from '@vizality/components/vizality';
import { Content, Layout } from '@vizality/components/dashboard';
import { toPlural, toTitleCase } from '@vizality/util/string';
@ -12,6 +12,79 @@ import React from 'react';
import SettingsPage from './components/Settings';
// From Strencher#1044 load all context menus (Causes error spam tho in console)
{
const modules = Object.values(instance.m).filter(e => e.toString().search(/openContextMenuLazy[\)\(]/) > -1);
const regex = [
{
regex: /return Promise\.all\(\[(.*?)\]\)\.then\(\D+(.+?)\)\)/,
parse(match) {
return {
imports: matchAll(/\(([\de]+)\)/g, match[0]).map(e => Number(e)),
main: match[1]
};
}
},
{
regex: /return Promise\.resolve\(\)\.then\(\D+(.+?)\)/,
parse(match) {
return {
imports: [],
main: match[0]
};
}
},
{
regex: /return [rn]\.e\((\d+)\)\.then\(\D+(\d+)\)\)/,
parse(match) {
return {
imports: [match[0]],
main: match[0]
};
}
}
];
function matchAll(regex, input, parent = false) {
let matches, output = [], lastIndex = 0;
while (matches = regex.exec(input.slice(lastIndex))) {
if (!regex.global) lastIndex += matches.index + matches[0].length;
if (parent) output.push(matches);
else {
const [, ...match] = matches;
output.push(match);
}
}
return output;
};
const found = [];
for (let i = 0; i < modules.length; i++) {
const str = modules[i].toString();
for (let i2 = 0; i2 < regex.length; i2++) {
const {regex: reg, parse} = regex[i2];
if (!reg.test(str)) continue;
const result = matchAll(reg, str).map(res => ({...parse(res), module: modules[i], reg}));
found.push(...result);
break;
}
}
Promise.all(found.map(item => {
try {
const imports = item.imports.map(i => instance.e(i));
return Promise.all(imports).then(instance.bind(instance, item.main)).catch(console.error);
} catch (error) {
console.error(error);
return Promise.resolve();
}
}));
}
/**
* The settings page categories.
*/
@ -103,8 +176,8 @@ export default class Settings extends Builtin {
</Confirm>);
}
patchSettingsContextMenu () {
const DiscordSettingsContextMenu = getModule(m => m.default?.displayName === 'UserSettingsCogContextMenu');
async patchSettingsContextMenu () {
const DiscordSettingsContextMenu = await getModule(m => m.default?.displayName === 'UserSettingsCogContextMenu', true);
patch('vz-settings-context-menu', DiscordSettingsContextMenu, 'default', (_, res) => {
const items = res.props.children.find(child => Array.isArray(child));
items.push(

@ -1,14 +1,14 @@
import { getModuleByDisplayName } from '@vizality/webpack';
import { findInReactTree } from '@vizality/util/react';
import { findInReactTree, wrapInHooks } from '@vizality/util/react';
import AsyncComponent from './AsyncComponent';
export default AsyncComponent.from((async () => {
/* Thanks to Harley for this~ */
const GuildFolderNode = await getModuleByDisplayName('GuildFolderNode', true);
const ModalRoot = GuildFolderNode?.prototype?.render?.call({ props: { transitionState: 0 }, state: { name: '', color: '' } });
const SuspendedPicker = findInReactTree(ModalRoot, n => n.props?.defaultColor)?.type;
const LazyWebpackModule = await SuspendedPicker()?.props?.children?.type;
const mdl = await (LazyWebpackModule?._ctor || LazyWebpackModule?._payload?._result)();
return mdl?.default;
const GuildSettingsRolesEditDisplay = await getModuleByDisplayName('GuildSettingsRolesEditDisplay', true);
const SettingsPageContent = wrapInHooks(() => new GuildSettingsRolesEditDisplay({ guild: { id: '' }, role: { id: '' } }))();
const ColorPickerFormItem = findInReactTree(SettingsPageContent, (n) => n.type?.displayName === 'ColorPickerFormItem').type({ role: { id: '' } });
const SuspendedPicker = findInReactTree(ColorPickerFormItem, (n) => n.props?.defaultColor).type;
const LazyWebpackModule = await SuspendedPicker().props.children.type;
const mdl = await (LazyWebpackModule._ctor || LazyWebpackModule._payload._result)();
return mdl.default;
})());

@ -283,3 +283,22 @@ export const jsonToReact = (elements, listener) => {
}
});
};
export const wrapInHooks = (method) => {
import React from "react"
return (...args) => {
const Internals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
const _Internals = {}
for (const InternalKey in Internals) _Internals[InternalKey] = Internals[InternalKey]
Internals.useMemo = (fn) => fn();
Internals.useState = (value) => [ value, () => void 0 ];
Internals.useReducer = (value) => [ value, () => void 0 ];
Internals.useEffect = () => null;
Internals.useLayoutEffect = () => null;
Internals.useRef = () => ({});
Internals.useCallback = (cb) => cb;
const res = method(...args);
for (const InternalKey in Internals) Internals[InternalKey] = _Internals[InternalKey]
return res;
}
}
Loading…
Cancel
Save