Merge branch 'dev' into immediate-finds

This commit is contained in:
Nuckyz 2024-05-26 01:12:22 -03:00
commit d936604f35
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -19,10 +19,10 @@
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { relaunch } from "@utils/native"; import { relaunch } from "@utils/native";
import { canonicalizeMatch, canonicalizeReplace, canonicalizeReplacement } from "@utils/patches"; import { canonicalizeMatch, canonicalizeReplace, canonicalizeReplacement } from "@utils/patches";
import definePlugin from "@utils/types"; import definePlugin, { StartAt } from "@utils/types";
import * as Webpack from "@webpack"; import * as Webpack from "@webpack";
import { cacheFindAll, extract, filters, search } from "@webpack"; import { cacheFindAll, extract, filters, findModuleId, search } from "@webpack";
import { React, ReactDOM } from "@webpack/common"; import * as Common from "@webpack/common";
import type { ComponentType } from "react"; import type { ComponentType } from "react";
const WEB_ONLY = (f: string) => () => { const WEB_ONLY = (f: string) => () => {
@ -34,7 +34,7 @@ export default definePlugin({
description: "Adds shorter Aliases for many things on the window. Run `shortcutList` for a list.", description: "Adds shorter Aliases for many things on the window. Run `shortcutList` for a list.",
authors: [Devs.Ven], authors: [Devs.Ven],
getShortcuts() { getShortcuts(): Record<PropertyKey, any> {
function newFindWrapper(filterFactory: (...props: any[]) => Webpack.FilterFn) { function newFindWrapper(filterFactory: (...props: any[]) => Webpack.FilterFn) {
const cache = new Map<string, unknown>(); const cache = new Map<string, unknown>();
@ -64,14 +64,15 @@ export default definePlugin({
let fakeRenderWin: WeakRef<Window> | undefined; let fakeRenderWin: WeakRef<Window> | undefined;
const find = newFindWrapper(f => f); const find = newFindWrapper(f => f);
const findByProps = newFindWrapper(filters.byProps); const findByProps = newFindWrapper(filters.byProps);
return { return {
...Vencord.Webpack.Common, ...Object.fromEntries(Object.keys(Common).map(key => [key, { getter: () => Common[key] }])),
wp: Vencord.Webpack, wp: Webpack,
wpc: Webpack.wreq.c, wpc: { getter: () => Webpack.cache },
wreq: Webpack.wreq, wreq: { getter: () => Webpack.wreq },
wpsearch: search, wpsearch: search,
wpex: extract, wpex: extract,
wpexs: (code: string) => extract(Webpack.findModuleId(code)!), wpexs: (code: string) => extract(findModuleId(code)!),
find, find,
findAll: cacheFindAll, findAll: cacheFindAll,
findByProps, findByProps,
@ -82,10 +83,10 @@ export default definePlugin({
findAllComponentsByCode: (...code: string[]) => cacheFindAll(filters.componentByCode(...code)), findAllComponentsByCode: (...code: string[]) => cacheFindAll(filters.componentByCode(...code)),
findExportedComponent: (...props: string[]) => findByProps(...props)[props[0]], findExportedComponent: (...props: string[]) => findByProps(...props)[props[0]],
findStore: newFindWrapper(filters.byStoreName), findStore: newFindWrapper(filters.byStoreName),
PluginsApi: Vencord.Plugins, PluginsApi: { getter: () => Vencord.Plugins },
plugins: Vencord.Plugins.plugins, plugins: { getter: () => Vencord.Plugins.plugins },
Settings: Vencord.Settings, Settings: { getter: () => Vencord.Settings },
Api: Vencord.Api, Api: { getter: () => Vencord.Api },
reload: () => location.reload(), reload: () => location.reload(),
restart: IS_WEB ? WEB_ONLY("restart") : relaunch, restart: IS_WEB ? WEB_ONLY("restart") : relaunch,
canonicalizeMatch, canonicalizeMatch,
@ -115,21 +116,40 @@ export default definePlugin({
}); });
} }
ReactDOM.render(React.createElement(component, props), doc.body.appendChild(document.createElement("div"))); Common.ReactDOM.render(Common.React.createElement(component, props), doc.body.appendChild(document.createElement("div")));
} }
}; };
}, },
startAt: StartAt.Init,
start() { start() {
const shortcuts = this.getShortcuts(); const shortcuts = this.getShortcuts();
window.shortcutList = shortcuts; window.shortcutList = {};
for (const [key, val] of Object.entries(shortcuts))
for (const [key, val] of Object.entries(shortcuts)) {
if (val.getter != null) {
Object.defineProperty(window.shortcutList, key, {
get: val.getter,
configurable: true,
enumerable: true
});
Object.defineProperty(window, key, {
get: () => window.shortcutList[key],
configurable: true,
enumerable: true
});
} else {
window.shortcutList[key] = val;
window[key] = val; window[key] = val;
}
}
}, },
stop() { stop() {
delete window.shortcutList; delete window.shortcutList;
for (const key in this.getShortcuts()) for (const key in this.getShortcuts()) {
delete window[key]; delete window[key];
} }
}
}); });